Skip to content

Commit

Permalink
Less hacky offhand (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Caedis <[email protected]>
  • Loading branch information
Lyfts and Caedis authored Jan 19, 2025
1 parent 0123a78 commit cd2ffb3
Show file tree
Hide file tree
Showing 68 changed files with 1,370 additions and 3,995 deletions.
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.7.13-GTNH:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.2:dev")
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.4-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.7.18-GTNH:dev")
compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.7.0:dev")
compileOnly(deobf("https://github.com/Roadhog360/Et-Futurum-Requiem/releases/download/2.6.0/Et_Futurum_Requiem-2.6.0-nomixin.jar", "Et Futurum Requiem"))
compileOnly("com.github.GTNewHorizons:CarpentersBlocks:3.7.0-GTNH:dev")
compileOnly(rfg.deobf('maven.modrinth:etfuturum:2.6.2'))
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.30'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.31'
}
20 changes: 0 additions & 20 deletions src/main/java/xonin/backhand/Backhand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.MinecraftForge;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -11,12 +10,10 @@
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import xonin.backhand.packet.BackhandPacketHandler;
import xonin.backhand.utils.BackhandConfig;
import xonin.backhand.utils.BackhandConfigClient;
Expand All @@ -37,11 +34,9 @@ public class Backhand {
@SidedProxy(clientSide = "xonin.backhand.client.ClientProxy", serverSide = "xonin.backhand.CommonProxy")
public static CommonProxy proxy;
public static BackhandPacketHandler packetHandler;
public static boolean isEFRLoaded;

@Mod.EventHandler
public void load(FMLPreInitializationEvent event) {
isEFRLoaded = Loader.isModLoaded("etfuturum");
try {
ConfigurationManager.registerConfig(BackhandConfig.class);
ConfigurationManager.registerConfig(BackhandConfigClient.class);
Expand All @@ -50,16 +45,6 @@ public void load(FMLPreInitializationEvent event) {
}

proxy.load();

MinecraftForge.EVENT_BUS.register(new ServerEventsHandler());
FMLCommonHandler.instance()
.bus()
.register(new ServerTickHandler());

MinecraftForge.EVENT_BUS.register(HookContainerClass.INSTANCE);
FMLCommonHandler.instance()
.bus()
.register(HookContainerClass.INSTANCE);
}

@Mod.EventHandler
Expand All @@ -68,11 +53,6 @@ public void init(FMLInitializationEvent event) {
packetHandler.register();
}

@Mod.EventHandler
public void onServerStopping(FMLServerStoppingEvent event) {
proxy.onServerStopping(event);
}

public static MinecraftServer getServer() {
return FMLCommonHandler.instance()
.getMinecraftServerInstance();
Expand Down
75 changes: 33 additions & 42 deletions src/main/java/xonin/backhand/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,51 @@
package xonin.backhand;

import javax.annotation.Nullable;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.FakePlayer;

import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber;

import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import xonin.backhand.api.core.BackhandUtils;
import xonin.backhand.utils.EnumAnimations;
import xonin.backhand.packet.OffhandConfigSyncPacket;
import xonin.backhand.packet.OffhandSyncItemPacket;

@EventBusSubscriber
public class CommonProxy {

public static ItemStack offhandItemUsed;

public void load() {

}
public void load() {}

public void onServerStopping(FMLServerStoppingEvent event) {
for (EntityPlayer player : Backhand.getServer()
.getConfigurationManager().playerEntityList) {
if (BackhandUtils.getOffhandItem(player) != null) {
BackhandUtils.resetAndDelayHotswap(player, 0);
@SubscribeEvent
public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (!(event.player instanceof EntityPlayerMP playerMP)) {
return;
}
Backhand.packetHandler.sendPacketToPlayer(new OffhandConfigSyncPacket().generatePacket(), playerMP);
ItemStack offhandItem = BackhandUtils.getOffhandItem(playerMP);
if (Backhand.isOffhandBlacklisted(offhandItem)) {
BackhandUtils.setPlayerOffhandItem(playerMP, null);
if (!playerMP.inventory.addItemStackToInventory(offhandItem)) {
event.player.entityDropItem(offhandItem, 0);
}
}
}

public EntityPlayer getClientPlayer() {
return null;
}

public void sendAnimationPacket(EnumAnimations animation, EntityPlayer entityPlayer) {}

// Should not be called on the server anyway
public boolean isRightClickHeld() {
return false;
}

public int getRightClickCounter() {
return 0;
}

public void setRightClickCounter(int i) {}

public int getRightClickDelay() {
return 0;
}

// Should not be called on the server anyway
public boolean isLeftClickHeld() {
return false;
@SubscribeEvent
public static void addTracking(net.minecraftforge.event.entity.player.PlayerEvent.StartTracking event) {
if (event.entityPlayer instanceof EntityPlayerMP playerMP && isValidPlayer(event.target)) {
Backhand.packetHandler
.sendPacketToPlayer(new OffhandSyncItemPacket((EntityPlayer) event.target).generatePacket(), playerMP);
}
}

// Should not be called on the server anyway
public int getLeftClickCounter() {
return 0;
private static boolean isValidPlayer(@Nullable Entity entity) {
return entity instanceof EntityPlayerMP playerMP
&& !(entity instanceof FakePlayer || playerMP.playerNetServerHandler == null);
}

// Should not be called on the server anyway
public void setLeftClickCounter(int i) {}
}
Loading

0 comments on commit cd2ffb3

Please sign in to comment.