diff --git a/src/main/java/com/xir/NHUtilities/ClientProxy.java b/src/main/java/com/xir/NHUtilities/ClientProxy.java index 0094d7e..c46ff43 100644 --- a/src/main/java/com/xir/NHUtilities/ClientProxy.java +++ b/src/main/java/com/xir/NHUtilities/ClientProxy.java @@ -1,4 +1,19 @@ package com.xir.NHUtilities; +import com.xir.NHUtilities.client.KeyBindings; +import com.xir.NHUtilities.client.KeyInputHandler; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; + public class ClientProxy extends CommonProxy { + + @Override + public void init(FMLInitializationEvent event) { + super.init(event); + FMLCommonHandler.instance() + .bus() + .register(new KeyInputHandler()); + KeyBindings.init(); + } } diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java new file mode 100644 index 0000000..c84c44c --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java @@ -0,0 +1,122 @@ +package com.xir.NHUtilities.Mixins; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.brandon3055.brandonscore.common.utills.Teleporter; +import com.brandon3055.draconicevolution.client.gui.GUITeleporter; +import com.brandon3055.draconicevolution.common.ModItems; +import com.brandon3055.draconicevolution.common.items.tools.TeleporterMKII; +import com.brandon3055.draconicevolution.common.utills.InventoryUtils; + +// Before modifying this code, please comment out the annotation below. +@SuppressWarnings("all") +@Mixin(value = GUITeleporter.class, remap = false) +public abstract class DE_GUITeleporter_Mixin { + + @Shadow + private ItemStack teleporterItem; + + @Shadow + private EntityPlayer player; + + @Shadow + protected List locations = new ArrayList(0); + + @Shadow + private int tick = 0; + + @Shadow + private int selected = 0; + + @Shadow + private int selectionOffset = 0; + + @Shadow + private boolean showFuelLight = true; + + private GUITeleporter theGUITeleporter = (GUITeleporter) ((Object) this); + + private boolean isBaubles = false; + + @Shadow + protected abstract void readDataFromItem(ItemStack teleporter); + + private Teleporter.TeleportLocation getLocationSafely(int index) { + if (index < locations.size() && index >= 0) return locations.get(index); + return new Teleporter.TeleportLocation(0, 0, 0, 0, 0, 0, EnumChatFormatting.DARK_RED + "[Index Error]"); + } + + @Inject(method = "", at = @At("TAIL"), cancellable = false) + private void setBaubles(EntityPlayer player, CallbackInfo ci) { + Optional playerBaublesInventory = InventoryUtils + .getItemInPlayerBaublesInventory(player, TeleporterMKII.class); + if (player.getHeldItem() != null && player.getHeldItem() + .getItem() == ModItems.teleporterMKII) { + isBaubles = false; + } else if (playerBaublesInventory.isPresent()) { + teleporterItem = playerBaublesInventory.get(); + readDataFromItem(playerBaublesInventory.get()); + isBaubles = true; + } + } + + /** + * @author Keriils + * @reason the simpler method + */ + @Overwrite(remap = false) + public void updateScreen() { + if (handOrBaubles()) { + theGUITeleporter.mc.displayGuiScreen(null); + theGUITeleporter.mc.setIngameFocus(); + } + + if (tick % 5 == 0 && locations.size() > 0 + && getLocationSafely(selected + selectionOffset).getDimensionName() + .equals("") + && banHand()) { + if (isBaubles) { + readDataFromItem( + InventoryUtils.getItemInPlayerBaublesInventory(player, TeleporterMKII.class) + .get()); + } else { + readDataFromItem(player.getHeldItem()); + } + } + + tick++; + if (tick >= 10) { + tick = 0; + showFuelLight = !showFuelLight; + } + } + + private boolean handOrBaubles() { + if (player.isDead) return true; + if (!isBaubles) { + return player.getCurrentEquippedItem() == null || !player.getCurrentEquippedItem() + .isItemEqual(new ItemStack(ModItems.teleporterMKII)); + } + return false; + } + + private boolean banHand() { + if (isBaubles) return true; + return player.getHeldItem() != null && player.getHeldItem() + .getItem() == ModItems.teleporterMKII; + } + +} diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java new file mode 100644 index 0000000..3fca215 --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java @@ -0,0 +1,81 @@ +package com.xir.NHUtilities.Mixins; + +import com.brandon3055.brandonscore.common.utills.InfoHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import org.spongepowered.asm.mixin.Mixin; + +import com.brandon3055.draconicevolution.common.items.tools.TeleporterMKII; + +import baubles.api.BaubleType; +import baubles.api.IBauble; +import cpw.mods.fml.common.Optional; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +// Before modifying this code, please comment out the annotation below. +@SuppressWarnings("all") +@Mixin(value = TeleporterMKII.class, remap = false) +@Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles") +public class DE_TeleporterMKII_Mixin implements IBauble { + + @Inject( + method = "addInformation", + at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z",ordinal = 3,shift = At.Shift.AFTER) + ) + private void addInfo(ItemStack teleporter, EntityPlayer player, List list2, boolean extraInformation, CallbackInfo ci) { + if (InfoHelper.holdShiftForDetails(list2)){ + list2.add( + EnumChatFormatting.GOLD + "" + + EnumChatFormatting.ITALIC + + StatCollector.translateToLocal("info.teleporterInfBaubles.txt")); + list2.add( + EnumChatFormatting.GOLD + "" + + EnumChatFormatting.ITALIC + + StatCollector.translateToLocal("info.teleporterInfBaublesButton.txt")); + } + } + + @Override + @Optional.Method(modid = "Baubles") + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.UNIVERSAL; + } + + @Override + @Optional.Method(modid = "Baubles") + public void onWornTick(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + @Optional.Method(modid = "Baubles") + public void onEquipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + @Optional.Method(modid = "Baubles") + public void onUnequipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + @Optional.Method(modid = "Baubles") + public boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + @Optional.Method(modid = "Baubles") + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } +} diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java new file mode 100644 index 0000000..ab53304 --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java @@ -0,0 +1,45 @@ +package com.xir.NHUtilities.Mixins; + +import java.util.Optional; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import com.brandon3055.draconicevolution.common.ModItems; +import com.brandon3055.draconicevolution.common.items.tools.TeleporterMKII; +import com.brandon3055.draconicevolution.common.network.TeleporterPacket; +import com.brandon3055.draconicevolution.common.utills.InventoryUtils; + +// Before modifying this code, please comment out the annotation below. +@SuppressWarnings("all") +@Mixin(value = TeleporterPacket.Handler.class, remap = false) +public class DE_TeleporterPacket_Mixin { + + @Nullable + private ItemStack getHandOrBaublesTeleporter(EntityPlayerMP instance) { + Optional playerBaublesInventory = InventoryUtils + .getItemInPlayerBaublesInventory(instance, TeleporterMKII.class); + if (instance.inventory.getCurrentItem() != null && instance.inventory.getCurrentItem() + .getItem() == ModItems.teleporterMKII) { + return instance.inventory.getCurrentItem(); + } else if (playerBaublesInventory.isPresent()) { + return playerBaublesInventory.get(); + } + return null; + } + + @Redirect( + method = "onMessage(Lcom/brandon3055/draconicevolution/common/network/TeleporterPacket;Lcpw/mods/fml/common/network/simpleimpl/MessageContext;)Lcpw/mods/fml/common/network/simpleimpl/IMessage;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/player/EntityPlayerMP;getHeldItem()Lnet/minecraft/item/ItemStack;"), + require = 1) + private ItemStack getTeleporterMKII(EntityPlayerMP instance) { + return getHandOrBaublesTeleporter(instance); + } +} diff --git a/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java b/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java index 0d1f5c7..77ddd0a 100644 --- a/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java +++ b/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java @@ -1,5 +1,6 @@ package com.xir.NHUtilities.Mixins; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -31,7 +32,11 @@ public void acceptTargets(Set myTargets, Set otherTargets) { @Override public List getMixins() { - return List.of(); + ArrayList Mixins = new ArrayList<>(); + Mixins.add("DE_TeleporterMKII_Mixin"); + Mixins.add("DE_TeleporterPacket_Mixin"); + Mixins.add("DE_GUITeleporter_Mixin"); + return Mixins; } @Override diff --git a/src/main/java/com/xir/NHUtilities/NHUtilities.java b/src/main/java/com/xir/NHUtilities/NHUtilities.java index f8b2b13..fac6d67 100644 --- a/src/main/java/com/xir/NHUtilities/NHUtilities.java +++ b/src/main/java/com/xir/NHUtilities/NHUtilities.java @@ -13,13 +13,13 @@ @Mod( modid = NHUtilities.MODID, version = Tags.VERSION, - name = NHUtilities.MOD_Name, + name = NHUtilities.MOD_NAME, dependencies = "required-before:IC2; " + "required-before:gregtech; ", acceptedMinecraftVersions = "[1.7.10]") public class NHUtilities { public static final String MODID = "NHUtilities"; - public static final String MOD_Name = "NH Utilities"; + public static final String MOD_NAME = "NH Utilities"; public static final Logger LOG = LogManager.getLogger(MODID); @Mod.Instance diff --git a/src/main/java/com/xir/NHUtilities/client/KeyBindings.java b/src/main/java/com/xir/NHUtilities/client/KeyBindings.java new file mode 100644 index 0000000..49ab049 --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/client/KeyBindings.java @@ -0,0 +1,27 @@ +package com.xir.NHUtilities.client; + +import net.minecraft.client.settings.KeyBinding; + +import org.lwjgl.input.Keyboard; + +import com.brandon3055.draconicevolution.common.lib.References; + +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public final class KeyBindings { + + private KeyBindings() {} + + public static final KeyBinding toggleTeleporterMKII; + + static { + toggleTeleporterMKII = new KeyBinding("key.toggleTeleporterMKII", Keyboard.KEY_NONE, References.MODNAME); + } + + public static void init() { + ClientRegistry.registerKeyBinding(toggleTeleporterMKII); + } +} diff --git a/src/main/java/com/xir/NHUtilities/client/KeyInputHandler.java b/src/main/java/com/xir/NHUtilities/client/KeyInputHandler.java new file mode 100644 index 0000000..f6ed651 --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/client/KeyInputHandler.java @@ -0,0 +1,50 @@ +package com.xir.NHUtilities.client; + +import java.util.Optional; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import com.brandon3055.draconicevolution.DraconicEvolution; +import com.brandon3055.draconicevolution.client.gui.GuiHandler; +import com.brandon3055.draconicevolution.common.items.tools.TeleporterMKII; +import com.brandon3055.draconicevolution.common.utills.InventoryUtils; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * Registers keyInput event by external method for draconic evolution teleporterMKII. + * This method can also be used to register other key events for this mod if needed. + */ +public class KeyInputHandler { + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void onKeyInput(InputEvent.KeyInputEvent event) { + if (KeyBindings.toggleTeleporterMKII.isPressed()) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + World world = player.worldObj; + Optional teleporterMKIIOptional = InventoryUtils + .getItemInPlayerBaublesInventory(player, TeleporterMKII.class); + + if (teleporterMKIIOptional.isPresent()) { + if (world.isRemote) { + FMLNetworkHandler.openGui( + player, + DraconicEvolution.instance, + GuiHandler.GUIID_TELEPORTER, + world, + (int) player.posX, + (int) player.posY, + (int) player.posZ); + } + } + } + } +} diff --git a/src/main/resources/assets/NHUtilities/lang/en_US.lang b/src/main/resources/assets/NHUtilities/lang/en_US.lang new file mode 100644 index 0000000..fdc1336 --- /dev/null +++ b/src/main/resources/assets/NHUtilities/lang/en_US.lang @@ -0,0 +1,3 @@ +key.toggleTeleporterMKII=Toggle Enhanced Charm of Dislocation GUI +info.teleporterInfBaubles.txt=Support putting in-any-baubles +info.teleporterInfBaublesButton.txt=Support the use of - button - to open the baubles diff --git a/src/main/resources/assets/NHUtilities/lang/zh_CN.lang b/src/main/resources/assets/NHUtilities/lang/zh_CN.lang new file mode 100644 index 0000000..69b6a87 --- /dev/null +++ b/src/main/resources/assets/NHUtilities/lang/zh_CN.lang @@ -0,0 +1,3 @@ +key.toggleTeleporterMKII=开关高级传送器GUI +info.teleporterInfBaubles.txt=支持放入-任意-饰品栏目 +info.teleporterInfBaublesButton.txt=支持使用-按键-打开饰品