Posted February 20, 20169 yr So in my mod I made an item that when activated it will place down a tile entity block that is invisible and has the same dimensions as a lily-pad, to give the illusion that you are walking on water, in an air block on top of a water source block When the item spawns the block, it sets an nbt integer of how long the block will last until it "decays." So far the blocks works great when the player is moving forward, however if the player were to stand still when the block under the player decays the held item is not fast enough to place a new one. What I would like to know is how can I have it so that when the item passes onUpdate() it will "reset" the integer of the blocks instead of waiting for them to decay and place a new one Test Item: @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); if (nbt.getBoolean("active")) { //GET PLAYER POSITION int posX = (int) Math.round(entityIn.posX - 0.5f); int posY = (int) entityIn.posY; int posZ = (int) Math.round(entityIn.posZ - 0.5f); //PLACE BLOCKS AROUND PLAYER POSITION for (int x = posX - 1; x <= posX + 1; x++) { for (int z = posZ - 1; z <= posZ + 1; z++) { BlockPos posWater = new BlockPos(x, posY - 1, z); BlockPos posAir = new BlockPos(x, posY, z); //ONLY PLACE BLOCK ONTOP OF WATER/IN AIR if (worldIn.getBlockState(posWater).getBlock() == Blocks.water) { if (worldIn.isAirBlock(posAir)) { worldIn.setBlockState(posAir, ModBlocks.magicLilypad.getDefaultState()); } } } } } } Bridge Block (magic lilypad) @Override public TileEntity createNewTileEntity(World world, int meta) { return new TEMagicLilypad(50); } Tile Entity Bridge Block public class TEMagicLilypad extends TileEntity implements ITickable{ private int ticksRemaining; public TEMagicLilypad(int ticksRemaining) { this.ticksRemaining = ticksRemaining; } @Override public void readFromNBT(NBTTagCompound tagCompound){ super.readFromNBT(tagCompound); this.ticksRemaining = tagCompound.getInteger("TICKS_REMAINING"); } @Override public void writeToNBT(NBTTagCompound tagCompound){ super.writeToNBT(tagCompound); tagCompound.setInteger("TICKS_REMAINING", ticksRemaining); } @Override public void update(){ ticksRemaining--; if (ticksRemaining <= 0){ worldObj.removeTileEntity(getPos()); worldObj.setBlockToAir(getPos()); } } }
February 20, 20169 yr See that "//ONLY PLACE BLOCK ONTOP OF WATER/IN AIR" chunk? Make it look for your own block too, and if it finds it, update the integer in the TE. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 20, 20169 yr Author Well that was my problem, how do I update the integer? I could make it find my block and just replace it with a new block which would set it back to the default integer but I that would probably cause problems on servers down the line
February 20, 20169 yr If only your te had a way for people to edit the integer... perhaps a method that when given an integer assigns it to the internal value.. setting it if you will.... I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
February 20, 20169 yr Author If only your te had a way for people to edit the integer... perhaps a method that when given an integer assigns it to the internal value.. setting it if you will.... but isint Public TEMagicLilypad(int ticksRemaining) { this.ticksRemaining = ticksRemaining;} a method that edits the integer when called? sorry I am SUPER new to everything
February 21, 20169 yr Author Yea was reading the link you gave me and WOOSH right over my head, I probably will just have my test item replace the existing decaying blocks with new "fresh" blocks
February 21, 20169 yr If your item is activated against what appears to be water but really has your bridge on it, then it will probably be activating against your invisible bridge block (not the water beneath). That's possibly the case you want to detect, at which point you want to lookup the TE at that bridge's pos, validate it, and fix its ticks. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
February 22, 20169 yr The problem is that he doesn't know how to use world.getBlockTileEntity() and cast it to his own object, then call a method on it. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 22, 20169 yr Author EUREKA!!!! I believe I've done it I finally got my item to update the stats of my tile entity remotely Item package com.armetron.crystalline_magic.items; import com.armetron.crystalline_magic.blocks.ModBlocks; import com.armetron.crystalline_magic.tileEntity.TEMagicLilypad; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class MagicTester extends Item { public MagicTester(String unlocalizedName) { super(); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(CreativeTabs.tabMaterials); } @Override public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { nbt = new NBTTagCompound(); stack.setTagCompound(nbt); } nbt.setBoolean("active", !(nbt.getBoolean("active"))); return stack; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); if (nbt.getBoolean("active")) { //GET PLAYER POSITION int posX = (int) Math.round(entityIn.posX - 0.5f); int posY = (int) entityIn.posY; int posZ = (int) Math.round(entityIn.posZ - 0.5f); //PLACE BLOCKS AROUND PLAYER POSITION for (int x = posX - 1; x <= posX + 1; x++) { for (int z = posZ - 1; z <= posZ + 1; z++) { BlockPos posWater = new BlockPos(x, posY - 1, z); BlockPos posAir = new BlockPos(x, posY, z); //ONLY PLACE BLOCK ONTOP OF WATER if (worldIn.getBlockState(posWater).getBlock() == Blocks.water) { if (worldIn.isAirBlock(posAir)) { worldIn.setBlockState(posAir, ModBlocks.magicLilypad.getDefaultState()); } //Updates the ticks of an existing TileEntity if (worldIn.getBlockState(posAir).getBlock() == ModBlocks.magicLilypad) { TileEntity lily = worldIn.getTileEntity(posAir); ((TEMagicLilypad) lily).UpdateDecay(7); } } } } } } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); boolean active = nbt.getBoolean("active"); return active; } } Tile Entity package com.armetron.crystalline_magic.tileEntity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; public class TEMagicLilypad extends TileEntity implements ITickable{ private int ticksRemaining; //Used when Tile Entity is made from Block Class public TEMagicLilypad(int ticksRemaining){ this.ticksRemaining = ticksRemaining; } //Function used to manually update the ticks remaining public void UpdateDecay(int ticksRemaining) { this.ticksRemaining = ticksRemaining; } @Override public void readFromNBT(NBTTagCompound tagCompound){ super.readFromNBT(tagCompound); this.ticksRemaining = tagCompound.getInteger("TICKS_REMAINING"); } @Override public void writeToNBT(NBTTagCompound tagCompound){ super.writeToNBT(tagCompound); tagCompound.setInteger("TICKS_REMAINING", ticksRemaining); } //TickRemaining is detucted every tick and block is replaced with air //when ticks run out @Override public void update(){ ticksRemaining--; System.out.println(ticksRemaining); if (ticksRemaining <= 0){ worldObj.removeTileEntity(getPos()); worldObj.setBlockToAir(getPos()); } } } The part that was the hardest to discover is TileEntity lily = worldIn.getTileEntity(posAir); ((TEMagicLilypad) lily).UpdateDecay(7); I had no idea that ((class name) tileEntity) would be what edited the stored tileEntity If you happen to see something that I'm overdoing, underdoing, could make more efficient then please feel free to let me know so that I may learn
February 22, 20169 yr Author woops forgot to take out the System.out.println(ticksRemaining); that's what I used to see that the ticks were being updated
February 22, 20169 yr I had no idea that ((class name) tileEntity) would be what edited the stored tileEntity https://howtoprogramwithjava.com/java-cast/ Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.