Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less hacky offhand #46

Merged
merged 38 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f9cfbd8
update bs+deps
Lyfts Jan 15, 2025
b700525
try for a more native feeling & less hacky offhand
Lyfts Jan 15, 2025
90deb2e
fix tinker's crosshair not rendering for offhand crossbow
Lyfts Jan 15, 2025
17b846e
fix an incorrect check
Lyfts Jan 15, 2025
ae080fa
add client-side check for offhand attack
Lyfts Jan 15, 2025
f27b034
re-add invtweaks hack
Lyfts Jan 15, 2025
31898f1
move inv slot next to player model
Lyfts Jan 15, 2025
3542fbe
get the config sync going again
Lyfts Jan 15, 2025
0a50db0
remove a ton of unused AT's
Lyfts Jan 15, 2025
b5ebef3
fix server crash
Lyfts Jan 15, 2025
369f446
cleanup rendering a bit
Lyfts Jan 16, 2025
036d66c
fix mp sync
Lyfts Jan 16, 2025
bea2d8c
also sync when offhand is emptied
Lyfts Jan 16, 2025
9411cd8
remove more now unused stuff & shuffle some mixins around
Lyfts Jan 16, 2025
8b5b33e
slight optimization
Lyfts Jan 16, 2025
dbff6c8
oops didn't mean to remove that
Lyfts Jan 16, 2025
bccda1f
fix a few issues with the offhand swing
Lyfts Jan 16, 2025
a4d42a0
reduce some CallbackInfo allocations
Lyfts Jan 16, 2025
c082795
more accurate name
Lyfts Jan 16, 2025
247a076
yeet
Lyfts Jan 16, 2025
b0c585e
fix obf crash
Lyfts Jan 16, 2025
c819fb1
compat with double wide surprise & other inv extending mods
Lyfts Jan 17, 2025
8017460
fix offhand being used when placing mainhand blocks
Lyfts Jan 17, 2025
1e1bda9
fix efr totem check
Lyfts Jan 18, 2025
98b7534
prioritize offhand block place when holding TiC tools
Lyfts Jan 18, 2025
f130464
stop constant reset animation when placing blocks in creative
Lyfts Jan 18, 2025
da47385
remove the weird creative survival inv offhand slot
Lyfts Jan 18, 2025
7c37e7d
less indents
Lyfts Jan 18, 2025
00d9cd8
remove the correct creative inv slot
Lyfts Jan 18, 2025
5342687
prioritise using arrows held in offhand when shooting bow
Lyfts Jan 18, 2025
567a793
fix pickblock placing block in wrong slot
Lyfts Jan 18, 2025
839300e
import items from bg2 slots
Lyfts Jan 18, 2025
3e3d241
fix efr remap
Lyfts Jan 18, 2025
32b532c
stack picked up items with offhand first if they're the same item
Lyfts Jan 18, 2025
0e22d7c
stack with mainhand first
Lyfts Jan 18, 2025
3f01a92
Simplify player inventory insert
Caedis Jan 18, 2025
1cc193f
spotless
Caedis Jan 18, 2025
94a079e
upgrade method visibility
Lyfts Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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