
Everything posted by Kokkie
-
[1.12] Recipe registry
Hi, I'm trying the new registry using events, but I seem to get a nullpointer exception. The console is not helping at all. Here's my code. Main class. @Mod(modid = Reference.ID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = "[" + Reference.MC_VERSION + "]") public class AutoMiner { @Instance public static AutoMiner INSTANCE = new AutoMiner(); @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY) public static CommonProxy PROXY = new CommonProxy(); @EventHandler public static void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new AMRegistryHandler()); new AMItems(); new AMBlocks(); new AMEntities(); new AMRecipes(); PROXY.setTitle("Minecraft - " + Reference.MC_VERSION + " AutoMiner - " + Reference.VERSION); } @EventHandler public static void init(FMLInitializationEvent event) { } @EventHandler public static void postInit(FMLPostInitializationEvent event) { } } Handler. public class AMRegistryHandler { @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(AMBlocks.BLOCKS); } @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(AMItems.ITEMS); for (int i = 0; i < AMBlocks.BLOCKS.length; i++) { Block block = AMBlocks.BLOCKS[i]; event.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName()) .setUnlocalizedName(block.getUnlocalizedName())); } } @SubscribeEvent public static void registerModels(ModelRegistryEvent event) { for (int i = 0; i < AMBlocks.BLOCKS.length; i++) { Block block = AMBlocks.BLOCKS[i]; ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } for (int i = 0; i < AMItems.ITEMS.length; i++) { Item item = AMItems.ITEMS[i]; ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } } } Blocks class. public class AMBlocks { public static final Block STEEL_BLOCK = new Block(Material.IRON).setCreativeTab(AMTabs.AM_TAB).setHardness(8.0F) .setResistance(15.0F); public static final Block AUTO_MINER = new BlockAutoMiner().setCreativeTab(AMTabs.AM_TAB).setHardness(7.0F) .setResistance(20.0F); public static final Block[] BLOCKS = new Block[] { STEEL_BLOCK, AUTO_MINER }; public AMBlocks() { STEEL_BLOCK.setHarvestLevel("pickaxe", 2); AUTO_MINER.setHarvestLevel("pickaxe", 1); AMUtils.setNames(STEEL_BLOCK, "steel_block"); AMUtils.setNames(AUTO_MINER, "auto_miner"); } } Items class. public class AMItems { public static final Item STEEL_INGOT = new Item().setCreativeTab(AMTabs.AM_TAB); public static final Item WRENCH = new Item().setCreativeTab(AMTabs.AM_TAB).setMaxDamage(128).setMaxStackSize(1); public static final Item[] ITEMS = new Item[] { STEEL_INGOT, WRENCH }; public AMItems() { AMUtils.setNames(STEEL_INGOT, "steel_ingot"); AMUtils.setNames(WRENCH, "wrench"); } } Also, the error in the console. java.lang.NullPointerException: Initializing game at net.minecraft.client.util.SearchTree.lambda$func_194042_b$0(SearchTree.java:57) at java.util.ArrayList.forEach(Unknown Source) at net.minecraft.client.util.SearchTree.func_194042_b(SearchTree.java:55) at net.minecraft.client.util.SearchTree.func_194043_a(SearchTree.java:50) at java.util.ArrayList.forEach(Unknown Source) at net.minecraft.client.Minecraft.func_193986_ar(Minecraft.java:640) at net.minecraft.client.Minecraft.init(Minecraft.java:565) at net.minecraft.client.Minecraft.run(Minecraft.java:411) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26)
- [1.12] Plant sapling based on Block
-
[1.12] Plant sapling based on Block
world.setBlockState(pos, Block.getBlockFromItem(stack.getItem()).getDefaultState().withProperty(BlockSapling.TYPE, BlockPlanks.EnumType.TYPE))
-
[1.12] Plant sapling based on Block
Set fortune to a level so that it drops leaves every time, use a for loop to get every individual itemstack
-
(Solved) Must run server. Eula.text wont generate. How to agree to eula??
This is Forge, no Spigot etc. Also, this is over 2 years old so you shouldn't reply here...
-
[SOLVED][1.11.2] onBlockActivated doesn't work
That method doesn't override anything... You've probably copied it from an older version because the parameters have changed.
-
Minecraft 1.2.5 Tekkit Classic Crash
1.2.5 isn't supported, and hasn't been for a really long time. Also, wrong subforum.
-
[1.12] Block destroyed method
Okay, thanks!
-
[SOLVED][1.11.2] Commands Usage
Show your register code.
-
[1.12] Block destroyed method
Ah yes, that was it, thanks! Also, is it called when a property was changed?
-
[1.12] Block destroyed method
Hello, Is there a method in the Block class that's called when the block is broken by anything? (Explosion, player etc.)
-
HELP! GETS BLOCKS IN AREA!
I was thinking the same thing...
-
[1.12] Tileentity not working right
Thanks, it works! EDIT: Fixed the lava myself, thanks anyway!
-
[1.12] Tileentity not working right
I fixed everything and it's finally working. But now, how do I get the block it should drop? I have this state.getBlock().getItemDropped(world.getBlockState(position), random, 0) but that doesn't work properly for diorite, andesite and granite, because it returns normal stone. Also for logs, the oak, spruce, birch and jungle return oak and the acacia and dark oak return acacia. The planks all return oak. Also, how do I cancel lava from being placed?
-
[1.12] Tileentity not working right
How'd you do it then? Changed it to facing.rotateY() and facing.rotateYCCW().
-
[1.12] Tileentity not working right
Also, by removing the line world.setTileEntity(position, world.getTileEntity(pos)); It does work, only everything gets reset (duh).
-
[1.12] Tileentity not working right
Also, here is what I tested. if (TICKS == 20) { System.out.println("20 1/2"); if (!world.isRemote) { System.out.println("20 2/2"); EnumFacing facing_ = (EnumFacing) world.getBlockState(pos).getValue(BlockAutoMiner.FACING); int index_ = facing_.getHorizontalIndex(); int index = index_ == 0 ? index_ + 3 : index_ - 1; EnumFacing facing = EnumFacing.getHorizontal(index); int index1 = index_ == 3 ? index_ - 3 : index_ + 1; EnumFacing facing1 = EnumFacing.getHorizontal(index1); BlockPos position = pos.offset(world.getBlockState(pos).getValue(BlockAutoMiner.FACING)); BlockPos position1 = position.up(); BlockPos position2 = position.down(); BlockPos position3 = position.offset(facing); BlockPos position4 = position.offset(facing1); BlockPos position5 = position3.up(); BlockPos position6 = position4.up(); BlockPos position7 = position3.down(); BlockPos position8 = position4.down(); ItemStack stack = new ItemStack(world.getBlockState(position).getBlock()); ItemStack stack1 = new ItemStack(world.getBlockState(position1).getBlock()); ItemStack stack2 = new ItemStack(world.getBlockState(position2).getBlock()); ItemStack stack3 = new ItemStack(world.getBlockState(position3).getBlock()); ItemStack stack4 = new ItemStack(world.getBlockState(position4).getBlock()); ItemStack stack5 = new ItemStack(world.getBlockState(position5).getBlock()); ItemStack stack6 = new ItemStack(world.getBlockState(position6).getBlock()); ItemStack stack7 = new ItemStack(world.getBlockState(position7).getBlock()); ItemStack stack8 = new ItemStack(world.getBlockState(position8).getBlock()); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack1)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack2)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack3)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack4)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack5)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack6)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack7)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack8)); world.setBlockToAir(position); world.setBlockToAir(position1); world.setBlockToAir(position2); world.setBlockToAir(position3); world.setBlockToAir(position4); world.setBlockToAir(position5); world.setBlockToAir(position6); world.setBlockToAir(position7); world.setBlockToAir(position8); } } if (TICKS == 40) { System.out.println("40 1/2"); if (!world.isRemote) { System.out.println("40 2/2"); BlockPos position = pos.offset(world.getBlockState(pos).getValue(BlockAutoMiner.FACING)); world.setBlockState(position, world.getBlockState(pos)); world.setTileEntity(position, world.getTileEntity(pos)); world.setBlockToAir(pos); } } With the output in the console being [22:39:18] [Server thread/INFO]: [STDOUT]: 20 1/2 [22:39:18] [Server thread/INFO]: [STDOUT]: 20 2/2 [22:39:18] [main/INFO]: [STDOUT]: 20 1/2 [22:39:19] [Server thread/INFO]: [STDOUT]: 40 1/2 [22:39:19] [Server thread/INFO]: [STDOUT]: 40 2/2 [22:39:19] [main/INFO]: [STDOUT]: 40 1/2 [22:39:20] [main/INFO]: [STDOUT]: 20 1/2 [22:39:21] [main/INFO]: [STDOUT]: 40 1/2 [22:39:22] [main/INFO]: [STDOUT]: 20 1/2 [22:39:23] [main/INFO]: [STDOUT]: 40 1/2 [22:39:24] [main/INFO]: [STDOUT]: 20 1/2
-
[1.12] Tileentity not working right
When it does that, it stays in place, strangely sets the block in front of it to air, and when you right-click with a wrench it doesn't react (stays on)
-
[1.12] How do I create the recipes in this MC version?
https://github.com/MinecraftForge/MinecraftForge/commit/f1cca475eadea9d15c996e521bf9b6b5970425e9 It isn't done yet.
-
[1.12] Tileentity not working right
Okay, now I've got another bug. I've created the code that removes blocks etc. but it seems to be bugged out. What happens is: I feed the machine fuel. I start the machine. Machine destroys first nine blocks. Machine bugs out and won't go any further and can't be turned off. I found this is because after running: BlockPos position = pos.offset(world.getBlockState(pos).getValue(BlockAutoMiner.FACING)); world.setBlockState(position, world.getBlockState(pos)); world.setTileEntity(position, world.getTileEntity(pos)); world.setBlockToAir(pos) The world isn't a "server" anymore, so it won't return false when world.isRemote is called. Does anyone know what could be causing this? Block class 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)); } 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) { if (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.isActivated()) { te.setActivated(false); } else { if (te.FUEL_AMOUNT > 0) { te.setActivated(true); } } } } } return true; } else { if (hand == EnumHand.MAIN_HAND) { if (playerIn.getHeldItem(hand).getItem() == AMItems.WRENCH) { Minecraft.getMinecraft().player.swingArm(hand); } } } return false; } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityAutoMiner(); } @Override public boolean hasTileEntity(IBlockState state) { return true; } } Tile entity class public class TileEntityAutoMiner extends TileEntity implements ITickable { public int FUEL_AMOUNT = 0; public boolean ACTIVATED = false; public boolean UPDATE = false; public int TICKS = 0; public TileEntityAutoMiner() { } public void addFuel(int amount) { this.FUEL_AMOUNT += amount; IBlockState state = world.getBlockState(pos); world.markBlockRangeForRenderUpdate(pos, pos); markDirty(); } public void removeFuel() { if (this.FUEL_AMOUNT > 0) { this.FUEL_AMOUNT--; IBlockState state = world.getBlockState(pos); world.markBlockRangeForRenderUpdate(pos, pos); markDirty(); } } public boolean isActivated() { return ACTIVATED; } public void setActivated(boolean active) { ACTIVATED = active; markDirty(); IBlockState state = world.getBlockState(pos); world.markBlockRangeForRenderUpdate(pos, pos); world.notifyBlockUpdate(pos, state, state, 3); world.scheduleBlockUpdate(pos, this.getBlockType(), 0, 0); } public void addTick() { TICKS++; markDirty(); } public void removeTicks() { TICKS = 0; markDirty(); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("FuelAmount", this.FUEL_AMOUNT); compound.setBoolean("Activated", this.ACTIVATED); compound.setInteger("Ticks", this.TICKS); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.FUEL_AMOUNT = compound.getInteger("FuelAmount"); this.ACTIVATED = compound.getBoolean("Activated"); this.TICKS = compound.getInteger("Ticks"); } @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) { UPDATE = true; removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; setActivated(false); markDirty(); } if (TICKS == 20) { if (!world.isRemote) { EnumFacing facing_ = (EnumFacing) world.getBlockState(pos).getValue(BlockAutoMiner.FACING); int index_ = facing_.getHorizontalIndex(); int index = index_ == 0 ? index_ + 3 : index_ - 1; EnumFacing facing = EnumFacing.getHorizontal(index); int index1 = index_ == 3 ? index_ - 3 : index_ + 1; EnumFacing facing1 = EnumFacing.getHorizontal(index1); BlockPos position = pos.offset(world.getBlockState(pos).getValue(BlockAutoMiner.FACING)); BlockPos position1 = position.up(); BlockPos position2 = position.down(); BlockPos position3 = position.offset(facing); BlockPos position4 = position.offset(facing1); BlockPos position5 = position3.up(); BlockPos position6 = position4.up(); BlockPos position7 = position3.down(); BlockPos position8 = position4.down(); ItemStack stack = new ItemStack(world.getBlockState(position).getBlock()); ItemStack stack1 = new ItemStack(world.getBlockState(position1).getBlock()); ItemStack stack2 = new ItemStack(world.getBlockState(position2).getBlock()); ItemStack stack3 = new ItemStack(world.getBlockState(position3).getBlock()); ItemStack stack4 = new ItemStack(world.getBlockState(position4).getBlock()); ItemStack stack5 = new ItemStack(world.getBlockState(position5).getBlock()); ItemStack stack6 = new ItemStack(world.getBlockState(position6).getBlock()); ItemStack stack7 = new ItemStack(world.getBlockState(position7).getBlock()); ItemStack stack8 = new ItemStack(world.getBlockState(position8).getBlock()); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack1)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack2)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack3)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack4)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack5)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack6)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack7)); world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack8)); world.setBlockToAir(position); world.setBlockToAir(position1); world.setBlockToAir(position2); world.setBlockToAir(position3); world.setBlockToAir(position4); world.setBlockToAir(position5); world.setBlockToAir(position6); world.setBlockToAir(position7); world.setBlockToAir(position8); } } if (TICKS == 40) { if (!world.isRemote) { BlockPos position = pos.offset(world.getBlockState(pos).getValue(BlockAutoMiner.FACING)); world.setBlockState(position, world.getBlockState(pos)); world.setTileEntity(position, world.getTileEntity(pos)); world.setBlockToAir(pos); } } } else { if (UPDATE) { IBlockState state = world.getBlockState(pos); world.markBlockRangeForRenderUpdate(pos, pos); } UPDATE = false; } if (TICKS >= 40) { this.removeTicks(); } else { this.addTick(); } } } Also, no errors in the console.
-
[1.12] Tileentity not working right
Nvm just fixed it.
-
[1.12] Tileentity not working right
Video: 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 TileEntityAutoMiner() { } 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; IBlockState state = world.getBlockState(pos); world.markBlockRangeForRenderUpdate(pos, pos); world.notifyBlockUpdate(pos, state, state, 3); world.scheduleBlockUpdate(pos,this.getBlockType(),0,0); markDirty(); } @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) { System.out.println(FUEL_AMOUNT); removeFuel(); if (FUEL_AMOUNT <= 0) { FUEL_AMOUNT = 0; markDirty(); setActivated(false); } } } } 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)); } 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 { if (te.FUEL_AMOUNT > 0) { te.setActivated(true); } } } } return true; } return false; } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityAutoMiner(); } @Override public boolean hasTileEntity(IBlockState state) { return true; } } How can I fix this?
-
[1.12] Tileentity not working right
Now the texture doesn't update when it is turned of. When I destroy or place a block anywhere it does change. But this doesn't always change the texture back to the turned of state...
-
[1.12] Tileentity not working right
I don't know what I did but I fixed it...
-
[1.12] Tileentity not working right
Couldn't find anything...
IPS spam blocked by CleanTalk.