forked from c0508383/Backhand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TiC battle sign not working in offhand (#55)
- Loading branch information
Showing
12 changed files
with
164 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package xonin.backhand.compat; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
|
||
import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber; | ||
|
||
import cpw.mods.fml.common.eventhandler.EventPriority; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import ganymedes01.etfuturum.ModItems; | ||
import ganymedes01.etfuturum.core.handlers.ServerEventHandler; | ||
import xonin.backhand.api.core.BackhandUtils; | ||
import xonin.backhand.utils.Mods; | ||
|
||
@SuppressWarnings("unused") | ||
@EventBusSubscriber | ||
public class EFRCompat { | ||
|
||
@EventBusSubscriber.Condition | ||
public static boolean register() { | ||
return Mods.ET_FUTURUM.isLoaded(); | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
public static void onEntityHurt(LivingHurtEvent event) { | ||
if (!(event.entityLiving instanceof EntityPlayer player)) return; | ||
ItemStack offhand = BackhandUtils.getOffhandItem(player); | ||
if (offhand == null) return; | ||
Item totem = ModItems.TOTEM_OF_UNDYING.get(); | ||
if (totem.equals(offhand.getItem())) { | ||
BackhandUtils.useOffhandItem(player, () -> ServerEventHandler.INSTANCE.handleTotemCheck(player, event)); | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/xonin/backhand/compat/TConstructCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package xonin.backhand.compat; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.client.event.RenderGameOverlayEvent; | ||
import net.minecraftforge.event.entity.living.LivingAttackEvent; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
|
||
import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber; | ||
|
||
import cpw.mods.fml.common.eventhandler.EventPriority; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import tconstruct.library.tools.HarvestTool; | ||
import tconstruct.library.weaponry.IWindup; | ||
import tconstruct.tools.TinkerToolEvents; | ||
import tconstruct.tools.TinkerTools; | ||
import tconstruct.weaponry.client.CrosshairHandler; | ||
import tconstruct.world.TinkerWorldEvents; | ||
import xonin.backhand.api.core.BackhandUtils; | ||
import xonin.backhand.utils.Mods; | ||
|
||
@SuppressWarnings("unused") | ||
@EventBusSubscriber | ||
public class TConstructCompat { | ||
|
||
private static CrosshairHandler crosshairHandler; | ||
private static MethodHandle onHurt, onAttack; | ||
|
||
@EventBusSubscriber.Condition | ||
public static boolean register() { | ||
if (Mods.TINKERS_CONSTRUCT.isLoaded()) { | ||
try { | ||
// Gotta hide those NEW instructions from the JVM | ||
crosshairHandler = CrosshairHandler.class.getConstructor() | ||
.newInstance(); | ||
// These need to be MethodHandles since the compiler complains about Mobs-Info not being present | ||
// otherwise | ||
onHurt = MethodHandles.publicLookup() | ||
.findVirtual( | ||
TinkerWorldEvents.class, | ||
"onHurt", | ||
MethodType.methodType(void.class, LivingHurtEvent.class)) | ||
.bindTo( | ||
TinkerWorldEvents.class.getConstructor() | ||
.newInstance()); | ||
onAttack = MethodHandles.publicLookup() | ||
.findVirtual( | ||
TinkerToolEvents.class, | ||
"onAttack", | ||
MethodType.methodType(void.class, LivingAttackEvent.class)) | ||
.bindTo( | ||
TinkerToolEvents.class.getConstructor() | ||
.newInstance()); | ||
} catch (Exception ignored) {} | ||
BackhandUtils.addOffhandPriorityItem(HarvestTool.class); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
public static void onEntityHurt(LivingHurtEvent event) { | ||
if (!(event.entityLiving instanceof EntityPlayer player) || event.ammount == 0) return; | ||
ItemStack offhandItem = BackhandUtils.getOffhandItem(player); | ||
if (offhandItem == null) return; | ||
if (offhandItem.getItem() == TinkerTools.cutlass || offhandItem.getItem() == TinkerTools.battlesign) { | ||
BackhandUtils.useOffhandItem(player, () -> { | ||
try { | ||
onHurt.invokeWithArguments(event); | ||
} catch (Throwable ignored) {} | ||
}); | ||
} | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
public static void onAttack(LivingAttackEvent event) { | ||
if (!(event.entityLiving instanceof EntityPlayer player)) return; | ||
ItemStack offhand = BackhandUtils.getOffhandItem(player); | ||
if (offhand == null) return; | ||
if (offhand.getItem() == TinkerTools.battlesign) { | ||
BackhandUtils.useOffhandItem(player, () -> { | ||
try { | ||
onAttack.invokeWithArguments(event); | ||
} catch (Throwable ignored) {} | ||
}); | ||
} | ||
} | ||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
public static void onRenderOverlay(RenderGameOverlayEvent.Pre event) { | ||
if (event.type != RenderGameOverlayEvent.ElementType.CROSSHAIRS) return; | ||
EntityPlayer player = Minecraft.getMinecraft().thePlayer; | ||
ItemStack offhand = BackhandUtils.getOffhandItem(player); | ||
if (offhand != null && offhand.getItem() instanceof IWindup) { | ||
BackhandUtils.useOffhandItem(player, () -> crosshairHandler.onRenderOverlay(event)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
src/main/java/xonin/backhand/mixins/late/etfuturum/MixinServerEventHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.