244 lines
11 KiB
Diff
244 lines
11 KiB
Diff
--- ../src-base/minecraft/net/minecraftforge/common/ForgeHooks.java
|
|
+++ ../src-work/minecraft/net/minecraftforge/common/ForgeHooks.java
|
|
@@ -1,5 +1,14 @@
|
|
package net.minecraftforge.common;
|
|
|
|
+import static net.minecraft.init.Blocks.diamond_block;
|
|
+import static net.minecraft.init.Blocks.diamond_ore;
|
|
+import static net.minecraft.init.Blocks.emerald_block;
|
|
+import static net.minecraft.init.Blocks.emerald_ore;
|
|
+import static net.minecraft.init.Blocks.gold_block;
|
|
+import static net.minecraft.init.Blocks.gold_ore;
|
|
+import static net.minecraft.init.Blocks.lit_redstone_ore;
|
|
+import static net.minecraft.init.Blocks.redstone_ore;
|
|
+
|
|
import java.net.URI;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
@@ -7,6 +16,8 @@
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
+import cc.capture.type.CaptureBlock;
|
|
+import cc.capture.type.CaptureTree;
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
import net.minecraft.block.Block;
|
|
@@ -20,19 +31,15 @@
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.inventory.ContainerRepair;
|
|
import net.minecraft.inventory.IInventory;
|
|
-import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemArmor;
|
|
import net.minecraft.item.ItemAxe;
|
|
import net.minecraft.item.ItemBucket;
|
|
import net.minecraft.item.ItemPickaxe;
|
|
import net.minecraft.item.ItemSpade;
|
|
import net.minecraft.item.ItemStack;
|
|
-import net.minecraft.item.ItemSword;
|
|
-import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.network.NetHandlerPlayServer;
|
|
import net.minecraft.network.Packet;
|
|
import net.minecraft.network.play.server.S23PacketBlockChange;
|
|
-import net.minecraft.stats.StatList;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.tileentity.TileEntityNote;
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
@@ -46,8 +53,9 @@
|
|
import net.minecraft.util.WeightedRandom;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.WorldSettings.GameType;
|
|
+// Cauldron start
|
|
+import net.minecraftforge.common.util.FakePlayer;
|
|
import net.minecraftforge.event.AnvilUpdateEvent;
|
|
-import net.minecraftforge.event.ForgeEventFactory;
|
|
import net.minecraftforge.event.ServerChatEvent;
|
|
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
@@ -58,11 +66,10 @@
|
|
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.entity.player.PlayerOpenContainerEvent;
|
|
import net.minecraftforge.event.entity.player.AnvilRepairEvent;
|
|
+import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
|
|
import net.minecraftforge.event.world.BlockEvent;
|
|
import net.minecraftforge.event.world.NoteBlockEvent;
|
|
-import static net.minecraft.init.Blocks.*;
|
|
|
|
public class ForgeHooks
|
|
{
|
|
@@ -379,10 +386,12 @@
|
|
public static ChatComponentTranslation onServerChatEvent(NetHandlerPlayServer net, String raw, ChatComponentTranslation comp)
|
|
{
|
|
ServerChatEvent event = new ServerChatEvent(net.playerEntity, raw, comp);
|
|
+ synchronized (ServerChatEvent.class) {
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
{
|
|
return null;
|
|
}
|
|
+ }
|
|
return event.component;
|
|
}
|
|
|
|
@@ -439,6 +448,8 @@
|
|
|
|
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z)
|
|
{
|
|
+ // Cauldron - pre-cancel handled in BreakEvent
|
|
+ /*
|
|
// Logic from tryHarvestBlock for pre-canceling the event
|
|
boolean preCancelEvent = false;
|
|
if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z))
|
|
@@ -449,9 +460,9 @@
|
|
{
|
|
preCancelEvent = true;
|
|
}
|
|
-
|
|
+ */
|
|
// Tell client the block is gone immediately then process events
|
|
- if (world.getTileEntity(x, y, z) == null)
|
|
+ if (world.getTileEntity(x, y, z) == null && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers
|
|
{
|
|
S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world);
|
|
packet.field_148883_d = Blocks.air;
|
|
@@ -463,11 +474,11 @@
|
|
Block block = world.getBlock(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);
|
|
+ // event.setCanceled(preCancelEvent); // Cauldron
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
// Handle if the event is canceled
|
|
- if (event.isCanceled())
|
|
+ if (event.isCanceled() && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers
|
|
{
|
|
// Let the client know the block still exists
|
|
entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
|
|
@@ -488,95 +499,43 @@
|
|
|
|
public static boolean onPlaceItemIntoWorld(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
{
|
|
- // handle all placement events here
|
|
- int meta = itemstack.getItemDamage();
|
|
- int size = itemstack.stackSize;
|
|
- NBTTagCompound nbt = null;
|
|
- if (itemstack.getTagCompound() != null)
|
|
- {
|
|
- nbt = (NBTTagCompound)itemstack.getTagCompound().copy();
|
|
- }
|
|
+ // handle all placement events here
|
|
+ CaptureBlock tCapture=null;
|
|
+ CaptureTree tTreeGenCapture=null;
|
|
|
|
- if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket
|
|
- {
|
|
- world.captureBlockSnapshots = true;
|
|
+ if(!(itemstack.getItem() instanceof ItemBucket)){ // if not bucket
|
|
+ tCapture=world.mCapture.startCapture(player,itemstack);
|
|
+ tCapture.setAgaistPostionAndSide(side,x,y,z);
|
|
+ // Cauldron start
|
|
+ if(itemstack.getItem() instanceof net.minecraft.item.ItemDye&&itemstack.getItemDamage()==15){
|
|
+ Block block=world.getBlock(x,y,z);
|
|
+ if(block!=null&&(block instanceof net.minecraft.block.BlockSapling||block instanceof net.minecraft.block.BlockMushroom)){
|
|
+ tTreeGenCapture=world.mCapture.startTreeGenCapture(player,x,y,z);
|
|
+ tTreeGenCapture.setAgaistPostionAndSide(x,y,z,side);
|
|
+ }
|
|
+ }
|
|
+ // Cauldron end
|
|
}
|
|
|
|
- boolean flag = itemstack.getItem().onItemUse(itemstack, player, world, x, y, z, side, hitX, hitY, hitZ);
|
|
- world.captureBlockSnapshots = false;
|
|
+ ItemStack.currentPlayer=player; // Cauldron
|
|
+ boolean flag=itemstack.getItem().onItemUse(itemstack,player,world,x,y,z,side,hitX,hitY,hitZ);
|
|
+ ItemStack.currentPlayer=null; // Cauldron
|
|
|
|
- if (flag)
|
|
- {
|
|
- // save new item data
|
|
- int newMeta = itemstack.getItemDamage();
|
|
- int newSize = itemstack.stackSize;
|
|
- NBTTagCompound newNBT = null;
|
|
- if (itemstack.getTagCompound() != null)
|
|
- {
|
|
- newNBT = (NBTTagCompound)itemstack.getTagCompound().copy();
|
|
- }
|
|
- net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
|
|
- List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<net.minecraftforge.common.util.BlockSnapshot>) world.capturedBlockSnapshots.clone();
|
|
- world.capturedBlockSnapshots.clear();
|
|
+ if(tCapture!=null) tCapture.disableCapture();
|
|
+ if(tTreeGenCapture!=null) tTreeGenCapture.disableCapture();
|
|
|
|
- // make sure to set pre-placement item data for event
|
|
- itemstack.setItemDamage(meta);
|
|
- itemstack.stackSize = size;
|
|
- if (nbt != null)
|
|
- {
|
|
- itemstack.setTagCompound(nbt);
|
|
+ // Cauldron start
|
|
+ if(flag){
|
|
+ if(tTreeGenCapture!=null&&tTreeGenCapture.mCapturedBlocks.size()>0){
|
|
+ tTreeGenCapture.endCapture();
|
|
+ }else if(tCapture!=null){
|
|
+ tCapture.endCapture();
|
|
}
|
|
- if (blockSnapshots.size() > 1)
|
|
- {
|
|
- placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, net.minecraftforge.common.util.ForgeDirection.getOrientation(side));
|
|
- }
|
|
- else if (blockSnapshots.size() == 1)
|
|
- {
|
|
- placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), net.minecraftforge.common.util.ForgeDirection.getOrientation(side));
|
|
- }
|
|
-
|
|
- if (placeEvent != null && (placeEvent.isCanceled()))
|
|
- {
|
|
- flag = false; // 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;
|
|
- }
|
|
- }
|
|
- else
|
|
- {
|
|
- // Change the stack to its new content
|
|
- itemstack.setItemDamage(newMeta);
|
|
- itemstack.stackSize = newSize;
|
|
- if (nbt != null)
|
|
- {
|
|
- itemstack.setTagCompound(newNBT);
|
|
- }
|
|
-
|
|
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
|
|
- {
|
|
- int blockX = blocksnapshot.x;
|
|
- int blockY = blocksnapshot.y;
|
|
- int blockZ = blocksnapshot.z;
|
|
- int metadata = world.getBlockMetadata(blockX, blockY, blockZ);
|
|
- int updateFlag = blocksnapshot.flag;
|
|
- Block oldBlock = blocksnapshot.replacedBlock;
|
|
- Block newBlock = world.getBlock(blockX, blockY, blockZ);
|
|
- if (newBlock != null && !(newBlock.hasTileEntity(metadata))) // Containers get placed automatically
|
|
- {
|
|
- newBlock.onBlockAdded(world, blockX, blockY, blockZ);
|
|
- }
|
|
-
|
|
- world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag);
|
|
- }
|
|
- player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);
|
|
- }
|
|
}
|
|
- world.capturedBlockSnapshots.clear();
|
|
|
|
+ if(tCapture!=null) tCapture.markHandled();
|
|
+ if(tTreeGenCapture!=null) tTreeGenCapture.markHandled();
|
|
+
|
|
return flag;
|
|
}
|
|
|