Fixes #665 - "Block place / drop event should be called by the constructor"
This commit is contained in:
@@ -33,7 +33,12 @@ import net.minecraft.tileentity.TileEntitySkull;
|
|||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.util.BlockSnapshot;
|
||||||
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||||
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
@@ -152,12 +157,20 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
BlockPos front = pos.offset(getDirection());
|
BlockPos front = pos.offset(getDirection());
|
||||||
|
|
||||||
if (worldObj.isAirBlock(front) && block.getBlock().canPlaceBlockAt(worldObj, front)) {
|
if (worldObj.isAirBlock(front) && block.getBlock().canPlaceBlockAt(worldObj, front)) {
|
||||||
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare, false);
|
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare, true);
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null) {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
IBlockState state = block.getBlock().getStateFromMeta(took.getMetadata());
|
IBlockState state = block.getBlock().getStateFromMeta(took.getMetadata());
|
||||||
|
|
||||||
|
BlockEvent.PlaceEvent e = new BlockEvent.PlaceEvent(new BlockSnapshot(worldObj, front, state), worldObj.getBlockState(pos), FakePlayerFactory.getMinecraft((WorldServer) worldObj), null);
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(e)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
network.extractItem(itemFilters.getStackInSlot(0), 1, compare, false);
|
||||||
|
|
||||||
worldObj.setBlockState(front, state, 1 | 2);
|
worldObj.setBlockState(front, state, 1 | 2);
|
||||||
|
|
||||||
// From ItemBlock#onItemUse
|
// From ItemBlock#onItemUse
|
||||||
@@ -166,23 +179,30 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
|
|
||||||
if (block.getBlock() == Blocks.SKULL) {
|
if (block.getBlock() == Blocks.SKULL) {
|
||||||
worldObj.setBlockState(front, worldObj.getBlockState(front).withProperty(BlockSkull.FACING, getDirection()));
|
worldObj.setBlockState(front, worldObj.getBlockState(front).withProperty(BlockSkull.FACING, getDirection()));
|
||||||
|
|
||||||
TileEntity tile = worldObj.getTileEntity(front);
|
TileEntity tile = worldObj.getTileEntity(front);
|
||||||
|
|
||||||
if (tile instanceof TileEntitySkull) {
|
if (tile instanceof TileEntitySkull) {
|
||||||
TileEntitySkull skullTile = (TileEntitySkull) tile;
|
TileEntitySkull skullTile = (TileEntitySkull) tile;
|
||||||
|
|
||||||
if (item.getItemDamage() == 3) {
|
if (item.getItemDamage() == 3) {
|
||||||
GameProfile playerInfo = null;
|
GameProfile playerInfo = null;
|
||||||
|
|
||||||
if (item.hasTagCompound()) {
|
if (item.hasTagCompound()) {
|
||||||
NBTTagCompound tagCompound = item.getTagCompound();
|
NBTTagCompound tag = item.getTagCompound();
|
||||||
if (tagCompound.hasKey("SkullOwner", 10)) {
|
|
||||||
playerInfo = NBTUtil.readGameProfileFromNBT(tagCompound.getCompoundTag("SkullOwner"));
|
if (tag.hasKey("SkullOwner", 10)) {
|
||||||
} else if (tagCompound.hasKey("SkullOwner", 8) && !tagCompound.getString("SkullOwner").isEmpty()) {
|
playerInfo = NBTUtil.readGameProfileFromNBT(tag.getCompoundTag("SkullOwner"));
|
||||||
playerInfo = new GameProfile(null, tagCompound.getString("SkullOwner"));
|
} else if (tag.hasKey("SkullOwner", 8) && !tag.getString("SkullOwner").isEmpty()) {
|
||||||
|
playerInfo = new GameProfile(null, tag.getString("SkullOwner"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skullTile.setPlayerProfile(playerInfo);
|
skullTile.setPlayerProfile(playerInfo);
|
||||||
} else {
|
} else {
|
||||||
skullTile.setType(item.getMetadata());
|
skullTile.setType(item.getMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
Blocks.SKULL.checkWitherSpawn(worldObj, front, skullTile);
|
Blocks.SKULL.checkWitherSpawn(worldObj, front, skullTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ public class TileSolderer extends TileNode {
|
|||||||
private ItemHandlerBasic items = new ItemHandlerBasic(3, this) {
|
private ItemHandlerBasic items = new ItemHandlerBasic(3, this) {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||||
|
|
||||||
for (ISoldererRecipe recipe : API.instance().getSoldererRegistry().getRecipes()) {
|
for (ISoldererRecipe recipe : API.instance().getSoldererRegistry().getRecipes()) {
|
||||||
if (API.instance().getComparer().isEqualNoQuantity(recipe.getRow(slot), stack) || API.instance().getComparer().isEqualOredict(recipe.getRow(slot), stack)) {
|
if (API.instance().getComparer().isEqualNoQuantity(recipe.getRow(slot), stack) || API.instance().getComparer().isEqualOredict(recipe.getRow(slot), stack)) {
|
||||||
return super.insertItem(slot, stack, simulate);
|
return super.insertItem(slot, stack, simulate);
|
||||||
|
|||||||
Reference in New Issue
Block a user