parent
5802a3b0b6
commit
9a9c02fa25
4 changed files with 46 additions and 8 deletions
|
@ -7,7 +7,7 @@
|
|||
+ // special case for handling block placement with water lilies
|
||||
+ net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(p_77659_2_, blockpos1);
|
||||
+ p_77659_2_.func_175656_a(blockpos1, Blocks.field_150392_bi.func_176223_P());
|
||||
+ if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(p_77659_3_, blocksnapshot, net.minecraft.util.EnumFacing.UP).isCanceled())
|
||||
+ if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(p_77659_3_, blocksnapshot, net.minecraft.util.EnumFacing.UP, p_77659_4_).isCanceled())
|
||||
+ {
|
||||
+ blocksnapshot.restore(true, false);
|
||||
+ return new ActionResult<ItemStack>(EnumActionResult.FAIL, p_77659_1_);
|
||||
|
|
|
@ -795,11 +795,11 @@ public class ForgeHooks
|
|||
}
|
||||
if (blockSnapshots.size() > 1)
|
||||
{
|
||||
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side);
|
||||
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand);
|
||||
}
|
||||
else if (blockSnapshots.size() == 1)
|
||||
{
|
||||
placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side);
|
||||
placeEvent = ForgeEventFactory.onPlayerBlockPlace(player, blockSnapshots.get(0), side, hand);
|
||||
}
|
||||
|
||||
if (placeEvent != null && (placeEvent.isCanceled()))
|
||||
|
|
|
@ -109,22 +109,42 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
|||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ForgeEventFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onPlayerMultiBlockPlace(EntityPlayer, List, EnumFacing, EnumHand)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static MultiPlaceEvent onPlayerMultiBlockPlace(EntityPlayer player, List<BlockSnapshot> blockSnapshots, EnumFacing direction)
|
||||
{
|
||||
return onPlayerMultiBlockPlace(player, blockSnapshots, direction, null);
|
||||
}
|
||||
|
||||
public static MultiPlaceEvent onPlayerMultiBlockPlace(EntityPlayer player, List<BlockSnapshot> blockSnapshots, EnumFacing direction, @Nullable EnumHand hand)
|
||||
{
|
||||
BlockSnapshot snap = blockSnapshots.get(0);
|
||||
IBlockState placedAgainst = snap.getWorld().getBlockState(snap.getPos().offset(direction.getOpposite()));
|
||||
MultiPlaceEvent event = new MultiPlaceEvent(blockSnapshots, placedAgainst, player);
|
||||
MultiPlaceEvent event = new MultiPlaceEvent(blockSnapshots, placedAgainst, player, hand);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onPlayerBlockPlace(EntityPlayer, BlockSnapshot, EnumFacing, EnumHand)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static PlaceEvent onPlayerBlockPlace(EntityPlayer player, BlockSnapshot blockSnapshot, EnumFacing direction)
|
||||
{
|
||||
return onPlayerBlockPlace(player, blockSnapshot, direction, null);
|
||||
}
|
||||
|
||||
public static PlaceEvent onPlayerBlockPlace(EntityPlayer player, BlockSnapshot blockSnapshot, EnumFacing direction, @Nullable EnumHand hand)
|
||||
{
|
||||
IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(direction.getOpposite()));
|
||||
PlaceEvent event = new PlaceEvent(blockSnapshot, placedAgainst, player);
|
||||
PlaceEvent event = new PlaceEvent(blockSnapshot, placedAgainst, player, hand);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -37,6 +38,8 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BlockEvent extends Event
|
||||
{
|
||||
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
|
||||
|
@ -170,26 +173,36 @@ public class BlockEvent extends Event
|
|||
private final BlockSnapshot blockSnapshot;
|
||||
private final IBlockState placedBlock;
|
||||
private final IBlockState placedAgainst;
|
||||
private final EnumHand hand;
|
||||
|
||||
@Deprecated
|
||||
public PlaceEvent(BlockSnapshot blockSnapshot, IBlockState placedAgainst, EntityPlayer player)
|
||||
{
|
||||
this(blockSnapshot, placedAgainst, player, null);
|
||||
}
|
||||
|
||||
public PlaceEvent(BlockSnapshot blockSnapshot, IBlockState placedAgainst, EntityPlayer player, @Nullable EnumHand hand) {
|
||||
super(blockSnapshot.getWorld(), blockSnapshot.getPos(), blockSnapshot.getCurrentBlock());
|
||||
this.player = player;
|
||||
this.itemInHand = player.getHeldItemMainhand();
|
||||
this.itemInHand = player.getHeldItem(hand != null ? hand : EnumHand.MAIN_HAND);
|
||||
this.blockSnapshot = blockSnapshot;
|
||||
this.placedBlock = blockSnapshot.getCurrentBlock();
|
||||
this.placedAgainst = placedAgainst;
|
||||
this.hand = hand;
|
||||
if (DEBUG)
|
||||
{
|
||||
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ]\n", getPlacedBlock(), placedAgainst, getItemInHand(), player);
|
||||
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, getItemInHand(), player, hand);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer() { return player; }
|
||||
@Nullable
|
||||
public ItemStack getItemInHand() { return itemInHand; }
|
||||
public BlockSnapshot getBlockSnapshot() { return blockSnapshot; }
|
||||
public IBlockState getPlacedBlock() { return placedBlock; }
|
||||
public IBlockState getPlacedAgainst() { return placedAgainst; }
|
||||
@Nullable
|
||||
public EnumHand getHand() { return hand; }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,9 +217,14 @@ public class BlockEvent extends Event
|
|||
{
|
||||
private final List<BlockSnapshot> blockSnapshots;
|
||||
|
||||
@Deprecated
|
||||
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, IBlockState placedAgainst, EntityPlayer player)
|
||||
{
|
||||
super(blockSnapshots.get(0), placedAgainst, player);
|
||||
this(blockSnapshots, placedAgainst, player, null);
|
||||
}
|
||||
|
||||
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, IBlockState placedAgainst, EntityPlayer player, @Nullable EnumHand hand) {
|
||||
super(blockSnapshots.get(0), placedAgainst, player, hand);
|
||||
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
|
||||
if (DEBUG)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue