Files
CatServer/patches/net/minecraftforge/common/ForgeHooks.java.patch

268 lines
12 KiB
Diff

--- ../src-base/minecraft/net/minecraftforge/common/ForgeHooks.java
+++ ../src-work/minecraft/net/minecraftforge/common/ForgeHooks.java
@@ -30,6 +30,13 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.entity.Player;
+import org.bukkit.event.world.StructureGrowEvent;
+
import com.google.common.base.Throwables;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
@@ -39,6 +46,8 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
+import net.minecraft.block.BlockMushroom;
+import net.minecraft.block.BlockSapling;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@@ -46,6 +55,7 @@
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
+import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityMinecartContainer;
@@ -62,6 +72,7 @@
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemBucket;
+import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
@@ -98,6 +109,7 @@
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraftforge.common.util.BlockSnapshot;
+import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.AnvilUpdateEvent;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.ServerChatEvent;
@@ -312,7 +324,7 @@
return;
}
- itemstack = block.func_185473_a(this.theWorld, blockpos, iblockstate);
+ itemstack = block.getItem(this.theWorld, blockpos, iblockstate);
if (itemstack == null)
{
@@ -358,7 +370,7 @@
EntityMinecart entityminecart = (EntityMinecart)this.objectMouseOver.entityHit;
Item item;
- switch (entityminecart.func_184264_v())
+ switch (entityminecart.getType())
{
case FURNACE:
item = Items.furnace_minecart;
@@ -383,7 +395,7 @@
}
else if (this.objectMouseOver.entityHit instanceof EntityBoat)
{
- itemstack = new ItemStack(((EntityBoat)this.objectMouseOver.entityHit).func_184455_j());
+ itemstack = new ItemStack(((EntityBoat)this.objectMouseOver.entityHit).getItemBoat());
}
else if (this.objectMouseOver.entityHit instanceof EntityArmorStand)
{
@@ -391,7 +403,7 @@
}
else if (this.objectMouseOver.entityHit instanceof EntityEnderCrystal)
{
- itemstack = new ItemStack(Items.field_185158_cP);
+ itemstack = new ItemStack(Items.END_CRYSTAL);
}
else
{
@@ -403,7 +415,7 @@
}
itemstack = new ItemStack(Items.spawn_egg);
- ItemMonsterPlacer.func_185078_a(itemstack, s);
+ ItemMonsterPlacer.applyEntityIdToItemStack(itemstack, s);
}
}
*/
@@ -710,7 +722,7 @@
public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos)
{
// Logic from tryHarvestBlock for pre-canceling the event
- boolean preCancelEvent = false;
+ /* boolean preCancelEvent = false;
if (gameType.isCreative() && entityPlayer.getHeldItemMainhand() != null && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
preCancelEvent = true;
@@ -725,10 +737,10 @@
if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
preCancelEvent = true;
}
- }
+ }*/
// Tell client the block is gone immediately then process events
- if (world.getTileEntity(pos) == null)
+ if (world.getTileEntity(pos) == null && !(entityPlayer instanceof FakePlayer))
{
SPacketBlockChange packet = new SPacketBlockChange(world, pos);
packet.blockState = Blocks.AIR.getDefaultState();
@@ -738,11 +750,11 @@
// Post the block break event
IBlockState state = world.getBlockState(pos);
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, entityPlayer);
- event.setCanceled(preCancelEvent);
+ //event.setCanceled(preCancelEvent);
MinecraftForge.EVENT_BUS.post(event);
// Handle if the event is canceled
- if (event.isCanceled())
+ if (event.isCanceled() && !(entityPlayer instanceof FakePlayer))
{
// Let the client know the block still exists
entityPlayer.connection.sendPacket(new SPacketBlockChange(world, pos));
@@ -766,6 +778,7 @@
// handle all placement events here
int meta = itemstack.getItemDamage();
int size = itemstack.stackSize;
+ int data = itemstack.getMetadata();
NBTTagCompound nbt = null;
if (itemstack.getTagCompound() != null)
{
@@ -774,79 +787,57 @@
if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket
{
- world.captureBlockSnapshots = true;
+ world.mCapture.startCapture(player,itemstack,side,hand);
+ // CraftBukkit start
+ if(itemstack.getItem() instanceof ItemDye && itemstack.getMetadata() == 15){
+ Block block = world.getBlockState(pos).getBlock();
+ if(block == Blocks.SAPLING || block instanceof BlockMushroom){
+ world.captureTreeGeneration = true;
+ }
+ }
+ // CraftBukkit end
}
EnumActionResult ret = itemstack.getItem().onItemUse(itemstack, player, world, pos, hand, side, hitX, hitY, hitZ);
- world.captureBlockSnapshots = false;
+ world.mCapture.endCapture();
- if (ret == EnumActionResult.SUCCESS)
- {
- // save new item data
- int newMeta = itemstack.getItemDamage();
- int newSize = itemstack.stackSize;
- NBTTagCompound newNBT = null;
- if (itemstack.getTagCompound() != null)
- {
- newNBT = (NBTTagCompound)itemstack.getTagCompound().copy();
+ // CraftBukkit start
+ int newCount = itemstack.stackSize;
+ if (ret == EnumActionResult.SUCCESS && world.captureTreeGeneration && world.capturedBlockSnapshots.size() > 0) {
+ List<BlockState> blocks = new ArrayList();
+ for (net.minecraftforge.common.util.BlockSnapshot snapshot : (List<net.minecraftforge.common.util.BlockSnapshot>) world.capturedBlockSnapshots.clone()) {
+ blocks.add(new CraftBlockState(snapshot));
}
- net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
- @SuppressWarnings("unchecked")
- List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<BlockSnapshot>)world.capturedBlockSnapshots.clone();
- world.capturedBlockSnapshots.clear();
- // make sure to set pre-placement item data for event
- itemstack.setItemDamage(meta);
- itemstack.stackSize = size;
- if (nbt != null)
- {
- itemstack.setTagCompound(nbt);
+ world.captureTreeGeneration = false;
+ Location location = new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ());
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
+ world.capturedBlockSnapshots.clear();
+ StructureGrowEvent event = null;
+ if (treeType != null) {
+ boolean isBonemeal = itemstack.getItem() == Items.DYE && data == 15;
+ event = new StructureGrowEvent(location, treeType, isBonemeal, (Player) player.getBukkitEntity(), blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
}
- if (blockSnapshots.size() > 1)
- {
- placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand);
- }
- else if (blockSnapshots.size() == 1)
- {
- placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
- }
-
- if (placeEvent != null && (placeEvent.isCanceled()))
- {
- ret = EnumActionResult.FAIL; // cancel placement
- // revert back all captured blocks
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
- {
- world.restoringBlockSnapshots = true;
- blocksnapshot.restore(true, false);
- world.restoringBlockSnapshots = false;
+ if (event == null || !event.isCancelled()) {
+ // Change the stack to its new contents if it hasn't been tampered with.
+ if (itemstack.stackSize == size && itemstack.getMetadata() == data) {
+ itemstack.stackSize = newCount;
}
- }
- else
- {
- // Change the stack to its new content
- itemstack.setItemDamage(newMeta);
- itemstack.stackSize = newSize;
- if (nbt != null)
- {
- itemstack.setTagCompound(newNBT);
+ for (BlockState blockstate : blocks) {
+ blockstate.update(true);
}
-
- for (BlockSnapshot snap : blockSnapshots)
- {
- int updateFlag = snap.getFlag();
- IBlockState oldBlock = snap.getReplacedBlock();
- IBlockState newBlock = world.getBlockState(snap.getPos());
- if (newBlock != null && !(newBlock.getBlock().hasTileEntity(newBlock))) // Containers get placed automatically
- {
- newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock);
- }
-
- world.markAndNotifyBlock(snap.getPos(), null, oldBlock, newBlock, updateFlag);
- }
- player.addStat(StatList.getObjectUseStats(itemstack.getItem()));
}
+ return ret;
}
+ world.captureTreeGeneration = false;
+ // CraftBukkit end
+
+ if (ret == EnumActionResult.SUCCESS)
+ {
+ return world.mCapture.handleCapture(itemstack);
+ }
world.capturedBlockSnapshots.clear();
return ret;
@@ -884,7 +875,7 @@
}
/**
- * Default implementation of IRecipe.func_179532_b {getRemainingItems} because
+ * Default implementation of IRecipe.getRemainingItems {getRemainingItems} because
* this is just copy pasted over a lot of recipes.
*
* Another use case for java 8 but sadly we can't use it!