From 4af2344cf453829cd68f45724a65bc8e8de23f4d Mon Sep 17 00:00:00 2001 From: Furgl Date: Tue, 24 May 2016 22:08:22 -0500 Subject: [PATCH] v1.2 --- build.gradle | 2 +- .../java/furgl/autoPickup/AutoPickup.java | 16 +++++- src/main/java/furgl/autoPickup/IgnoreKey.java | 31 +++++++++++ .../furgl/autoPickup/PacketIgnoreKey.java | 53 +++++++++++++++++++ .../event/EntityItemPickupEvents.java | 3 +- src/main/resources/mcmod.info | 2 +- 6 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/main/java/furgl/autoPickup/IgnoreKey.java create mode 100644 src/main/java/furgl/autoPickup/PacketIgnoreKey.java diff --git a/build.gradle b/build.gradle index 08991c8..6974fc2 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ plugins { id "net.minecraftforge.gradle.forge" version "2.0.2" } -version = "1.8-1.1" +version = "1.8-1.2" group= "furgl.autoPickup" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "AutoPickup" diff --git a/src/main/java/furgl/autoPickup/AutoPickup.java b/src/main/java/furgl/autoPickup/AutoPickup.java index b8ec91a..ec941d5 100644 --- a/src/main/java/furgl/autoPickup/AutoPickup.java +++ b/src/main/java/furgl/autoPickup/AutoPickup.java @@ -1,5 +1,7 @@ package furgl.autoPickup; +import org.lwjgl.input.Keyboard; + import furgl.autoPickup.event.AttackEntityEvents; import furgl.autoPickup.event.BlockEvents; import furgl.autoPickup.event.EntityInteractEvents; @@ -8,17 +10,23 @@ import furgl.autoPickup.event.LivingEvents; import furgl.autoPickup.event.PlaySoundAtEntityEvents; import furgl.autoPickup.event.PlayerInteractEvents; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.relauncher.Side; @Mod(modid = AutoPickup.MODID, name = AutoPickup.MODNAME, version = AutoPickup.VERSION) public class AutoPickup @@ -26,11 +34,15 @@ public class AutoPickup public static final String MODID = "autopickup"; public static final String MODNAME = "AutoPickup"; public static final String VERSION = "1.1"; + + public static SimpleNetworkWrapper network; + public static KeyBinding ignoreBlacklist = new KeyBinding("Ignore Blacklist", Keyboard.KEY_LMENU, "Auto Pickup"); @EventHandler public void preInit(FMLPreInitializationEvent event) { - System.out.println(event.getSuggestedConfigurationFile()); + network = NetworkRegistry.INSTANCE.newSimpleChannel("autoPickupChannel"); + network.registerMessage(PacketIgnoreKey.Handler.class, PacketIgnoreKey.class, 1, Side.SERVER); Config.init(event.getSuggestedConfigurationFile()); } @@ -38,6 +50,7 @@ public void preInit(FMLPreInitializationEvent event) public void init(FMLInitializationEvent event) { registerEventListeners(); + ClientRegistry.registerKeyBinding(ignoreBlacklist); } @EventHandler @@ -56,6 +69,7 @@ public void registerEventListeners() MinecraftForge.EVENT_BUS.register(new PlayerInteractEvents()); MinecraftForge.EVENT_BUS.register(new EntityItemPickupEvents()); MinecraftForge.EVENT_BUS.register(new ItemTossEvents()); + FMLCommonHandler.instance().bus().register(new IgnoreKey()); } public static boolean addItem(EntityPlayer player, ItemStack itemStack, boolean giveIfCreative) diff --git a/src/main/java/furgl/autoPickup/IgnoreKey.java b/src/main/java/furgl/autoPickup/IgnoreKey.java new file mode 100644 index 0000000..2f3d808 --- /dev/null +++ b/src/main/java/furgl/autoPickup/IgnoreKey.java @@ -0,0 +1,31 @@ +package furgl.autoPickup; + +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; +import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class IgnoreKey +{ + public static boolean isPressed; + + public IgnoreKey() + { + + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void playerTick(PlayerTickEvent event) + { + if (event.side == Side.CLIENT && event.phase == Phase.START) + { + if ((AutoPickup.ignoreBlacklist.isPressed() || AutoPickup.ignoreBlacklist.isKeyDown()) != isPressed) + { + isPressed = AutoPickup.ignoreBlacklist.isPressed() || AutoPickup.ignoreBlacklist.isKeyDown(); + AutoPickup.network.sendToServer(new PacketIgnoreKey(isPressed)); + } + } + } +} diff --git a/src/main/java/furgl/autoPickup/PacketIgnoreKey.java b/src/main/java/furgl/autoPickup/PacketIgnoreKey.java new file mode 100644 index 0000000..7959e2c --- /dev/null +++ b/src/main/java/furgl/autoPickup/PacketIgnoreKey.java @@ -0,0 +1,53 @@ +package furgl.autoPickup; + +import io.netty.buffer.ByteBuf; +import net.minecraft.util.IThreadListener; +import net.minecraft.world.WorldServer; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public class PacketIgnoreKey implements IMessage +{ + protected boolean pressed; + + public PacketIgnoreKey() + { + + } + + public PacketIgnoreKey(boolean pressed) + { + this.pressed = pressed; + } + + @Override + public void fromBytes(ByteBuf buf) + { + this.pressed = buf.readBoolean(); + } + + @Override + public void toBytes(ByteBuf buf) + { + buf.writeBoolean(pressed); + } + + public static class Handler implements IMessageHandler + { + @Override + public IMessage onMessage(final PacketIgnoreKey packet, final MessageContext ctx) + { + IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; + mainThread.addScheduledTask(new Runnable() + { + @Override + public void run() + { + IgnoreKey.isPressed = packet.pressed; + } + }); + return null; + } + } +} \ No newline at end of file diff --git a/src/main/java/furgl/autoPickup/event/EntityItemPickupEvents.java b/src/main/java/furgl/autoPickup/event/EntityItemPickupEvents.java index 3ce599c..7696296 100644 --- a/src/main/java/furgl/autoPickup/event/EntityItemPickupEvents.java +++ b/src/main/java/furgl/autoPickup/event/EntityItemPickupEvents.java @@ -1,6 +1,7 @@ package furgl.autoPickup.event; import furgl.autoPickup.Config; +import furgl.autoPickup.IgnoreKey; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -11,7 +12,7 @@ public class EntityItemPickupEvents public void onEvent(EntityItemPickupEvent event) { Config.syncFromConfig(event.entityPlayer.getName()); - if (Config.blacklistNames.contains(event.item.getEntityItem().getItem().getItemStackDisplayName(event.item.getEntityItem()).replace(" ", "_"))) + if (!IgnoreKey.isPressed && Config.blacklistNames.contains(event.item.getEntityItem().getItem().getItemStackDisplayName(event.item.getEntityItem()).replace(" ", "_"))) { event.item.setDefaultPickupDelay(); event.setCanceled(true); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4f665f6..c9bbc35 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "autopickup", "name": "AutoPickup", "description": "Allows items to be picked up automatically or blacklisted and never picked up.", - "version": "1.1", + "version": "1.2", "mcversion": "1.8", "url": "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2566182-1-8-furgls-mods-auto-pickup-baby-mobs", "updateUrl": "",