Jump to content

[1.10.2] Tile Entity reacting weird


Egietje

Recommended Posts

So, I decided to add a cheeseboard in my mod and it somewhat works but when I right-click it with cheese it adds it and also removes it, does anyone have any idea how this happened? Stuff:

package com.Egietje.degeweldigemod.blocks;

import com.Egietje.degeweldigemod.entities.tileentities.blocks.cheeseboard.TileEntityCheeseBoard;
import com.Egietje.degeweldigemod.init.CheeseItems;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class CheeseBoard extends Block implements ITileEntityProvider {

public CheeseBoard() {
	super(Material.WOOD);
	this.setSoundType(SoundType.WOOD);
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(!worldIn.isRemote) {
		TileEntity tileEntity = worldIn.getTileEntity(pos);
		if(tileEntity instanceof TileEntityCheeseBoard) {
			TileEntityCheeseBoard cheeseBoard = (TileEntityCheeseBoard) tileEntity;
			if(heldItem != null) {
				if(heldItem.getItem() == CheeseItems.CHEESE) {
					if(cheeseBoard.addCheese()) {
						heldItem.stackSize--;
						return true;
					}
				}
			}
			cheeseBoard.removeCheese();
		}
	}
	return false;
}

@Override
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {
	if(!worldIn.isRemote) {
		TileEntity tileEntity = worldIn.getTileEntity(pos);
		if(tileEntity instanceof TileEntityCheeseBoard) {
			TileEntityCheeseBoard cheeseBoard = (TileEntityCheeseBoard) tileEntity;
			worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 1.0, pos.getZ() + 0.5, new ItemStack(CheeseItems.CHEESE, cheeseBoard.CHEESE_COUNT)));
		}
	}
}

public BlockRenderLayer getBlockLayer() {
	return BlockRenderLayer.CUTOUT;
}

public boolean isFullCube(IBlockState state) {
        return false;
    }

public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

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

}

package com.Egietje.degeweldigemod.entities.tileentities.blocks.cheeseboard;

import com.Egietje.degeweldigemod.init.CheeseItems;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityCheeseBoard extends TileEntity {

public int CHEESE_COUNT = 0;

public boolean addCheese() {
	if(this.CHEESE_COUNT <  {
		this.CHEESE_COUNT++;
		return true;
	}
	return false;
}

public void removeCheese() {
	if(this.CHEESE_COUNT > 0) {
		worldObj.spawnEntityInWorld(new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1.0, pos.getZ() + 0.5, new ItemStack(CheeseItems.CHEESE)));
		this.CHEESE_COUNT--;
	}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setInteger("CheeseCount", this.CHEESE_COUNT);
	return compound;
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	this.CHEESE_COUNT = compound.getInteger("CheeseCount");
}

}

Link to comment
Share on other sites

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.