Reimplement ForgeHooks#onPlaceItemIntoWorld and remove old place events

This commit is contained in:
tterrag committed 2019-04-23 20:42:08 -04:00
1 parent ca973f053f
commit a86317efc8
6 files changed
+21 -117

No files matched your search

@@ -119,12 +119,10 @@ import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.event.terraingen.ChunkGeneratorEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.GetCollisionBoxesEvent;
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
@@ -143,15 +141,6 @@ public class ForgeEventFactory
return MinecraftForge.EVENT_BUS.post(event);
}
public static MultiPlaceEvent onPlayerMultiBlockPlace(EntityPlayer player, List<BlockSnapshot> blockSnapshots, EnumFacing direction, EnumHand hand)
{
BlockSnapshot snap = blockSnapshots.get(0);
IBlockState placedAgainst = snap.getWorld().getBlockState(snap.getPos().offset(direction.getOpposite()));
MultiPlaceEvent event = new MultiPlaceEvent(blockSnapshots, placedAgainst, player, hand);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static boolean onBlockPlace(@Nullable Entity entity, @Nonnull BlockSnapshot blockSnapshot, @Nonnull EnumFacing direction)
{
IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(direction.getOpposite()));
@@ -159,14 +148,6 @@ public class ForgeEventFactory
return MinecraftForge.EVENT_BUS.post(event);
}
public static PlaceEvent onPlayerBlockPlace(@Nonnull EntityPlayer player, @Nonnull BlockSnapshot blockSnapshot, @Nonnull EnumFacing direction, @Nonnull EnumHand hand)
{
IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(direction.getOpposite()));
PlaceEvent event = new PlaceEvent(blockSnapshot, placedAgainst, player, hand);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static NeighborNotifyEvent onNeighborNotify(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides, boolean forceRedstoneUpdate)
{
NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides, forceRedstoneUpdate);
@@ -201,35 +201,6 @@ public class BlockEvent extends Event
public IBlockState getPlacedAgainst() { return placedAgainst; }
}
/**
* Called when a block is placed by a player.
*
* If a Block Place event is cancelled, the block will not be placed.
*/
@Cancelable
@Deprecated // Remove in 1.13
public static class PlaceEvent extends EntityPlaceEvent
{
private final EntityPlayer player;
private final EnumHand hand;
public PlaceEvent(@Nonnull BlockSnapshot blockSnapshot, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshot, placedAgainst, player);
this.player = player;
this.hand = hand;
if (DEBUG)
{
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, player.getHeldItem(hand), player, hand);
}
}
public EntityPlayer getPlayer() { return player; }
@Nonnull
@Deprecated
public ItemStack getItemInHand() { return player.getHeldItem(hand); }
public EnumHand getHand() { return hand; }
}
/**
* Fired when a single block placement triggers the
* creation of multiple blocks(e.g. placing a bed block). The block returned
@@ -263,40 +234,6 @@ public class BlockEvent extends Event
}
}
/**
* Fired when a single block placement action of a player triggers the
* creation of multiple blocks(e.g. placing a bed block). The block returned
* by {@link #state} and its related methods is the block where
* the placed block would exist if the placement only affected a single
* block.
*/
@Cancelable
public static class MultiPlaceEvent extends PlaceEvent
{
private final List<BlockSnapshot> blockSnapshots;
public MultiPlaceEvent(@Nonnull List<BlockSnapshot> blockSnapshots, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshots.get(0), placedAgainst, player, hand);
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
if (DEBUG)
{
System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, player.getHeldItem(hand), player);
}
}
/**
* Gets a list of BlockSnapshots for all blocks which were replaced by the
* placement of the new blocks. Most of these blocks will just be of type AIR.
*
* @return immutable list of replaced BlockSnapshots
*/
public List<BlockSnapshot> getReplacedBlockSnapshots()
{
return blockSnapshots;
}
}
/**
* Fired when a physics update occurs on a block. This event acts as
* a way for mods to detect physics updates, in the same way a BUD switch