From 85516d9588ebfadbba25f21b2f973e4e81abbaa6 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 17 Dec 2013 11:24:57 -0500 Subject: [PATCH] ICraftingHandler, IPickupHandler are now both events. --- .../entity/item/EntityItem.java.patch | 4 +- .../inventory/SlotCrafting.java.patch | 4 +- .../inventory/SlotFurnace.java.patch | 4 +- .../cpw/mods/fml/common/FMLCommonHandler.java | 18 ++++++++ .../cpw/mods/fml/common/IConsoleHandler.java | 22 ---------- .../cpw/mods/fml/common/ICraftingHandler.java | 42 ------------------ .../cpw/mods/fml/common/IPickupNotifier.java | 21 --------- .../fml/common/gameevent/PlayerEvent.java | 31 +++++++++++++ .../fml/common/registry/GameRegistry.java | 44 +------------------ 9 files changed, 57 insertions(+), 133 deletions(-) delete mode 100644 src/main/java/cpw/mods/fml/common/IConsoleHandler.java delete mode 100644 src/main/java/cpw/mods/fml/common/ICraftingHandler.java delete mode 100644 src/main/java/cpw/mods/fml/common/IPickupNotifier.java diff --git a/patches/minecraft/net/minecraft/entity/item/EntityItem.java.patch b/patches/minecraft/net/minecraft/entity/item/EntityItem.java.patch index c4916e9248..4798e9ed69 100644 --- a/patches/minecraft/net/minecraft/entity/item/EntityItem.java.patch +++ b/patches/minecraft/net/minecraft/entity/item/EntityItem.java.patch @@ -4,7 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -+import cpw.mods.fml.common.registry.GameRegistry; ++import cpw.mods.fml.common.FMLCommonHandler; + public class EntityItem extends Entity { @@ -13,7 +13,7 @@ } } -+ GameRegistry.onPickupNotification(p_70100_1_, this); ++ FMLCommonHandler.instance().firePlayerItemPickupEvent(p_70100_1_, this); + this.field_70170_p.func_72956_a(p_70100_1_, "random.pop", 0.2F, ((this.field_70146_Z.nextFloat() - this.field_70146_Z.nextFloat()) * 0.7F + 1.0F) * 2.0F); p_70100_1_.func_71001_a(this, i); diff --git a/patches/minecraft/net/minecraft/inventory/SlotCrafting.java.patch b/patches/minecraft/net/minecraft/inventory/SlotCrafting.java.patch index 4e5aa974f9..fe83af5f2f 100644 --- a/patches/minecraft/net/minecraft/inventory/SlotCrafting.java.patch +++ b/patches/minecraft/net/minecraft/inventory/SlotCrafting.java.patch @@ -3,7 +3,7 @@ @@ -1,5 +1,6 @@ package net.minecraft.inventory; -+import cpw.mods.fml.common.registry.GameRegistry; ++import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -11,7 +11,7 @@ public void func_82870_a(EntityPlayer p_82870_1_, ItemStack p_82870_2_) { -+ GameRegistry.onItemCrafted(p_82870_1_, p_82870_2_, field_75239_a); ++ FMLCommonHandler.instance().firePlayerCraftingEvent(p_82870_1_, p_82870_2_, field_75239_a); this.func_75208_c(p_82870_2_); for (int i = 0; i < this.field_75239_a.func_70302_i_(); ++i) diff --git a/patches/minecraft/net/minecraft/inventory/SlotFurnace.java.patch b/patches/minecraft/net/minecraft/inventory/SlotFurnace.java.patch index a4e31ab0b8..3837df4f66 100644 --- a/patches/minecraft/net/minecraft/inventory/SlotFurnace.java.patch +++ b/patches/minecraft/net/minecraft/inventory/SlotFurnace.java.patch @@ -3,7 +3,7 @@ @@ -1,5 +1,6 @@ package net.minecraft.inventory; -+import cpw.mods.fml.common.registry.GameRegistry; ++import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; @@ -11,7 +11,7 @@ this.field_75228_b = 0; -+ GameRegistry.onItemSmelted(field_75229_a, p_75208_1_); ++ FMLCommonHandler.instance().firePlayerSmeltedEvent(field_75229_a, p_75208_1_); + if (p_75208_1_.func_77973_b() == Items.field_151042_j) { diff --git a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java index 6a459bef37..40c2c96971 100644 --- a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java +++ b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java @@ -18,7 +18,10 @@ import java.util.Set; import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -467,4 +470,19 @@ public class FMLCommonHandler { bus().post(new PlayerEvent.PlayerRespawnEvent(player)); } + + public void firePlayerItemPickupEvent(EntityPlayer player, EntityItem item) + { + bus().post(new PlayerEvent.ItemPickupEvent(player, item)); + } + + public void firePlayerCraftingEvent(EntityPlayer player, ItemStack crafted, IInventory craftMatrix) + { + bus().post(new PlayerEvent.ItemCraftedEvent(player, crafted, craftMatrix)); + } + + public void firePlayerSmeltedEvent(EntityPlayer player, ItemStack smelted) + { + bus().post(new PlayerEvent.ItemSmeltedEvent(player, smelted)); + } } diff --git a/src/main/java/cpw/mods/fml/common/IConsoleHandler.java b/src/main/java/cpw/mods/fml/common/IConsoleHandler.java deleted file mode 100644 index 30b8fe4088..0000000000 --- a/src/main/java/cpw/mods/fml/common/IConsoleHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Forge Mod Loader - * Copyright (c) 2012-2013 cpw. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v2.1 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * - * Contributors: - * cpw - implementation - */ - -package cpw.mods.fml.common; - -/** - * @author cpw - * - */ -public interface IConsoleHandler -{ - public boolean handleCommand(String command, Object... data); -} diff --git a/src/main/java/cpw/mods/fml/common/ICraftingHandler.java b/src/main/java/cpw/mods/fml/common/ICraftingHandler.java deleted file mode 100644 index 37a19ea807..0000000000 --- a/src/main/java/cpw/mods/fml/common/ICraftingHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Forge Mod Loader - * Copyright (c) 2012-2013 cpw. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v2.1 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * - * Contributors: - * cpw - implementation - */ - -package cpw.mods.fml.common; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -/** - * Return a crafting handler for the mod container to call - * - * @author cpw - * - */ -public interface ICraftingHandler -{ - /** - * The object array contains these three arguments - * - * @param player - * @param item - * @param craftMatrix - */ - void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix); - - /** - * The object array contains these two arguments - * @param player - * @param item - */ - void onSmelting(EntityPlayer player, ItemStack item); -} diff --git a/src/main/java/cpw/mods/fml/common/IPickupNotifier.java b/src/main/java/cpw/mods/fml/common/IPickupNotifier.java deleted file mode 100644 index c201c51928..0000000000 --- a/src/main/java/cpw/mods/fml/common/IPickupNotifier.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Forge Mod Loader - * Copyright (c) 2012-2013 cpw. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v2.1 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * - * Contributors: - * cpw - implementation - */ - -package cpw.mods.fml.common; - -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; - -public interface IPickupNotifier -{ - void notifyPickup(EntityItem item, EntityPlayer player); -} diff --git a/src/main/java/cpw/mods/fml/common/gameevent/PlayerEvent.java b/src/main/java/cpw/mods/fml/common/gameevent/PlayerEvent.java index 960f9d0e18..31ba84b502 100644 --- a/src/main/java/cpw/mods/fml/common/gameevent/PlayerEvent.java +++ b/src/main/java/cpw/mods/fml/common/gameevent/PlayerEvent.java @@ -1,6 +1,9 @@ package cpw.mods.fml.common.gameevent; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import cpw.mods.fml.common.eventhandler.Event; public class PlayerEvent extends Event { @@ -10,6 +13,34 @@ public class PlayerEvent extends Event { this.player = player; } + public static class ItemPickupEvent extends PlayerEvent { + public final EntityItem pickedUp; + public ItemPickupEvent(EntityPlayer player, EntityItem pickedUp) + { + super(player); + this.pickedUp = pickedUp; + } + } + + public static class ItemCraftedEvent extends PlayerEvent { + public final ItemStack crafting; + public final IInventory craftMatrix; + public ItemCraftedEvent(EntityPlayer player, ItemStack crafting, IInventory craftMatrix) + { + super(player); + this.crafting = crafting; + this.craftMatrix = craftMatrix; + } + } + public static class ItemSmeltedEvent extends PlayerEvent { + public final ItemStack smelting; + public ItemSmeltedEvent(EntityPlayer player, ItemStack crafting) + { + super(player); + this.smelting = crafting; + } + } + public static class PlayerLoggedInEvent extends PlayerEvent { public PlayerLoggedInEvent(EntityPlayer player) { diff --git a/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java b/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java index 47291522d0..3fdfe9f21b 100644 --- a/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java +++ b/src/main/java/cpw/mods/fml/common/registry/GameRegistry.java @@ -17,12 +17,8 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; -import org.apache.logging.log4j.Level; import net.minecraft.block.Block; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; @@ -33,14 +29,14 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; +import org.apache.logging.log4j.Level; + import com.google.common.base.Objects; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IFuelHandler; -import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.LoaderException; @@ -51,8 +47,6 @@ public class GameRegistry { private static Set worldGenerators = Sets.newHashSet(); private static List fuelHandlers = Lists.newArrayList(); - private static List craftingHandlers = Lists.newArrayList(); - private static List pickupHandlers = Lists.newArrayList(); /** * Register a world generator - something that inserts new block types into the world @@ -242,40 +236,6 @@ public class GameRegistry return fuelValue; } - public static void registerCraftingHandler(ICraftingHandler handler) - { - craftingHandlers.add(handler); - } - - public static void onItemCrafted(EntityPlayer player, ItemStack item, IInventory craftMatrix) - { - for (ICraftingHandler handler : craftingHandlers) - { - handler.onCrafting(player, item, craftMatrix); - } - } - - public static void onItemSmelted(EntityPlayer player, ItemStack item) - { - for (ICraftingHandler handler : craftingHandlers) - { - handler.onSmelting(player, item); - } - } - - public static void registerPickupHandler(IPickupNotifier handler) - { - pickupHandlers.add(handler); - } - - public static void onPickupNotification(EntityPlayer player, EntityItem item) - { - for (IPickupNotifier notify : pickupHandlers) - { - notify.notifyPickup(item, player); - } - } - /** * Look up a mod block in the global "named item list" * @param modId The modid owning the block