3
0
Fork 1

在放置事件取消时,对添加到玩家背包的物品进行还原

kcx-1614
聪聪 2017-06-30 16:37:49 +08:00
parent 1811737e6a
commit 62ebe6c4e9
3 changed files with 45 additions and 14 deletions

View File

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/entity/player/InventoryPlayer.java
+++ ../src-work/minecraft/net/minecraft/entity/player/InventoryPlayer.java
@@ -2,7 +2,9 @@
@@ -2,10 +2,13 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -10,21 +10,28 @@
import net.minecraft.block.Block;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
@@ -13,7 +15,13 @@
+import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
@@ -13,7 +16,16 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ReportedException;
+import net.minecraftforge.common.util.EntitySnapshot;
+// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+
public class InventoryPlayer implements IInventory
{
public ItemStack[] mainInventory = new ItemStack[36];
@@ -25,7 +33,46 @@
@@ -25,7 +37,46 @@
private ItemStack itemStack;
public boolean inventoryChanged;
private static final String __OBFID = "CL_00001709";
@ -71,7 +78,7 @@
public InventoryPlayer(EntityPlayer p_i1750_1_)
{
this.player = p_i1750_1_;
@@ -81,6 +128,34 @@
@@ -81,6 +132,34 @@
return -1;
}
@ -106,7 +113,18 @@
public int getFirstEmptyStack()
{
for (int i = 0; i < this.mainInventory.length; ++i)
@@ -430,25 +505,24 @@
@@ -350,6 +429,10 @@
{
if (p_70441_1_ != null && p_70441_1_.stackSize != 0 && p_70441_1_.getItem() != null)
{
+ if(player.worldObj.captureBlockSnapshots){
+ player.worldObj.capturedItems.add(ItemStack.copyItemStack(p_70441_1_));
+ return true;
+ }
try
{
int i;
@@ -430,25 +513,24 @@
if (aitemstack[p_70298_1_] != null)
{
@ -140,7 +158,7 @@
}
else
{
@@ -658,7 +732,7 @@
@@ -658,7 +740,7 @@
if (this.mainInventory[i] != null)
{
this.player.func_146097_a(this.mainInventory[i], true, false);
@ -149,7 +167,7 @@
}
}
@@ -667,7 +741,7 @@
@@ -667,7 +749,7 @@
if (this.armorInventory[i] != null)
{
this.player.func_146097_a(this.armorInventory[i], true, false);

View File

@ -152,7 +152,6 @@
int[] lightUpdateBlockList;
+ // Cauldron start
+ public boolean captureTreeGeneration = false;
+ public ArrayList<EntityItem> capturedItems = new ArrayList<EntityItem>();
+ public int entitiesTicked;
+ public int tilesTicked;
+ public CauldronWorldConfig cauldronConfig;
@ -209,7 +208,8 @@
public boolean restoringBlockSnapshots = false;
public boolean captureBlockSnapshots = false;
public ArrayList<net.minecraftforge.common.util.BlockSnapshot> capturedBlockSnapshots = new ArrayList<net.minecraftforge.common.util.BlockSnapshot>();
+ public ArrayList<net.minecraftforge.common.util.EntitySnapshot> capturedEntityItemSnapshots=new ArrayList<net.minecraftforge.common.util.EntitySnapshot>();
+ public ArrayList<net.minecraftforge.common.util.EntitySnapshot> capturedEntitySnapshots=new ArrayList<net.minecraftforge.common.util.EntitySnapshot>();
+ public ArrayList<ItemStack> capturedItems=new ArrayList<ItemStack>();
public BiomeGenBase getBiomeGenForCoords(final int p_72807_1_, final int p_72807_2_)
{
@ -631,7 +631,7 @@
+ if(p_72838_1_ instanceof net.minecraft.entity.item.EntityItem&&this.restoringBlockSnapshots)
+ return false;
+ if(this.captureBlockSnapshots&&!(p_72838_1_ instanceof EntityPlayerMP)){
+ this.capturedEntityItemSnapshots.add(new net.minecraftforge.common.util.EntitySnapshot(this,p_72838_1_,spawnReason));
+ this.capturedEntitySnapshots.add(new net.minecraftforge.common.util.EntitySnapshot(this,p_72838_1_,spawnReason));
+ return true;
+ }
+ }

View File

@ -65,7 +65,7 @@
{
// Let the client know the block still exists
entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
@@ -500,81 +514,144 @@
@@ -500,81 +514,157 @@
if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket
{
world.captureBlockSnapshots = true;
@ -169,8 +169,10 @@
+ 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.capturedEntityItemSnapshots.clone();
+ world.capturedEntityItemSnapshots.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);
@ -247,6 +249,17 @@
+ 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);