From 296a484f4bd94f0e809a2fa35db065a3ba5c1a66 Mon Sep 17 00:00:00 2001 From: OniBait Date: Thu, 3 Oct 2013 01:46:17 -0500 Subject: [PATCH 1/4] Add block break events based on @bloodmc's initial 1.5.2 Pull Request --- .../net/minecraftforge/common/FakePlayer.java | 9 +- .../common/FakePlayerFactory.java | 18 +++- .../event/world/BlockEvent.java | 55 ++++++++++++ .../net/minecraft/block/Block.java.patch | 35 +++++--- .../item/ItemInWorldManager.java.patch | 86 +++++++++++++++++-- 5 files changed, 179 insertions(+), 24 deletions(-) diff --git a/common/net/minecraftforge/common/FakePlayer.java b/common/net/minecraftforge/common/FakePlayer.java index 1d462593f..7d63255fb 100644 --- a/common/net/minecraftforge/common/FakePlayer.java +++ b/common/net/minecraftforge/common/FakePlayer.java @@ -1,16 +1,19 @@ package net.minecraftforge.common; -import net.minecraft.entity.player.EntityPlayer; +import cpw.mods.fml.common.FMLCommonHandler; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemInWorldManager; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; //Preliminary, simple Fake Player class -public class FakePlayer extends EntityPlayer +public class FakePlayer extends EntityPlayerMP { public FakePlayer(World world, String name) { - super(world, name); + super(FMLCommonHandler.instance().getMinecraftServerInstance(), world, name, new ItemInWorldManager(world)); } public void sendChatToPlayer(String s){} diff --git a/common/net/minecraftforge/common/FakePlayerFactory.java b/common/net/minecraftforge/common/FakePlayerFactory.java index 80b334c25..ac102c8a3 100644 --- a/common/net/minecraftforge/common/FakePlayerFactory.java +++ b/common/net/minecraftforge/common/FakePlayerFactory.java @@ -5,14 +5,30 @@ import net.minecraft.world.World; //To be expanded for generic Mod fake players? public class FakePlayerFactory { + // Map of all active fake player usernames to their entities + private static java.util.Map fakePlayers = new java.util.HashMap(); private static FakePlayer MINECRAFT_PLAYER = null; public static FakePlayer getMinecraft(World world) { if (MINECRAFT_PLAYER == null) { - MINECRAFT_PLAYER = new FakePlayer(world, "[Minecraft]"); + MINECRAFT_PLAYER = FakePlayerFactory.get(world, "[Minecraft]"); } return MINECRAFT_PLAYER; } + + /** + * Get a fake player with a given username + */ + public static FakePlayer get(World world, String username) + { + if (!fakePlayers.containsKey(username)) + { + FakePlayer fakePlayer = new FakePlayer(world, username); + fakePlayers.put(username, fakePlayer); + } + + return fakePlayers.get(username); + } } diff --git a/common/net/minecraftforge/event/world/BlockEvent.java b/common/net/minecraftforge/event/world/BlockEvent.java index f86d37bd7..e0e549aba 100644 --- a/common/net/minecraftforge/event/world/BlockEvent.java +++ b/common/net/minecraftforge/event/world/BlockEvent.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.event.Cancelable; import net.minecraftforge.event.Event; public class BlockEvent extends Event { @@ -53,5 +54,59 @@ public class BlockEvent extends Event { this.harvester = harvester; } } + + /** + * Fired when a block is broken and about to drop experience + * The amount of experience that is dropped can be retrieved or set + */ + public static class ExperienceDropsEvent extends BlockEvent + { + private int exp; + public ExperienceDropsEvent(int x, int y, int z, World world, Block block, int blockMetadata, int exp) + { + super(x, y, z, world, block, blockMetadata); + this.exp = exp; + } + + /** + * Get the experience dropped by the block after the event has processed + * + * @return The experience to drop + */ + public int getExpToDrop() + { + return exp; + } + + /** + * Set the amount of experience dropped by the block after the event has processed + * + * @param exp 1 or higher to drop experience, else nothing will drop + */ + public void setExpToDrop(int exp) + { + this.exp = exp; + } + } + + /** + * Event that is fired when an Block is about to be broken by a player + * Canceling this event will prevent the Block from being broken. + */ + @Cancelable + public static class BreakEvent extends BlockEvent + { + /** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */ + private final EntityPlayer player; + public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player) { + super(x, y, z, world, block, blockMetadata); + this.player = player; + } + + public EntityPlayer getPlayer() + { + return player; + } + } } diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index 7c4d8bf20..f98529ecb 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -36,7 +36,7 @@ import net.minecraft.util.Icon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.StatCollector; -@@ -35,9 +44,20 @@ +@@ -35,9 +44,22 @@ import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -45,8 +45,10 @@ +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.IPlantable; ++import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.RotationHelper; +import net.minecraftforge.event.ForgeEventFactory; ++import net.minecraftforge.event.world.BlockEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; @@ -57,7 +59,7 @@ /** * used as foreach item, if item.tab = current tab, display it on the screen */ -@@ -460,9 +480,10 @@ +@@ -460,9 +482,10 @@ return this.needsRandomTick; } @@ -69,7 +71,7 @@ } /** -@@ -485,7 +506,7 @@ +@@ -485,7 +508,7 @@ */ public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -78,7 +80,7 @@ } @SideOnly(Side.CLIENT) -@@ -495,7 +516,7 @@ +@@ -495,7 +518,7 @@ */ public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -87,7 +89,7 @@ } @SideOnly(Side.CLIENT) -@@ -648,7 +669,13 @@ +@@ -648,7 +671,13 @@ * different metadata value, but before the new metadata value is set. Args: World, x, y, z, old block ID, old * metadata */ @@ -102,7 +104,7 @@ /** * Returns the quantity of items to drop on block destruction. -@@ -673,7 +700,7 @@ +@@ -673,7 +702,7 @@ public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4, int par5) { float f = this.getBlockHardness(par2World, par3, par4, par5); @@ -111,7 +113,7 @@ } /** -@@ -691,18 +718,14 @@ +@@ -691,18 +720,14 @@ { if (!par1World.isRemote) { @@ -135,7 +137,18 @@ } } } -@@ -935,7 +958,8 @@ +@@ -732,6 +757,10 @@ + { + if (!par1World.isRemote) + { ++ BlockEvent.ExperienceDropsEvent event = new BlockEvent.ExperienceDropsEvent(par2, par3, par4, par1World, this, par1World.getBlockMetadata(par2, par3, par4), par5); ++ MinecraftForge.EVENT_BUS.post(event); ++ par5 = event.getExpToDrop(); ++ + while (par5 > 0) + { + int i1 = EntityXPOrb.getXPSplit(par5); +@@ -935,7 +964,8 @@ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { int l = par1World.getBlockId(par2, par3, par4); @@ -145,7 +158,7 @@ } /** -@@ -1086,6 +1110,7 @@ +@@ -1086,6 +1116,7 @@ */ public void setBlockBoundsForItemRender() {} @@ -153,7 +166,7 @@ /** * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the * block and l is the block's subtype/damage. -@@ -1095,28 +1120,37 @@ +@@ -1095,28 +1126,37 @@ par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); par2EntityPlayer.addExhaustion(0.025F); @@ -198,7 +211,7 @@ } /** -@@ -1457,4 +1491,993 @@ +@@ -1457,4 +1497,993 @@ canBlockGrass[0] = true; StatList.initBreakableStats(); } diff --git a/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch b/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch index 61c281d30..9bbaad8de 100644 --- a/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch +++ b/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch @@ -1,6 +1,11 @@ --- ../src_base/minecraft/net/minecraft/item/ItemInWorldManager.java +++ ../src_work/minecraft/net/minecraft/item/ItemInWorldManager.java -@@ -8,8 +8,19 @@ +@@ -4,12 +4,25 @@ + import net.minecraft.entity.player.EntityPlayer; + import net.minecraft.entity.player.EntityPlayerMP; + import net.minecraft.network.packet.Packet53BlockChange; ++import net.minecraft.tileentity.TileEntity; + import net.minecraft.world.EnumGameType; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -11,6 +16,7 @@ +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; ++import net.minecraftforge.event.world.BlockEvent; + public class ItemInWorldManager { @@ -20,7 +26,7 @@ /** The world object that this object is connected to. */ public World theWorld; -@@ -145,6 +156,13 @@ +@@ -145,6 +158,13 @@ { if (!this.gameType.isAdventure() || this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) { @@ -34,7 +40,7 @@ if (this.isCreative()) { if (!this.theWorld.extinguishFire((EntityPlayer)null, par1, par2, par3, par4)) -@@ -154,15 +172,33 @@ +@@ -154,15 +174,33 @@ } else { @@ -73,7 +79,7 @@ } if (i1 > 0 && f >= 1.0F) -@@ -236,7 +272,7 @@ +@@ -236,7 +274,7 @@ block.onBlockHarvested(this.theWorld, par1, par2, par3, l, this.thisPlayerMP); } @@ -82,8 +88,20 @@ if (block != null && flag) { -@@ -261,19 +297,30 @@ +@@ -251,29 +289,37 @@ + */ + public boolean tryHarvestBlock(int par1, int par2, int par3) + { +- if (this.gameType.isAdventure() && !this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) ++ BlockEvent.BreakEvent event = triggerBlockBreakEvent(par1, par2, par3); ++ if (event.isCanceled()) + { + return false; } +- else if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) +- { +- return false; +- } else { + ItemStack stack = thisPlayerMP.getCurrentEquippedItem(); @@ -115,7 +133,7 @@ if (itemstack != null) { -@@ -285,6 +332,7 @@ +@@ -285,6 +331,7 @@ } } @@ -123,7 +141,57 @@ if (flag && flag1) { Block.blocksList[l].harvestBlock(this.theWorld, this.thisPlayerMP, par1, par2, par3, i1); -@@ -325,6 +373,7 @@ +@@ -293,6 +340,49 @@ + + return flag; + } ++ } ++ ++ private BlockEvent.BreakEvent triggerBlockBreakEvent(int par1, int par2, int par3) ++ { ++ // Logic from tryHarvestBlock for pre-canceling the event ++ boolean preCancelEvent = false; ++ if (this.gameType.isAdventure() && !this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) ++ { ++ preCancelEvent = true; ++ } ++ else if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) ++ { ++ preCancelEvent = true; ++ } ++ ++ // Tell client the block is gone immediately then process events ++ if (theWorld.getBlockTileEntity(par1, par2, par3) == null) ++ { ++ Packet53BlockChange packet = new Packet53BlockChange(par1, par2, par3, this.theWorld); ++ packet.type = 0; ++ packet.metadata = 0; ++ ((EntityPlayerMP) this.thisPlayerMP).playerNetServerHandler.sendPacketToPlayer(packet); ++ } ++ ++ // Post the block break event ++ Block block = Block.blocksList[this.theWorld.getBlockId(par1, par2, par3)]; ++ BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(par1, par2, par3, this.theWorld, block, this.theWorld.getBlockMetadata(par1, par2, par3), this.thisPlayerMP); ++ event.setCanceled(preCancelEvent); ++ MinecraftForge.EVENT_BUS.post(event); ++ ++ // Handle if the event is canceled ++ if (event.isCanceled()) ++ { ++ // Let the client know the block still exists ++ ((EntityPlayerMP) this.thisPlayerMP).playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par1, par2, par3, this.theWorld)); ++ // Update any tile entity data for this block ++ TileEntity tileentity = this.theWorld.getBlockTileEntity(par1, par2, par3); ++ if (tileentity != null) ++ { ++ this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(tileentity.getDescriptionPacket()); ++ } ++ } ++ return event; + } + + /** +@@ -325,6 +415,7 @@ if (itemstack1.stackSize == 0) { par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = null; @@ -131,7 +199,7 @@ } if (!par1EntityPlayer.isUsingItem()) -@@ -342,35 +391,56 @@ +@@ -342,35 +433,56 @@ */ public boolean activateBlockOrUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { @@ -215,7 +283,7 @@ } /** -@@ -380,4 +450,13 @@ +@@ -380,4 +492,13 @@ { this.theWorld = par1WorldServer; } From eb5940664c885027ae43474f3956fdcfbd2f24c1 Mon Sep 17 00:00:00 2001 From: OniBait Date: Tue, 8 Oct 2013 19:00:02 -0500 Subject: [PATCH 2/4] Add block break events based on @bloodmc's initial 1.5.2 Pull Request --- common/forge_at.cfg | 1 + .../net/minecraftforge/common/ForgeHooks.java | 54 +++++++++++++++ .../event/world/BlockEvent.java | 55 ++++++++-------- .../net/minecraft/block/Block.java.patch | 43 ++++++------ .../block/BlockMobSpawner.java.patch | 17 +++++ .../net/minecraft/block/BlockOre.java.patch | 50 ++++++++++++++ .../block/BlockRedstoneOre.java.patch | 26 ++++++++ .../item/ItemInWorldManager.java.patch | 65 ++++--------------- 8 files changed, 208 insertions(+), 103 deletions(-) create mode 100644 patches/minecraft/net/minecraft/block/BlockMobSpawner.java.patch create mode 100644 patches/minecraft/net/minecraft/block/BlockOre.java.patch create mode 100644 patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch diff --git a/common/forge_at.cfg b/common/forge_at.cfg index 5c6996cdd..0356e872a 100644 --- a/common/forge_at.cfg +++ b/common/forge_at.cfg @@ -47,6 +47,7 @@ public aqz.a(F)Laqz; #MD:Block/func_71900_a #setLightValue public aqz.r()Laqz; #MD:Block/func_71875_q #setBlockUnbreakable public aqz.b(Z)Laqz; #MD:Block/func_71907_b #setTickRandomly public aqz.a(FFFFFF)V #MD:Block/func_71905_a #setBlockBounds +public aqz.j(Labw;IIII)V #MD:Block/func_71923_g #dropXpOnBlockBreak # NetServerHandler public ka.f #FD:NetServerHandler/field_72572_g #playerInAirTime # TileEntity diff --git a/common/net/minecraftforge/common/ForgeHooks.java b/common/net/minecraftforge/common/ForgeHooks.java index 7916f10ba..aa430b6ff 100644 --- a/common/net/minecraftforge/common/ForgeHooks.java +++ b/common/net/minecraftforge/common/ForgeHooks.java @@ -7,17 +7,23 @@ import java.util.HashSet; import java.util.List; import net.minecraft.block.Block; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; import net.minecraft.network.NetServerHandler; +import net.minecraft.network.packet.Packet53BlockChange; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.DamageSource; @@ -26,7 +32,9 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.WeightedRandom; import net.minecraft.util.WeightedRandomItem; +import net.minecraft.world.EnumGameType; import net.minecraft.world.World; +import net.minecraftforge.event.Event; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; @@ -38,6 +46,7 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.event.world.BlockEvent; public class ForgeHooks { @@ -430,4 +439,49 @@ public class ForgeHooks } return event.component; } + + public static BlockEvent.BreakEvent onBlockBreakEvent(World world, EnumGameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) + { + // Logic from tryHarvestBlock for pre-canceling the event + boolean preCancelEvent = false; + if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z)) + { + preCancelEvent = true; + } + else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) + { + preCancelEvent = true; + } + + // Tell client the block is gone immediately then process events + if (world.getBlockTileEntity(x, y, z) == null) + { + Packet53BlockChange packet = new Packet53BlockChange(x, y, z, world); + packet.type = 0; + packet.metadata = 0; + entityPlayer.playerNetServerHandler.sendPacketToPlayer(packet); + } + + // Post the block break event + Block block = Block.blocksList[world.getBlockId(x, y, z)]; + int blockMetadata = world.getBlockMetadata(x, y, z); + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); + event.setCanceled(preCancelEvent); + MinecraftForge.EVENT_BUS.post(event); + + // Handle if the event is canceled + if (event.isCanceled()) + { + // Let the client know the block still exists + entityPlayer.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(x, y, z, world)); + + // Update any tile entity data for this block + TileEntity tileentity = world.getBlockTileEntity(x, y, z); + if (tileentity != null) + { + entityPlayer.playerNetServerHandler.sendPacketToPlayer(tileentity.getDescriptionPacket()); + } + } + return event; + } } diff --git a/common/net/minecraftforge/event/world/BlockEvent.java b/common/net/minecraftforge/event/world/BlockEvent.java index e0e549aba..f94c7c75e 100644 --- a/common/net/minecraftforge/event/world/BlockEvent.java +++ b/common/net/minecraftforge/event/world/BlockEvent.java @@ -3,6 +3,7 @@ package net.minecraftforge.event.world; import java.util.ArrayList; import net.minecraft.block.Block; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -56,27 +57,47 @@ public class BlockEvent extends Event { } /** - * Fired when a block is broken and about to drop experience - * The amount of experience that is dropped can be retrieved or set + * Event that is fired when an Block is about to be broken by a player + * Canceling this event will prevent the Block from being broken. */ - public static class ExperienceDropsEvent extends BlockEvent + @Cancelable + public static class BreakEvent extends BlockEvent { + /** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */ + private final EntityPlayer player; private int exp; - public ExperienceDropsEvent(int x, int y, int z, World world, Block block, int blockMetadata, int exp) + public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player) { super(x, y, z, world, block, blockMetadata); - this.exp = exp; + this.player = player; + + if (block == null || !player.canHarvestBlock(block) || // Handle empty block or player unable to break block scenario + block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player)) // If the block is being silk harvested, the exp dropped is 0 + { + this.exp = 0; + } + else + { + int meta = block.getDamageValue(world, x, y, z); + int bonusLevel = EnchantmentHelper.getFortuneModifier(player); + this.exp = block.getExpDrop(world, meta, bonusLevel); + } } + public EntityPlayer getPlayer() + { + return player; + } + /** * Get the experience dropped by the block after the event has processed * - * @return The experience to drop + * @return The experience to drop or 0 if the event was canceled */ public int getExpToDrop() { - return exp; + return this.isCanceled() ? 0 : exp; } /** @@ -89,24 +110,4 @@ public class BlockEvent extends Event { this.exp = exp; } } - - /** - * Event that is fired when an Block is about to be broken by a player - * Canceling this event will prevent the Block from being broken. - */ - @Cancelable - public static class BreakEvent extends BlockEvent - { - /** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */ - private final EntityPlayer player; - public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player) { - super(x, y, z, world, block, blockMetadata); - this.player = player; - } - - public EntityPlayer getPlayer() - { - return player; - } - } } diff --git a/patches/minecraft/net/minecraft/block/Block.java.patch b/patches/minecraft/net/minecraft/block/Block.java.patch index f98529ecb..4a691a02e 100644 --- a/patches/minecraft/net/minecraft/block/Block.java.patch +++ b/patches/minecraft/net/minecraft/block/Block.java.patch @@ -36,7 +36,7 @@ import net.minecraft.util.Icon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.StatCollector; -@@ -35,9 +44,22 @@ +@@ -35,9 +44,20 @@ import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -45,10 +45,8 @@ +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.IPlantable; -+import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.RotationHelper; +import net.minecraftforge.event.ForgeEventFactory; -+import net.minecraftforge.event.world.BlockEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; @@ -59,7 +57,7 @@ /** * used as foreach item, if item.tab = current tab, display it on the screen */ -@@ -460,9 +482,10 @@ +@@ -460,9 +480,10 @@ return this.needsRandomTick; } @@ -71,7 +69,7 @@ } /** -@@ -485,7 +508,7 @@ +@@ -485,7 +506,7 @@ */ public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -80,7 +78,7 @@ } @SideOnly(Side.CLIENT) -@@ -495,7 +518,7 @@ +@@ -495,7 +516,7 @@ */ public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -89,7 +87,7 @@ } @SideOnly(Side.CLIENT) -@@ -648,7 +671,13 @@ +@@ -648,7 +669,13 @@ * different metadata value, but before the new metadata value is set. Args: World, x, y, z, old block ID, old * metadata */ @@ -104,7 +102,7 @@ /** * Returns the quantity of items to drop on block destruction. -@@ -673,7 +702,7 @@ +@@ -673,7 +700,7 @@ public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4, int par5) { float f = this.getBlockHardness(par2World, par3, par4, par5); @@ -113,7 +111,7 @@ } /** -@@ -691,18 +720,14 @@ +@@ -691,18 +718,14 @@ { if (!par1World.isRemote) { @@ -137,18 +135,7 @@ } } } -@@ -732,6 +757,10 @@ - { - if (!par1World.isRemote) - { -+ BlockEvent.ExperienceDropsEvent event = new BlockEvent.ExperienceDropsEvent(par2, par3, par4, par1World, this, par1World.getBlockMetadata(par2, par3, par4), par5); -+ MinecraftForge.EVENT_BUS.post(event); -+ par5 = event.getExpToDrop(); -+ - while (par5 > 0) - { - int i1 = EntityXPOrb.getXPSplit(par5); -@@ -935,7 +964,8 @@ +@@ -935,7 +958,8 @@ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { int l = par1World.getBlockId(par2, par3, par4); @@ -158,7 +145,7 @@ } /** -@@ -1086,6 +1116,7 @@ +@@ -1086,6 +1110,7 @@ */ public void setBlockBoundsForItemRender() {} @@ -166,7 +153,7 @@ /** * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the * block and l is the block's subtype/damage. -@@ -1095,28 +1126,37 @@ +@@ -1095,28 +1120,37 @@ par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); par2EntityPlayer.addExhaustion(0.025F); @@ -211,7 +198,7 @@ } /** -@@ -1457,4 +1497,993 @@ +@@ -1457,4 +1491,1001 @@ canBlockGrass[0] = true; StatList.initBreakableStats(); } @@ -1164,6 +1151,14 @@ + } + return false; + } ++ ++ /** ++ * @return the amount of XP that this block should drop when it is broken ++ */ ++ public int getExpDrop(World world, int data, int enchantmentLevel) ++ { ++ return 0; ++ } + + /** + * Called when a tile entity on a side of this block changes is created or is destroyed. diff --git a/patches/minecraft/net/minecraft/block/BlockMobSpawner.java.patch b/patches/minecraft/net/minecraft/block/BlockMobSpawner.java.patch new file mode 100644 index 000000000..605fe5464 --- /dev/null +++ b/patches/minecraft/net/minecraft/block/BlockMobSpawner.java.patch @@ -0,0 +1,17 @@ +--- ../src_base/minecraft/net/minecraft/block/BlockMobSpawner.java ++++ ../src_work/minecraft/net/minecraft/block/BlockMobSpawner.java +@@ -45,8 +45,12 @@ + public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) + { + super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); +- int j1 = 15 + par1World.rand.nextInt(15) + par1World.rand.nextInt(15); +- this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); ++ } ++ ++ @Override ++ public int getExpDrop(World world, int data, int enchantmentLevel) ++ { ++ return 15 + world.rand.nextInt(15) + world.rand.nextInt(15); + } + + /** diff --git a/patches/minecraft/net/minecraft/block/BlockOre.java.patch b/patches/minecraft/net/minecraft/block/BlockOre.java.patch new file mode 100644 index 000000000..7026487b8 --- /dev/null +++ b/patches/minecraft/net/minecraft/block/BlockOre.java.patch @@ -0,0 +1,50 @@ +--- ../src_base/minecraft/net/minecraft/block/BlockOre.java ++++ ../src_work/minecraft/net/minecraft/block/BlockOre.java +@@ -59,34 +59,36 @@ + public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) + { + super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); +- +- if (this.idDropped(par5, par1World.rand, par7) != this.blockID) ++ } ++ ++ @Override ++ public int getExpDrop(World world, int data, int enchantmentLevel) ++ { ++ int j1 = 0; ++ if (this.idDropped(data, world.rand, enchantmentLevel) != this.blockID) + { +- int j1 = 0; +- + if (this.blockID == Block.oreCoal.blockID) + { +- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 0, 2); ++ j1 = MathHelper.getRandomIntegerInRange(world.rand, 0, 2); + } + else if (this.blockID == Block.oreDiamond.blockID) + { +- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 3, 7); ++ j1 = MathHelper.getRandomIntegerInRange(world.rand, 3, 7); + } + else if (this.blockID == Block.oreEmerald.blockID) + { +- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 3, 7); ++ j1 = MathHelper.getRandomIntegerInRange(world.rand, 3, 7); + } + else if (this.blockID == Block.oreLapis.blockID) + { +- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 2, 5); ++ j1 = MathHelper.getRandomIntegerInRange(world.rand, 2, 5); + } + else if (this.blockID == Block.oreNetherQuartz.blockID) + { +- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 2, 5); ++ j1 = MathHelper.getRandomIntegerInRange(world.rand, 2, 5); + } +- +- this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); + } ++ return j1; + } + + /** diff --git a/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch b/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch new file mode 100644 index 000000000..cbad99390 --- /dev/null +++ b/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch @@ -0,0 +1,26 @@ +--- ../src_base/minecraft/net/minecraft/block/BlockRedstoneOre.java ++++ ../src_work/minecraft/net/minecraft/block/BlockRedstoneOre.java +@@ -115,12 +115,17 @@ + public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) + { + super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); +- +- if (this.idDropped(par5, par1World.rand, par7) != this.blockID) +- { +- int j1 = 1 + par1World.rand.nextInt(5); +- this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); +- } ++ } ++ ++ @Override ++ public int getExpDrop(World world, int data, int enchantmentLevel) ++ { ++ int j1 = 0; ++ if (this.idDropped(data, world.rand, enchantmentLevel) != this.blockID) ++ { ++ j1 = 1 + world.rand.nextInt(5); ++ } ++ return j1; + } + + @SideOnly(Side.CLIENT) diff --git a/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch b/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch index 9bbaad8de..37bb8c940 100644 --- a/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch +++ b/patches/minecraft/net/minecraft/item/ItemInWorldManager.java.patch @@ -93,7 +93,7 @@ public boolean tryHarvestBlock(int par1, int par2, int par3) { - if (this.gameType.isAdventure() && !this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) -+ BlockEvent.BreakEvent event = triggerBlockBreakEvent(par1, par2, par3); ++ BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, par1, par2, par3); + if (event.isCanceled()) { return false; @@ -133,7 +133,7 @@ if (itemstack != null) { -@@ -285,6 +331,7 @@ +@@ -285,11 +331,18 @@ } } @@ -141,57 +141,18 @@ if (flag && flag1) { Block.blocksList[l].harvestBlock(this.theWorld, this.thisPlayerMP, par1, par2, par3, i1); -@@ -293,6 +340,49 @@ + } + } ++ ++ // Drop experience ++ if (!this.isCreative() && flag && event != null) ++ { ++ Block.blocksList[l].dropXpOnBlockBreak(this.theWorld, par1, par2, par3, event.getExpToDrop()); ++ } return flag; } -+ } -+ -+ private BlockEvent.BreakEvent triggerBlockBreakEvent(int par1, int par2, int par3) -+ { -+ // Logic from tryHarvestBlock for pre-canceling the event -+ boolean preCancelEvent = false; -+ if (this.gameType.isAdventure() && !this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) -+ { -+ preCancelEvent = true; -+ } -+ else if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) -+ { -+ preCancelEvent = true; -+ } -+ -+ // Tell client the block is gone immediately then process events -+ if (theWorld.getBlockTileEntity(par1, par2, par3) == null) -+ { -+ Packet53BlockChange packet = new Packet53BlockChange(par1, par2, par3, this.theWorld); -+ packet.type = 0; -+ packet.metadata = 0; -+ ((EntityPlayerMP) this.thisPlayerMP).playerNetServerHandler.sendPacketToPlayer(packet); -+ } -+ -+ // Post the block break event -+ Block block = Block.blocksList[this.theWorld.getBlockId(par1, par2, par3)]; -+ BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(par1, par2, par3, this.theWorld, block, this.theWorld.getBlockMetadata(par1, par2, par3), this.thisPlayerMP); -+ event.setCanceled(preCancelEvent); -+ MinecraftForge.EVENT_BUS.post(event); -+ -+ // Handle if the event is canceled -+ if (event.isCanceled()) -+ { -+ // Let the client know the block still exists -+ ((EntityPlayerMP) this.thisPlayerMP).playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(par1, par2, par3, this.theWorld)); -+ // Update any tile entity data for this block -+ TileEntity tileentity = this.theWorld.getBlockTileEntity(par1, par2, par3); -+ if (tileentity != null) -+ { -+ this.thisPlayerMP.playerNetServerHandler.sendPacketToPlayer(tileentity.getDescriptionPacket()); -+ } -+ } -+ return event; - } - - /** -@@ -325,6 +415,7 @@ +@@ -325,6 +378,7 @@ if (itemstack1.stackSize == 0) { par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = null; @@ -199,7 +160,7 @@ } if (!par1EntityPlayer.isUsingItem()) -@@ -342,35 +433,56 @@ +@@ -342,35 +396,56 @@ */ public boolean activateBlockOrUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { @@ -283,7 +244,7 @@ } /** -@@ -380,4 +492,13 @@ +@@ -380,4 +455,13 @@ { this.theWorld = par1WorldServer; } From e47a6402e1ec779ef9ff5e7ff91e5d332c04fd1d Mon Sep 17 00:00:00 2001 From: OniBait Date: Thu, 10 Oct 2013 12:45:56 -0500 Subject: [PATCH 3/4] Fixed formatting --- common/net/minecraftforge/common/FakePlayerFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/net/minecraftforge/common/FakePlayerFactory.java b/common/net/minecraftforge/common/FakePlayerFactory.java index ac102c8a3..430bec2b5 100644 --- a/common/net/minecraftforge/common/FakePlayerFactory.java +++ b/common/net/minecraftforge/common/FakePlayerFactory.java @@ -22,13 +22,13 @@ public class FakePlayerFactory * Get a fake player with a given username */ public static FakePlayer get(World world, String username) - { + { if (!fakePlayers.containsKey(username)) { FakePlayer fakePlayer = new FakePlayer(world, username); fakePlayers.put(username, fakePlayer); } - + return fakePlayers.get(username); - } + } } From 79e016536202aab6c7c7c9a466f3cf86887eff79 Mon Sep 17 00:00:00 2001 From: OniBait Date: Thu, 10 Oct 2013 17:15:38 -0500 Subject: [PATCH 4/4] Cleaned up patches to BlockOre and BlockRedstoneOre Fixed trailing whitespace (it bugs me too) --- .../common/FakePlayerFactory.java | 2 +- .../net/minecraft/block/BlockOre.java.patch | 47 +++++-------------- .../block/BlockRedstoneOre.java.patch | 24 ++++------ 3 files changed, 23 insertions(+), 50 deletions(-) diff --git a/common/net/minecraftforge/common/FakePlayerFactory.java b/common/net/minecraftforge/common/FakePlayerFactory.java index 430bec2b5..e3d0f3a93 100644 --- a/common/net/minecraftforge/common/FakePlayerFactory.java +++ b/common/net/minecraftforge/common/FakePlayerFactory.java @@ -28,7 +28,7 @@ public class FakePlayerFactory FakePlayer fakePlayer = new FakePlayer(world, username); fakePlayers.put(username, fakePlayer); } - + return fakePlayers.get(username); } } diff --git a/patches/minecraft/net/minecraft/block/BlockOre.java.patch b/patches/minecraft/net/minecraft/block/BlockOre.java.patch index 7026487b8..ad83441b3 100644 --- a/patches/minecraft/net/minecraft/block/BlockOre.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockOre.java.patch @@ -1,50 +1,27 @@ --- ../src_base/minecraft/net/minecraft/block/BlockOre.java +++ ../src_work/minecraft/net/minecraft/block/BlockOre.java -@@ -59,34 +59,36 @@ - public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) +@@ -60,6 +60,11 @@ { super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); -- -- if (this.idDropped(par5, par1World.rand, par7) != this.blockID) + + } + + @Override -+ public int getExpDrop(World world, int data, int enchantmentLevel) ++ public int getExpDrop(World par1World, int par5, int par7) + { -+ int j1 = 0; -+ if (this.idDropped(data, world.rand, enchantmentLevel) != this.blockID) + if (this.idDropped(par5, par1World.rand, par7) != this.blockID) { -- int j1 = 0; -- - if (this.blockID == Block.oreCoal.blockID) + int j1 = 0; +@@ -84,9 +89,10 @@ { -- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 0, 2); -+ j1 = MathHelper.getRandomIntegerInRange(world.rand, 0, 2); + j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 2, 5); } - else if (this.blockID == Block.oreDiamond.blockID) - { -- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 3, 7); -+ j1 = MathHelper.getRandomIntegerInRange(world.rand, 3, 7); - } - else if (this.blockID == Block.oreEmerald.blockID) - { -- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 3, 7); -+ j1 = MathHelper.getRandomIntegerInRange(world.rand, 3, 7); - } - else if (this.blockID == Block.oreLapis.blockID) - { -- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 2, 5); -+ j1 = MathHelper.getRandomIntegerInRange(world.rand, 2, 5); - } - else if (this.blockID == Block.oreNetherQuartz.blockID) - { -- j1 = MathHelper.getRandomIntegerInRange(par1World.rand, 2, 5); -+ j1 = MathHelper.getRandomIntegerInRange(world.rand, 2, 5); - } -- ++ return j1; ++ } + - this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); - } -+ return j1; +- } ++ return 0; } /** diff --git a/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch b/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch index cbad99390..5fac601b4 100644 --- a/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockRedstoneOre.java.patch @@ -1,26 +1,22 @@ --- ../src_base/minecraft/net/minecraft/block/BlockRedstoneOre.java +++ ../src_work/minecraft/net/minecraft/block/BlockRedstoneOre.java -@@ -115,12 +115,17 @@ - public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) +@@ -116,11 +116,17 @@ { super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7); -- -- if (this.idDropped(par5, par1World.rand, par7) != this.blockID) -- { -- int j1 = 1 + par1World.rand.nextInt(5); -- this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); -- } + + } + + @Override -+ public int getExpDrop(World world, int data, int enchantmentLevel) ++ public int getExpDrop(World par1World, int par5, int par7) + { -+ int j1 = 0; -+ if (this.idDropped(data, world.rand, enchantmentLevel) != this.blockID) -+ { -+ j1 = 1 + world.rand.nextInt(5); + if (this.idDropped(par5, par1World.rand, par7) != this.blockID) + { + int j1 = 1 + par1World.rand.nextInt(5); +- this.dropXpOnBlockBreak(par1World, par2, par3, par4, j1); +- } ++ return j1; + } -+ return j1; ++ return 0; } @SideOnly(Side.CLIENT)