-
Posts
796 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Kokkie
-
I checked if the tile entity at the pos of the block was an instanceof TileEntityAutoMiner and it return false...
-
So now I've got this. package com.Egietje.AutoMiner.blocks; import java.util.Random; import com.Egietje.AutoMiner.entities.tileentities.TileEntityAutoMiner; import com.Egietje.AutoMiner.init.AMBlocks; import com.Egietje.AutoMiner.init.AMItems; import net.minecraft.block.Block; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemBoat; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockAutoMiner extends Block { public static final PropertyDirection FACING = BlockHorizontal.FACING; public static IProperty ACTIVATED = PropertyBool.create("activated"); public BlockAutoMiner() { super(Material.PISTON); this.setDefaultState( this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVATED, false)); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(AMBlocks.AUTO_MINER); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(AMBlocks.AUTO_MINER); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2); } 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 IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); return state.withProperty(ACTIVATED, te.ACTIVATED); } public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING, ACTIVATED }); } @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) { if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); if (te.ACTIVATED) { EnumFacing enumfacing = (EnumFacing) stateIn.getValue(FACING); double d0 = (double) pos.getX() + 0.5D; double d1 = (double) pos.getY() + 0.5D; double d2 = (double) pos.getZ() + 0.5D; double d3 = 0.52D; double d4 = rand.nextDouble() * 0.6D - 0.3D; switch (enumfacing) { case WEST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case EAST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case NORTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]); break; case SOUTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]); default: break; } } } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) { if (TileEntityFurnace.isItemFuel(playerIn.getHeldItem(hand))) { if (!playerIn.isCreative()) { playerIn.getHeldItem(hand).shrink(1); } if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); te.addFuel(TileEntityFurnace.getItemBurnTime(playerIn.getHeldItem(hand))); } } else if (playerIn.getHeldItem(hand).getItem() == AMItems.WRENCH) { if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); if (te.ACTIVATED) { te.setActivated(false); } else { te.setActivated(true); } } } return true; } return false; } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityAutoMiner(); } } package com.Egietje.AutoMiner.entities.tileentities; import com.Egietje.AutoMiner.blocks.BlockAutoMiner; import com.Egietje.AutoMiner.init.AMBlocks; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class TileEntityAutoMiner extends TileEntity implements ITickable { public int FUEL_AMOUNT = 0; public boolean ACTIVATED = false; public void addFuel(int amount) { System.out.println("Before: " + FUEL_AMOUNT); System.out.println("Added: " + amount); this.FUEL_AMOUNT += amount; System.out.println("After: " + FUEL_AMOUNT); markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } public void removeFuel() { if (this.FUEL_AMOUNT > 0) { this.FUEL_AMOUNT--; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } public boolean isActivated() { return ACTIVATED; } public void setActivated(boolean active) { ACTIVATED = active; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("FuelAmount", this.FUEL_AMOUNT); compound.setBoolean("Activated", this.ACTIVATED); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.FUEL_AMOUNT = compound.getInteger("FuelAmount"); this.ACTIVATED = compound.getBoolean("Activated"); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); handleUpdateTag(pkt.getNbtCompound()); } @Override public SPacketUpdateTileEntity getUpdatePacket() { return new SPacketUpdateTileEntity(pos, 3, getUpdateTag()); } @Override public NBTTagCompound getUpdateTag() { return this.writeToNBT(new NBTTagCompound()); } @Override public void update() { if (ACTIVATED) { removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; markDirty(); setActivated(false); } } } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return !(newSate.getBlock() instanceof BlockAutoMiner); } } It seems like I didn't create the tile entity right...
-
Also, is this going to work? package com.Egietje.AutoMiner.blocks; import java.util.Random; import com.Egietje.AutoMiner.entities.tileentities.TileEntityAutoMiner; import com.Egietje.AutoMiner.init.AMBlocks; import com.Egietje.AutoMiner.init.AMItems; import net.minecraft.block.Block; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemBoat; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockAutoMiner extends Block implements ITileEntityProvider { public static final PropertyDirection FACING = BlockHorizontal.FACING; public static IProperty ACTIVATED = PropertyBool.create("activated"); public BlockAutoMiner() { super(Material.PISTON); this.setDefaultState( this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVATED, false)); } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(AMBlocks.AUTO_MINER); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(AMBlocks.AUTO_MINER); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2); } 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 IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); return state.withProperty(ACTIVATED, te.ACTIVATED); } public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING, ACTIVATED }); } @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) { if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); if (te.ACTIVATED) { EnumFacing enumfacing = (EnumFacing) stateIn.getValue(FACING); double d0 = (double) pos.getX() + 0.5D; double d1 = (double) pos.getY() + 0.5D; double d2 = (double) pos.getZ() + 0.5D; double d3 = 0.52D; double d4 = rand.nextDouble() * 0.6D - 0.3D; switch (enumfacing) { case WEST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case EAST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case NORTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]); break; case SOUTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]); default: break; } } } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) { if (TileEntityFurnace.isItemFuel(playerIn.getHeldItem(hand))) { if (!playerIn.isCreative()) { playerIn.getHeldItem(hand).shrink(1); } if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); te.addFuel(TileEntityFurnace.getItemBurnTime(playerIn.getHeldItem(hand))); } } else if (playerIn.getHeldItem(hand).getItem() == AMItems.WRENCH) { if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); if (te.ACTIVATED) { te.setActivated(false); } else { te.setActivated(true); } } } return true; } return false; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityAutoMiner(); } } package com.Egietje.AutoMiner.entities.tileentities; import com.Egietje.AutoMiner.blocks.BlockAutoMiner; import com.Egietje.AutoMiner.init.AMBlocks; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class TileEntityAutoMiner extends TileEntity implements ITickable { public int FUEL_AMOUNT = 0; public boolean ACTIVATED = false; public void addFuel(int amount) { System.out.println("Before: " + FUEL_AMOUNT); System.out.println("Added: " + amount); this.FUEL_AMOUNT += amount; System.out.println("After: " + FUEL_AMOUNT); markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } public void removeFuel() { if (this.FUEL_AMOUNT > 0) { this.FUEL_AMOUNT--; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } public boolean isActivated() { return ACTIVATED; } public void setActivated(boolean active) { ACTIVATED = active; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("FuelAmount", this.FUEL_AMOUNT); compound.setBoolean("Activated", this.ACTIVATED); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.FUEL_AMOUNT = compound.getInteger("FuelAmount"); this.ACTIVATED = compound.getBoolean("Activated"); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); handleUpdateTag(pkt.getNbtCompound()); } @Override public SPacketUpdateTileEntity getUpdatePacket() { return new SPacketUpdateTileEntity(pos, 3, getUpdateTag()); } @Override public NBTTagCompound getUpdateTag() { return this.writeToNBT(new NBTTagCompound()); } @Override public void update() { if (ACTIVATED) { removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; setActivated(false); } } } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return !(newSate.getBlock() instanceof BlockAutoMiner); } }
-
How can I make it so they have different textures?
-
Not checking if it was server or client didn't make a difference. Also, how would I go about making powered a property and not 2 different blocks? Any vanilla examples?
-
I meant that. Also, it doesn't work D: Any suggestions?
-
So basicly this? @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return !(newSate.getBlock() instanceof BlockAutoMiner); } Also, typo in the games code: newSate instead of newState
-
So, I now have this, and it seems to be working fine. @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) { if (TileEntityFurnace.isItemFuel(playerIn.getHeldItem(hand))) { if (!playerIn.isCreative()) { playerIn.getHeldItem(hand).shrink(1); } if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); te.addFuel(TileEntityFurnace.getItemBurnTime(playerIn.getHeldItem(hand))); } } else if (playerIn.getHeldItem(hand).getItem() == AMItems.WRENCH) { if (!powered) { worldIn.setBlockState(pos, AMBlocks.POWERED_AUTO_MINER.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3); } else { worldIn.setBlockState(pos, AMBlocks.AUTO_MINER.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3); } } return true; } return false; } But now, every time I activate it with a wrench, it immediately changes back to the deactivated. I tested and found out it was because fuel kept getting reset to zero when activated. How can I fix this? Here's the tile entity. public class TileEntityAutoMiner extends TileEntity implements ITickable { public int FUEL_AMOUNT = 0; public void addFuel(int amount) { System.out.println("Before: " + FUEL_AMOUNT); System.out.println("Added: " + amount); this.FUEL_AMOUNT += amount; System.out.println("After: " + FUEL_AMOUNT); markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } public void removeFuel() { if (this.FUEL_AMOUNT > 0) { this.FUEL_AMOUNT--; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); writeUpdateTag(compound); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); readUpdateTag(compound); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { NBTTagCompound compound = pkt.getNbtCompound(); readUpdateTag(compound); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); writeUpdateTag(compound); return new SPacketUpdateTileEntity(pos, getBlockMetadata(), compound); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound compound = super.getUpdateTag(); writeUpdateTag(compound); return compound; } public void writeUpdateTag(NBTTagCompound compound) { compound.setInteger("FuelAmount", this.FUEL_AMOUNT); } public void readUpdateTag(NBTTagCompound compound) { this.FUEL_AMOUNT = compound.getInteger("FuelAmount"); } @Override public void update() { if (world.getBlockState(pos).getBlock() == AMBlocks.POWERED_AUTO_MINER) { removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; world.setBlockState(pos, AMBlocks.AUTO_MINER.getDefaultState().withProperty(BlockAutoMiner.FACING, world.getBlockState(pos).getValue(BlockAutoMiner.FACING)), 3); } } } }
-
Hello, I'm trying to make an auto miner. When I right-click it with a fuel item or block it should take the item and activate and deactivate when the fuel runs out. But now when I right-click with a fuel item it doesn't work. And when I right-click with a fuel block it activates. Also, how do I get the slot that the player is holding? My code so far: Block class public class BlockAutoMiner extends Block implements ITileEntityProvider { public static final PropertyDirection FACING = BlockHorizontal.FACING; private final boolean powered; public BlockAutoMiner(boolean powered) { super(Material.PISTON); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.powered = powered; } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(AMBlocks.AUTO_MINER); } @Override public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(AMBlocks.AUTO_MINER); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2); } 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); } public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING }); } @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) { if (this.powered) { EnumFacing enumfacing = (EnumFacing) stateIn.getValue(FACING); double d0 = (double) pos.getX() + 0.5D; double d1 = (double) pos.getY() + 0.5D; double d2 = (double) pos.getZ() + 0.5D; double d3 = 0.52D; double d4 = rand.nextDouble() * 0.6D - 0.3D; switch (enumfacing) { case WEST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case EAST: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]); break; case NORTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]); break; case SOUTH: worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]); default: break; } } } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { if (hand == EnumHand.MAIN_HAND) { if (isItemFuel(playerIn.getHeldItemMainhand())) { if (worldIn.getTileEntity(pos) instanceof TileEntityAutoMiner) { TileEntityAutoMiner te = (TileEntityAutoMiner) worldIn.getTileEntity(pos); te.addFuel(getItemBurnTime(playerIn.getHeldItemMainhand())); playerIn.inventory.decrStackSize(EntityEquipmentSlot.MAINHAND.getIndex(), 1); } if (!powered) { worldIn.setBlockState(pos, AMBlocks.POWERED_AUTO_MINER.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3); } } else { if (powered) { worldIn.setBlockState(pos, AMBlocks.AUTO_MINER.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3); } } return true; } } return false; } public static int getItemBurnTime(ItemStack stack) { if (stack.isEmpty()) { return 0; } else { Item item = stack.getItem(); if (!item.getRegistryName().getResourceDomain().equals("minecraft")) { int burnTime = net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack); if (burnTime != 0) return burnTime; } if (item == Item.getItemFromBlock(Blocks.WOODEN_SLAB)) { return 150; } else if (item == Item.getItemFromBlock(Blocks.WOOL)) { return 100; } else if (item == Item.getItemFromBlock(Blocks.CARPET)) { return 67; } else if (item == Item.getItemFromBlock(Blocks.LADDER)) { return 300; } else if (item == Item.getItemFromBlock(Blocks.WOODEN_BUTTON)) { return 100; } else if (Block.getBlockFromItem(item).getDefaultState().getMaterial() == Material.WOOD) { return 300; } else if (item == Item.getItemFromBlock(Blocks.COAL_BLOCK)) { return 16000; } else if (item instanceof ItemTool && "WOOD".equals(((ItemTool) item).getToolMaterialName())) { return 200; } else if (item instanceof ItemSword && "WOOD".equals(((ItemSword) item).getToolMaterialName())) { return 200; } else if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe) item).getMaterialName())) { return 200; } else if (item == Items.STICK) { return 100; } else if (item != Items.BOW && item != Items.FISHING_ROD) { if (item == Items.SIGN) { return 200; } else if (item == Items.COAL) { return 1600; } else if (item == Items.LAVA_BUCKET) { return 20000; } else if (item != Item.getItemFromBlock(Blocks.SAPLING) && item != Items.BOWL) { if (item == Items.BLAZE_ROD) { return 2400; } else if (item instanceof ItemDoor && item != Items.IRON_DOOR) { return 200; } else { return item instanceof ItemBoat ? 400 : 0; } } else { return 100; } } else { return 300; } } } public static boolean isItemFuel(ItemStack stack) { return getItemBurnTime(stack) > 0; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityAutoMiner(); } } Tileentity class public class TileEntityAutoMiner extends TileEntity implements ITickable { public int FUEL_AMOUNT = 0; public void addFuel(int amount) { this.FUEL_AMOUNT += amount; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } public void removeFuel() { if (this.FUEL_AMOUNT > 0) { this.FUEL_AMOUNT--; markDirty(); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); writeUpdateTag(compound); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); readUpdateTag(compound); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { NBTTagCompound compound = pkt.getNbtCompound(); readUpdateTag(compound); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); writeUpdateTag(compound); return new SPacketUpdateTileEntity(pos, getBlockMetadata(), compound); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound compound = super.getUpdateTag(); writeUpdateTag(compound); return compound; } public void writeUpdateTag(NBTTagCompound compound) { compound.setInteger("FuelAmount", this.FUEL_AMOUNT); } public void readUpdateTag(NBTTagCompound compound) { this.FUEL_AMOUNT = compound.getInteger("FuelAmount"); } @Override public void update() { if (world.getBlockState(pos).getBlock() == AMBlocks.POWERED_AUTO_MINER) { removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; world.setBlockState(pos, AMBlocks.AUTO_MINER.getDefaultState().withProperty(BlockAutoMiner.FACING, world.getBlockState(pos).getValue(BlockAutoMiner.FACING)), 3); } } } }
-
It just isn't supported here anymore.
-
Why can't you? Also why 1.10, if you update you should go to the latest version (1.11.2)
-
Help moving items from inventory to hotbar
Kokkie replied to JakeNelson1999's topic in Modder Support
Use packets -
In your CommonProxy, create a preInit method, in preInit in your main class call proxy.preInit at the end of the method.
-
Go to github.com, make an account, click on start a project, choose a name, create it, add a README.md, click on upload files, upload them, share the link
-
Can you post your code in a github repo?
-
For items, do ModelLoader.setCustomModelResourceLocation(ModItems.youritem, 0, new ModelResourceLocation(ModItems.youritem.getRegistryName(), "inventory"));
-
Change block to ModBlocks.yourblock.
-
Show the item model.
-
Have you changed the name in the item folder as well?
-
Indeed it is...
-
You haven't changed the name... In your blockstates folder change the name of towncentre.json to blocktowncentre.json and the same for your model.
-
It doesn't have anything to do with the chat. Use the EntityJoinWorldEvent and get the EntityPlayer from it and use EntityPlayer#addPrefix.
-
Don't post in old posts, if you want the answer make your own post.