Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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");
}

}

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.