1
0
forked from xjboss/KCauldronX
KCauldronX/patches/net/minecraftforge/common/ForgeHooks.java.patch

244 lines
11 KiB
Diff
Raw Normal View History

2015-03-22 17:38:04 +00:00
--- ../src-base/minecraft/net/minecraftforge/common/ForgeHooks.java
+++ ../src-work/minecraft/net/minecraftforge/common/ForgeHooks.java
2017-07-04 06:29:35 +00:00
@@ -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;
2015-03-25 05:24:42 +00:00
+// Cauldron start
+import net.minecraftforge.common.util.FakePlayer;
2017-07-04 06:29:35 +00:00
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.*;
2015-03-22 17:38:04 +00:00
public class ForgeHooks
{
2017-07-04 06:29:35 +00:00
@@ -379,10 +386,12 @@
2015-06-27 20:29:04 +00:00
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;
}
2017-07-04 06:29:35 +00:00
@@ -439,6 +448,8 @@
2015-03-22 17:38:04 +00:00
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))
2017-07-04 06:29:35 +00:00
@@ -449,9 +460,9 @@
2015-03-22 17:38:04 +00:00
{
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;
2017-07-04 06:29:35 +00:00
@@ -463,11 +474,11 @@
2015-03-22 17:38:04 +00:00
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));
2017-07-04 06:29:35 +00:00
@@ -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);
2015-03-25 05:24:42 +00:00
+ // Cauldron start
2017-07-04 06:29:35 +00:00
+ 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);
2015-03-25 05:24:42 +00:00
+ }
+ }
+ // Cauldron end
}
2017-07-04 06:29:35 +00:00
- 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
2015-03-25 05:24:42 +00:00
- if (flag)
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- // save new item data
- int newMeta = itemstack.getItemDamage();
- int newSize = itemstack.stackSize;
- NBTTagCompound newNBT = null;
- if (itemstack.getTagCompound() != null)
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- newNBT = (NBTTagCompound)itemstack.getTagCompound().copy();
2017-07-04 06:29:35 +00:00
- }
2015-03-25 05:24:42 +00:00
- 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();
2017-07-04 06:29:35 +00:00
+ if(tCapture!=null) tCapture.disableCapture();
+ if(tTreeGenCapture!=null) tTreeGenCapture.disableCapture();
2015-03-25 05:24:42 +00:00
- // make sure to set pre-placement item data for event
- itemstack.setItemDamage(meta);
- itemstack.stackSize = size;
- if (nbt != null)
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- itemstack.setTagCompound(nbt);
2017-07-04 06:29:35 +00:00
+ // Cauldron start
+ if(flag){
+ if(tTreeGenCapture!=null&&tTreeGenCapture.mCapturedBlocks.size()>0){
+ tTreeGenCapture.endCapture();
+ }else if(tCapture!=null){
+ tCapture.endCapture();
2015-03-25 05:24:42 +00:00
}
- 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));
- }
2017-07-04 06:29:35 +00:00
-
2015-03-25 05:24:42 +00:00
- if (placeEvent != null && (placeEvent.isCanceled()))
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- flag = false; // cancel placement
- // revert back all captured blocks
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- world.restoringBlockSnapshots = true;
- blocksnapshot.restore(true, false);
- world.restoringBlockSnapshots = false;
2017-07-04 06:29:35 +00:00
- }
- }
2015-03-25 05:24:42 +00:00
- else
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- // Change the stack to its new content
- itemstack.setItemDamage(newMeta);
- itemstack.stackSize = newSize;
2017-07-04 06:29:35 +00:00
- if (nbt != null)
- {
2015-03-25 05:24:42 +00:00
- itemstack.setTagCompound(newNBT);
2017-07-04 06:29:35 +00:00
- }
-
2015-03-25 05:24:42 +00:00
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
2017-07-04 06:29:35 +00:00
- {
2015-03-25 05:24:42 +00:00
- 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
2017-07-04 06:29:35 +00:00
- {
- newBlock.onBlockAdded(world, blockX, blockY, blockZ);
2017-07-04 06:29:35 +00:00
- }
-
2015-03-25 05:24:42 +00:00
- world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag);
2017-07-04 06:29:35 +00:00
- }
2015-03-25 05:24:42 +00:00
- player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);
2017-07-04 06:29:35 +00:00
- }
2015-03-25 05:24:42 +00:00
}
2017-07-04 06:29:35 +00:00
- world.capturedBlockSnapshots.clear();
2015-03-25 05:24:42 +00:00
2017-07-04 06:29:35 +00:00
+ if(tCapture!=null) tCapture.markHandled();
+ if(tTreeGenCapture!=null) tTreeGenCapture.markHandled();
+
2015-03-25 05:24:42 +00:00
return flag;
2017-07-04 06:29:35 +00:00
}