3
0

模块化方块捕获还原动作

This commit is contained in:
2017-07-04 14:29:35 +08:00
parent 559b9ad248
commit bfe43ae465
12 changed files with 992 additions and 402 deletions

View File

@ -1,23 +1,74 @@
--- ../src-base/minecraft/net/minecraftforge/common/ForgeHooks.java
+++ ../src-work/minecraft/net/minecraftforge/common/ForgeHooks.java
@@ -63,6 +63,16 @@
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import static net.minecraft.init.Blocks.*;
@@ -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 org.bukkit.Bukkit;
+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;
+//Cauldron end
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 +389,12 @@
@@ -379,10 +386,12 @@
public static ChatComponentTranslation onServerChatEvent(NetHandlerPlayServer net, String raw, ChatComponentTranslation comp)
{
ServerChatEvent event = new ServerChatEvent(net.playerEntity, raw, comp);
@ -30,7 +81,7 @@
return event.component;
}
@@ -439,6 +451,8 @@
@@ -439,6 +448,8 @@
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z)
{
@ -39,7 +90,7 @@
// Logic from tryHarvestBlock for pre-canceling the event
boolean preCancelEvent = false;
if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z))
@@ -449,9 +463,9 @@
@@ -449,9 +460,9 @@
{
preCancelEvent = true;
}
@ -51,7 +102,7 @@
{
S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world);
packet.field_148883_d = Blocks.air;
@@ -463,11 +477,11 @@
@@ -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);
@ -65,62 +116,73 @@
{
// Let the client know the block still exists
entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
@@ -500,81 +514,157 @@
if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket
{
world.captureBlockSnapshots = true;
@@ -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))
+ {
+ world.captureTreeGeneration = true;
+ 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
}
+ ItemStack.currentPlayer = player; // Cauldron
boolean flag = itemstack.getItem().onItemUse(itemstack, player, world, x, y, z, side, hitX, hitY, hitZ);
+ ItemStack.currentPlayer = null; // Cauldron
world.captureBlockSnapshots = false;
- 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)
+ // Cauldron start
+ if (flag && world.captureTreeGeneration && world.capturedBlockSnapshots.size() > 0)
{
- {
- // save new item data
- int newMeta = itemstack.getItemDamage();
- int newSize = itemstack.stackSize;
- NBTTagCompound newNBT = null;
- if (itemstack.getTagCompound() != null)
+ world.captureTreeGeneration = false;
+ Location loc = new Location(world.getWorld(), (double) x, (double) y, (double) z);
+ TreeType type = net.minecraft.block.BlockSapling.treeType;
+ net.minecraft.block.BlockSapling.treeType = null;
+ List<BlockState> states = new ArrayList();
+
+ for (net.minecraftforge.common.util.BlockSnapshot snapshot : (List<net.minecraftforge.common.util.BlockSnapshot>) world.capturedBlockSnapshots.clone())
{
- {
- newNBT = (NBTTagCompound)itemstack.getTagCompound().copy();
+ states.add(new CraftBlockState(snapshot));
}
- }
- 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)
+ world.capturedBlockSnapshots.clear();
+ StructureGrowEvent event = null;
+ if (type != null)
{
- {
- itemstack.setTagCompound(nbt);
+ event = new StructureGrowEvent(loc, type, false, (Player) player.getBukkitEntity(), states);
+ Bukkit.getPluginManager().callEvent(event);
+ // Cauldron start
+ if(flag){
+ if(tTreeGenCapture!=null&&tTreeGenCapture.mCapturedBlocks.size()>0){
+ tTreeGenCapture.endCapture();
+ }else if(tCapture!=null){
+ tCapture.endCapture();
}
- if (blockSnapshots.size() > 1)
- {
@ -130,72 +192,30 @@
- {
- placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), net.minecraftforge.common.util.ForgeDirection.getOrientation(side));
- }
-
- if (placeEvent != null && (placeEvent.isCanceled()))
+ if (event == null || !event.isCancelled())
{
- {
- flag = false; // cancel placement
- // revert back all captured blocks
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
+ for (BlockState state : states)
{
- {
- world.restoringBlockSnapshots = true;
- blocksnapshot.restore(true, false);
- world.restoringBlockSnapshots = false;
+ state.update(true);
}
}
- }
- }
- else
+
+ return flag;
+ }
+ else
+ {
+ world.captureTreeGeneration = false; // Cauldron end
+ if (flag)
{
- {
- // Change the stack to its new content
- itemstack.setItemDamage(newMeta);
- itemstack.stackSize = newSize;
+ // 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();
+ List<net.minecraftforge.common.util.EntitySnapshot> tDropItemSnapshots=(List<net.minecraftforge.common.util.EntitySnapshot>)world.capturedEntitySnapshots.clone();
+ world.capturedEntitySnapshots.clear();
+ List<ItemStack> tCaptureItems=(List<ItemStack>)world.capturedItems.clone();
+ world.capturedItems.clear();
+
+ // make sure to set pre-placement item data for event
+ itemstack.setItemDamage(meta);
+ itemstack.stackSize = size;
if (nbt != null)
{
- if (nbt != null)
- {
- itemstack.setTagCompound(newNBT);
+ itemstack.setTagCompound(nbt);
}
+ 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));
+ }
- }
-
- for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
+ if (placeEvent != null && (placeEvent.isCanceled()))
{
- {
- int blockX = blocksnapshot.x;
- int blockY = blocksnapshot.y;
- int blockZ = blocksnapshot.z;
@ -204,69 +224,20 @@
- Block oldBlock = blocksnapshot.replacedBlock;
- Block newBlock = world.getBlock(blockX, blockY, blockZ);
- if (newBlock != null && !(newBlock.hasTileEntity(metadata))) // Containers get placed automatically
+ flag = false; // cancel placement
+ // revert back all captured blocks
+ for(int i=blockSnapshots.size();i>0;){
+ world.restoringBlockSnapshots=true;
+ blockSnapshots.get(--i).restore(true,false);
+ world.restoringBlockSnapshots=false;
+ }
+ for(net.minecraftforge.common.util.EntitySnapshot sEntityItem : tDropItemSnapshots){
+ sEntityItem.cancel();
+ }
+ }
+ else
+ {
+ // Change the stack to its new content
+ itemstack.setItemDamage(newMeta);
+ itemstack.stackSize = newSize;
+ if (nbt != null)
{
- {
- newBlock.onBlockAdded(world, blockX, blockY, blockZ);
+ itemstack.setTagCompound(newNBT);
}
- }
-
- world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag);
+ 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);
+ }
+ for(net.minecraftforge.common.util.EntitySnapshot sEntityItem : tDropItemSnapshots){
+ sEntityItem.apply();
+ }
+ if(!tCaptureItems.isEmpty()){
+ boolean tAdded=false;
+ for(ItemStack sItem : tCaptureItems){
+ if(!player.inventory.addItemStackToInventory(sItem)){
+ world.spawnEntityInWorld(new EntityItem(world,player.posX,player.posY,player.posZ,sItem));
+ }else{
+ tAdded=true;
+ }
+ }
+ if(tAdded) player.openContainer.detectAndSendChanges();
+ }
+ player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);
}
- }
- player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);
+
}
- }
}
+
world.capturedBlockSnapshots.clear();
- world.capturedBlockSnapshots.clear();
+ if(tCapture!=null) tCapture.markHandled();
+ if(tTreeGenCapture!=null) tTreeGenCapture.markHandled();
+
return flag;
}

View File

@ -1,23 +1,33 @@
--- ../src-base/minecraft/net/minecraftforge/event/world/BlockEvent.java
+++ ../src-work/minecraft/net/minecraftforge/event/world/BlockEvent.java
@@ -16,6 +16,16 @@
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
@@ -3,17 +3,23 @@
import java.util.ArrayList;
import java.util.List;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+// Cauldron start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockMultiPlaceEvent;
+
import com.google.common.collect.ImmutableList;
+import cc.capture.type.CaptureBlock;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.block.Block;
-import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.init.Blocks;
+import net.minecraft.entity.player.EntityPlayerMP;
+// Cauldron end
+
public class BlockEvent extends Event {
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
-import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
@@ -80,17 +90,18 @@
public class BlockEvent extends Event {
@@ -80,17 +86,18 @@
super(x, y, z, world, block, blockMetadata);
this.player = player;
@ -42,7 +52,7 @@
}
public EntityPlayer getPlayer()
@@ -140,6 +151,16 @@
@@ -140,6 +147,21 @@
this.blockSnapshot = blockSnapshot;
this.placedBlock = blockSnapshot.getCurrentBlock();
this.placedAgainst = placedAgainst;
@ -54,12 +64,17 @@
+ if(bukkitEvent.isCancelled()||!bukkitEvent.canBuild()){
+ this.setCanceled(true);
+ }
+
+ CaptureBlock tCapture=world.mCapture.getLastBlockCapture();
+ if(tCapture!=null&&tCapture.mEnable){
+ tCapture.addCheckedBlock(world,x,y,z);
+ }
+ }
+ // Cauldron end
if (DEBUG)
{
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ]\n", placedBlock, placedAgainst, player.getCurrentEquippedItem(), player);
@@ -160,7 +181,17 @@
@@ -160,7 +182,17 @@
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, Block placedAgainst, EntityPlayer player) {
super(blockSnapshots.get(0), placedAgainst, player);