Jump to content

Recommended Posts

Posted

So, I added a block with a tile entity, and it is completely transparent when placed in the world. It renders just fine in the inventory. Here is a screenshot:

mpLwK9l.png

And my code:

Block:

 

public class BlockPopFurnace extends BlockContainer {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

public BlockPopFurnace() {
	super(Material.iron);
	setUnlocalizedName("pop_furnace");
	setCreativeTab(UnLogicII.TabUnLogicII);
	setHardness(5F);
	setResistance(15F);
	this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
@Override
public boolean isOpaqueCube(){
	return true;
}

@Override
public boolean isVisuallyOpaque()
{
	return true;
}

@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer(){
	return EnumWorldBlockLayer.SOLID;
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileEntityPopFurnace();
}

@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state){
	super.onBlockAdded(world, pos, state);
	setDefaultDirection(world, pos, state);
}

private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state){
	if(!worldIn.isRemote){
		Block block = worldIn.getBlockState(pos.north()).getBlock();
		Block block1 = worldIn.getBlockState(pos.south()).getBlock();
		Block block2 = worldIn.getBlockState(pos.west()).getBlock();
		Block block3 = worldIn.getBlockState(pos.east()).getBlock();
		EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

		if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())
		{
			enumfacing = EnumFacing.SOUTH;
		}
		else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
		{
			enumfacing = EnumFacing.NORTH;
		}
		else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())
		{
			enumfacing = EnumFacing.EAST;
		}
		else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())
		{
			enumfacing = EnumFacing.WEST;
		}

		worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
	}
}

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
	return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if (!worldIn.isRemote)
	{
		TileEntity tileentity = worldIn.getTileEntity(pos);

		if (tileentity instanceof TileEntityPopFurnace)
		{
			FMLNetworkHandler.openGui(playerIn, UnLogicII.MODID, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
	}
	return true;
}

@Override
protected BlockState createBlockState(){ 
	return new BlockState(this, new IProperty[] {FACING});
}

@Override
public IBlockState getStateFromMeta(int meta)
{
	EnumFacing enumfacing = EnumFacing.getFront(meta);

	if (enumfacing.getAxis() == EnumFacing.Axis.Y)
	{
		enumfacing = EnumFacing.NORTH;
	}

	return this.getDefaultState().withProperty(FACING, enumfacing);
}
@Override
public int getMetaFromState(IBlockState state)
{
	return ((EnumFacing)state.getValue(FACING)).getIndex();
}
}

 

And the tile entity:

 

/**
* 
* @author The_Fireplace
*
*/
public class TileEntityPopFurnace extends TileEntity implements IInventory {
private ItemStack[] inventory;
short storedGunpowder = -32768;
public static final short storedGunpowderMin = -32768;
int storedFirestarter;
public static final byte storedFirestarterMin = 0;

public TileEntityPopFurnace(){
	inventory = new ItemStack[12];
}

@Override
public String getName() {
	return StatCollector.translateToLocal("tile.pop_furnace.name");
}

@Override
public boolean hasCustomName() {
	return false;
}

@Override
public IChatComponent getDisplayName() {
	return null;
}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int index) {
	return inventory[index];
}

@Override
public ItemStack decrStackSize(int index, int count) {
	ItemStack is = getStackInSlot(index);
	if(is != null){
		if(is.stackSize <= count){
			setInventorySlotContents(index, null);
		}else{
			is = is.splitStack(count);
			markDirty();
		}
	}
	return is;
}

@Override
public ItemStack getStackInSlotOnClosing(int index) {
	ItemStack is = getStackInSlot(index);
	setInventorySlotContents(index, null);
	return is;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	inventory[index] = stack;

	if(stack != null && stack.stackSize > getInventoryStackLimit()){
		stack.stackSize = getInventoryStackLimit();
	}
	markDirty();
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64;
}

@Override
public void openInventory(EntityPlayer player) {
}

@Override
public void closeInventory(EntityPlayer player) {
}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	return true;
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {
}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {
	for(int i = 0; i < inventory.length; ++i){
		inventory[i]=null;
	}
}

@Override
public void writeToNBT(NBTTagCompound compound){
	super.writeToNBT(compound);

	NBTTagList list = new NBTTagList();
	for(int i = 0; i<getSizeInventory();i++){
		ItemStack is = getStackInSlot(i);
		if(is != null){
			NBTTagCompound item = new NBTTagCompound();

			item.setByte("SlotPopFurnace", (byte)i);
			is.writeToNBT(item);

			list.appendTag(item);
		}
	}
	compound.setTag("ItemsPopFurnace", list);
}

@Override
public void readFromNBT(NBTTagCompound compound){
	super.readFromNBT(compound);
	NBTTagList list = (NBTTagList) compound.getTag("ItemsPopFurnace");
	if(list != null){
		for(int i = 0; i<list.tagCount();i++){
			NBTTagCompound item = (NBTTagCompound) list.get(i);
			int slot = item.getByte("SlotPopFurnace");
			if(slot >= 0 && slot < getSizeInventory()){
				setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
			}
		}
	}else{
		System.out.println("List was null when reading TileEntityPopFurnace NBTTagCompound");
	}
}

public void addToGunpowder(int amount){
	if(storedGunpowder+amount <= 32767){
		storedGunpowder += amount;
	}else{
		storedGunpowder = 32767;
		System.out.println("Someone actually managed to cram 1024 stacks of gunpowder in to a Pop Furnace. Congratulations to them for hitting the limit.");
		System.out.println("I recommend turning down the number of items popped per gunpowder in the UnLogic II config, to help use some of that up.");
	}
}

public void removeFromGunpowder(int amount){
	if(storedGunpowder-amount < storedGunpowderMin){
		storedGunpowder=storedGunpowderMin;
		System.out.println("Error: something tried subtracting more gunpowder than was stored in a Pop Furnace. This is not a good sign.");
	}else{
		storedGunpowder -= amount;
	}
}

public void addToFireStarter(int amount){
	storedFirestarter += amount;
	System.out.println(storedFirestarter);
}

public void removeFromFirestarter(int amount){
	storedFirestarter -= amount;
	if(storedFirestarter < storedFirestarterMin){
		storedFirestarter = storedFirestarterMin;
	}
}
}

 

And the related json files

 

{
    "variants": {
        "facing=north": { "model": "unlogicii:pop_furnace" },
        "facing=south": { "model": "unlogicii:pop_furnace", "y": 180 },
        "facing=west":  { "model": "unlogicii:pop_furnace", "y": 270 },
        "facing=east":  { "model": "unlogicii:pop_furnace", "y": 90 }
    }
}

{
    "parent": "block/orientable",
    "textures": {
        "top": "blocks/iron_block",
        "front": "unlogicii:blocks/pop_furnace_front",
        "side": "blocks/iron_block"
    }
}

 

Any help would be appreciated.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.