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

Fix various issues #21

Merged
merged 16 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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.4.0:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.14-GTNH:dev")
compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.6.2: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.6.2-GTNH:dev")
}
12 changes: 9 additions & 3 deletions src/main/java/xonin/backhand/Backhand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
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.network.NetworkRegistry;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import xonin.backhand.packet.BackhandPacketHandler;
import xonin.backhand.utils.BackhandConfig;

@Mod(
modid = Backhand.MODID,
name = "Backhand",
version = Tags.VERSION,
dependencies = "required-after:gtnhlib@[0.3.2,)",
guiFactory = "xonin.backhand.client.gui.BackhandGuiFactory")
public class Backhand {

Expand Down Expand Up @@ -55,7 +56,6 @@ public void load(FMLPreInitializationEvent event) {
BackhandConfig.getConfig(new Configuration(event.getSuggestedConfigurationFile()));

proxy.load();
NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy);

MinecraftForge.EVENT_BUS.register(new ServerEventsHandler());
FMLCommonHandler.instance()
Expand All @@ -74,8 +74,14 @@ public void init(FMLInitializationEvent event) {
packetHandler.register();
}

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

public static MinecraftServer getServer() {
return MinecraftServer.getServer();
return FMLCommonHandler.instance()
.getMinecraftServerInstance();
}

public static boolean isOffhandBlacklisted(ItemStack stack) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/xonin/backhand/BackhandLateMixins.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xonin.backhand;

import java.util.List;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;

import xonin.backhand.mixins.Mixins;

@LateMixin
public class BackhandLateMixins implements ILateMixinLoader {

@Override
public String getMixinConfig() {
return "mixins.backhand.late.json";
}

@Override
public List<String> getMixins(Set<String> loadedMods) {
return Mixins.getLateMixins(loadedMods);
}
}
27 changes: 10 additions & 17 deletions src/main/java/xonin/backhand/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import xonin.backhand.api.core.BackhandUtils;
import xonin.backhand.utils.EnumAnimations;

public class CommonProxy implements IGuiHandler {
public class CommonProxy {

public static ItemStack offhandItemUsed;

public void load() {

}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
/*
* if(ID > EnumGuiType.values().length)
* return null;
* EnumGuiType gui = EnumGuiType.values()[ID];
* return getContainer(gui, player, x, y, z, npc);
*/
return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
public void onServerStopping(FMLServerStoppingEvent event) {
for (EntityPlayer player : Backhand.getServer()
.getConfigurationManager().playerEntityList) {
if (BackhandUtils.getOffhandItem(player) != null) {
BackhandUtils.resetAndDelayHotswap(player, 0);
}
}
}

public EntityPlayer getClientPlayer() {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/xonin/backhand/HookContainerClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void onEntityJoin(EntityJoinWorldEvent event) {
Backhand.packetHandler.sendPacketToPlayer(
new OffhandConfigSyncPacket(player).generatePacket(),
(EntityPlayerMP) event.entity);
Backhand.packetHandler.sendPacketToPlayer(
new OffhandSyncItemPacket(player).generatePacket(),
(EntityPlayerMP) event.entity);
}
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
if (Backhand.isOffhandBlacklisted(offhandItem)) {
Expand Down Expand Up @@ -285,7 +288,7 @@ public void onOffhandSwing(PlayerEventChild.OffhandSwingEvent event) {}

public boolean interactWithNoEvent(EntityPlayer pl, Entity p_70998_1_) {
ItemStack itemstack = pl.getCurrentEquippedItem();
ItemStack itemstack1 = itemstack != null ? itemstack.copy() : null;
ItemStack itemstack1 = ItemStack.copyItemStack(itemstack);

if (!p_70998_1_.interactFirst(pl)) {
if (itemstack != null && p_70998_1_ instanceof EntityLivingBase) {
Expand Down
73 changes: 32 additions & 41 deletions src/main/java/xonin/backhand/ServerEventsHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package xonin.backhand;

import net.minecraft.block.BlockDispenser;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.RegistrySimple;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
Expand All @@ -16,13 +18,11 @@
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import ganymedes01.etfuturum.ModItems;
import ganymedes01.etfuturum.items.ItemArrowTipped;
import xonin.backhand.api.core.BackhandUtils;
import xonin.backhand.api.core.OffhandExtendedProperty;

public class ServerEventsHandler {

public static boolean arrowHotSwapped = false;
public static boolean regularHotSwap = false;
public static int fireworkHotSwapped = -1;

@SubscribeEvent
Expand All @@ -31,7 +31,9 @@ public void onPlayerInteractNonVanilla(PlayerInteractEvent event) {
EntityPlayer player = event.entityPlayer;
ItemStack mainhandItem = player.getHeldItem();
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
if ((mainhandItem == null || mainhandItem.getItem() != Items.fireworks) && offhandItem != null
if ((mainhandItem == null
|| mainhandItem.getItem() != Items.fireworks && !BackhandUtils.usagePriorAttack(mainhandItem))
&& offhandItem != null
&& offhandItem.getItem() == Items.fireworks) {
fireworkHotSwapped = 1;
}
Expand All @@ -56,6 +58,7 @@ public void onLivingHurt(LivingHurtEvent event) {

ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
ItemStack mainhandItem = player.getCurrentEquippedItem();
OffhandExtendedProperty offhandProp = BackhandUtils.getOffhandEP(player);

if (offhandItem == null) {
return;
Expand All @@ -65,8 +68,8 @@ public void onLivingHurt(LivingHurtEvent event) {
Item totem = ModItems.TOTEM_OF_UNDYING.get();

if (offhandItem.getItem() == totem && (mainhandItem == null || mainhandItem.getItem() != totem)) {
BackhandUtils.swapOffhandItem(player);
regularHotSwap = true;
BackhandUtils.swapOffhandItem(player, 5);
offhandProp.regularHotSwap = true;
}
}
}
Expand All @@ -76,39 +79,30 @@ public void onItemUseStart(PlayerUseItemEvent.Start event) {
EntityPlayer player = event.entityPlayer;
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
ItemStack mainhandItem = player.getCurrentEquippedItem();

// boolean offHandUse = BattlegearUtils.checkForRightClickFunction(offhandItem);
boolean mainhandUse = BackhandUtils.checkForRightClickFunction(mainhandItem);

if (offhandItem != null && !mainhandUse) {
event.setCanceled(true);
}
}

@SubscribeEvent
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onArrowNock(ArrowNockEvent event) {
if (!Backhand.UseOffhandArrows) {
return;
}

boolean overrideWithOffhand = false;
ItemStack offhandItem = BackhandUtils.getOffhandItem(event.entityPlayer);
EntityPlayer player = event.entityPlayer;
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
if (offhandItem != null) {
if (Backhand.isEFRLoaded && offhandItem.getItem() instanceof ItemArrowTipped) {
overrideWithOffhand = true;
if (!((RegistrySimple) BlockDispenser.dispenseBehaviorRegistry).containsKey(offhandItem.getItem())) {
return;
}

if (Items.arrow == offhandItem.getItem()) {
overrideWithOffhand = true;
}

if (overrideWithOffhand) {
event.setCanceled(true);
event.entityPlayer.setItemInUse(
event.result,
event.result.getItem()
.getMaxItemUseDuration(event.result));
}
event.setCanceled(true);
player.setItemInUse(
event.result,
event.result.getItem()
.getMaxItemUseDuration(event.result));
}
}

Expand All @@ -117,49 +111,46 @@ public void onItemFinish(PlayerUseItemEvent.Finish event) {
EntityPlayer player = event.entityPlayer;
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
ItemStack mainhandItem = player.getCurrentEquippedItem();
OffhandExtendedProperty offhandProp = BackhandUtils.getOffhandEP(player);
boolean mainhandUse = BackhandUtils.checkForRightClickFunction(mainhandItem);
if (offhandItem == null || mainhandUse) {
if (offhandItem == null || mainhandUse || offhandProp == null) {
return;
}
if (FMLCommonHandler.instance()
.getEffectiveSide() == Side.SERVER && !ServerTickHandler.tickStartItems.containsKey(player.getUniqueID())) {
BackhandUtils.swapOffhandItem(player);
regularHotSwap = true;
offhandProp.regularHotSwap = true;
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onItemStop(PlayerUseItemEvent.Stop event) {
EntityPlayer player = event.entityPlayer;
ItemStack mainhandItem = player.getCurrentEquippedItem();
OffhandExtendedProperty offhandProp = BackhandUtils.getOffhandEP(player);
boolean skip = BackhandUtils.checkForRightClickFunction(mainhandItem)
|| BackhandUtils.getOffhandItem(player) == null;

if (!skip && !ServerTickHandler.tickStartItems.containsKey(player.getUniqueID()) && !regularHotSwap) {
if (!skip && !ServerTickHandler.tickStartItems.containsKey(player.getUniqueID())
&& !offhandProp.regularHotSwap) {
BackhandUtils.swapOffhandItem(player);
regularHotSwap = true;
offhandProp.regularHotSwap = true;
return;
}

if (!Backhand.UseOffhandArrows || !(event.item.getItem() instanceof ItemBow)) {
return;
}

boolean overrideWithOffhand = false;
ItemStack offhandItem = BackhandUtils.getOffhandItem(player);
if (offhandItem != null) {
if (Backhand.isEFRLoaded && offhandItem.getItem() instanceof ItemArrowTipped) {
overrideWithOffhand = true;
}

if (Items.arrow == offhandItem.getItem()) {
overrideWithOffhand = true;
if (!((RegistrySimple) BlockDispenser.dispenseBehaviorRegistry).containsKey(offhandItem.getItem())) {
return;
}

if (overrideWithOffhand) {
arrowHotSwapped = true;
if (offhandItem.getItem() != Items.arrow) {
BackhandUtils.swapOffhandItem(event.entityPlayer);
}
if (offhandItem.getItem() != Items.arrow) {
offhandProp.regularHotSwap = true;
BackhandUtils.swapOffhandItem(player, 5);
}
}
}
Expand Down
Loading