Revert block snapshots in reverse order. Fixes #3608.
This commit is contained in:
parent
be2d814155
commit
f7f46be8ff
2 changed files with 33 additions and 6 deletions
|
@ -30,6 +30,7 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -811,7 +812,7 @@ public class ForgeHooks
|
|||
NBTTagCompound nbt = null;
|
||||
if (itemstack.getTagCompound() != null)
|
||||
{
|
||||
nbt = (NBTTagCompound)itemstack.getTagCompound().copy();
|
||||
nbt = itemstack.getTagCompound().copy();
|
||||
}
|
||||
|
||||
if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket
|
||||
|
@ -830,11 +831,11 @@ public class ForgeHooks
|
|||
NBTTagCompound newNBT = null;
|
||||
if (itemstack.getTagCompound() != null)
|
||||
{
|
||||
newNBT = (NBTTagCompound)itemstack.getTagCompound().copy();
|
||||
newNBT = itemstack.getTagCompound().copy();
|
||||
}
|
||||
net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
|
||||
BlockEvent.PlaceEvent placeEvent = null;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<BlockSnapshot>)world.capturedBlockSnapshots.clone();
|
||||
List<BlockSnapshot> blockSnapshots = (List<BlockSnapshot>)world.capturedBlockSnapshots.clone();
|
||||
world.capturedBlockSnapshots.clear();
|
||||
|
||||
// make sure to set pre-placement item data for event
|
||||
|
@ -853,11 +854,11 @@ public class ForgeHooks
|
|||
placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
|
||||
}
|
||||
|
||||
if (placeEvent != null && (placeEvent.isCanceled()))
|
||||
if (placeEvent != null && placeEvent.isCanceled())
|
||||
{
|
||||
ret = EnumActionResult.FAIL; // cancel placement
|
||||
// revert back all captured blocks
|
||||
for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots)
|
||||
for (BlockSnapshot blocksnapshot : Lists.reverse(blockSnapshots))
|
||||
{
|
||||
world.restoringBlockSnapshots = true;
|
||||
blocksnapshot.restore(true, false);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package net.minecraftforge.test;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = BlockPlaceEventTest.MOD_ID, name = "BlockPlaceEvent test mod", version = "1.0")
|
||||
@Mod.EventBusSubscriber
|
||||
public class BlockPlaceEventTest
|
||||
{
|
||||
static final String MOD_ID = "block_place_event_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockPlaced(BlockEvent.PlaceEvent event)
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
|
||||
if (event.getPlacedBlock().getBlock() == Blocks.CHEST
|
||||
&& event.getPlacedAgainst().getBlock() != Blocks.DIAMOND_BLOCK)
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue