Allow placing of skulls (#480)

* Allow placing of skulls

* Fix incorrect position when checking wither spawn

* Fix rotation, and format with idea's default formatter.
This commit is contained in:
Modmuss50
2016-10-17 17:52:00 +01:00
committed by Raoul
parent 074c11d78d
commit 5293cc45fd
2 changed files with 34 additions and 5 deletions

View File

@@ -3,10 +3,8 @@ package refinedstorage.container.slot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBlockSpecial;
import net.minecraft.item.ItemStack;
import net.minecraft.init.Blocks;
import net.minecraft.item.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.IPlantable;
@@ -38,7 +36,7 @@ public class SlotSpecimen extends SlotItemHandler {
@Override
public boolean isItemValid(ItemStack stack) {
return super.isItemValid(stack) && (isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable) : true);
return super.isItemValid(stack) && (isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable || stack.getItem() instanceof ItemSkull) : true);
}
@Override
@@ -74,6 +72,8 @@ public class SlotSpecimen extends SlotItemHandler {
return (((ItemBlock) item).getBlock()).getDefaultState();
} else if (item instanceof IPlantable) {
return ((IPlantable) item).getPlant(world, pos);
} else if (item instanceof ItemSkull) {
return Blocks.SKULL.getDefaultState();
}
}

View File

@@ -1,7 +1,9 @@
package refinedstorage.tile;
import com.mojang.authlib.GameProfile;
import mcmultipart.microblock.IMicroblock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSkull;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
@@ -9,7 +11,10 @@ import net.minecraft.dispenser.PositionImpl;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
@@ -148,6 +153,30 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
// From ItemBlock#onItemUse
SoundType blockSound = block.getBlock().getSoundType(state, worldObj, pos, null);
worldObj.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F);
if (block.getBlock() == Blocks.SKULL) {
worldObj.setBlockState(front, worldObj.getBlockState(front).withProperty(BlockSkull.FACING, getDirection()));
TileEntity tile = worldObj.getTileEntity(front);
if (tile instanceof TileEntitySkull) {
TileEntitySkull skullTile = (TileEntitySkull) tile;
if (item.getItemDamage() == 3) {
GameProfile playerInfo = null;
if (item.hasTagCompound()) {
NBTTagCompound tagCompound = item.getTagCompound();
if (tagCompound.hasKey("SkullOwner", 10)) {
playerInfo = NBTUtil.readGameProfileFromNBT(tagCompound.getCompoundTag("SkullOwner"));
} else if (tagCompound.hasKey("SkullOwner", 8) && !tagCompound.getString("SkullOwner").isEmpty()) {
playerInfo = new GameProfile(null, tagCompound.getString("SkullOwner"));
}
}
skullTile.setPlayerProfile(playerInfo);
} else {
skullTile.setType(item.getMetadata());
}
Blocks.SKULL.checkWitherSpawn(worldObj, front, skullTile);
}
}
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0);