Posted August 26, 201411 yr I try to make a different farming system for me. But I need to update my item if it is in my bag. I coded update code but I don't find any way to tick my item to update for my every step. How can I do this? Thanks for everyone
August 26, 201411 yr Halfway the itemclass there is this handy method: /** * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and * update it's contents. */ public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {}
August 26, 201411 yr hi If that doesn't work for you, you could always hook the general tick event and check all the inventory slots to see if your item is in any of them. -TGG
August 27, 201411 yr Author Halfway the itemclass there is this handy method: /** * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and * update it's contents. */ public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {} I tried it but it didn't ticked hi If that doesn't work for you, you could always hook the general tick event and check all the inventory slots to see if your item is in any of them. -TGG But which one because I tried TickHandler -> onPlayerTick but I couldn't
August 27, 201411 yr Whenever asking for help with code, you should always post the code you are using - otherwise we cannot help you beyond vague guesses at what you may be doing incorrectly. http://i.imgur.com/NdrFdld.png[/img]
August 27, 201411 yr Author When I search at internet I found a code named Diamond Meter and try to understand its method. But Inetworkhandler and customsendpacket sections not work I decode code something like this; package net.extend.mod.items; import java.util.ArrayList; import java.util.Date; import javax.swing.Icon; import sun.rmi.runtime.RuntimeUtil.GetInstanceAction; import sun.security.jca.GetInstance; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.extend.mod.ref; import net.extend.mod.functions.writeline; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class ItemCoalMeter extends Item { private IIcon[] iconIndexes = new IIcon[5]; private Long lastUpdate = Long.valueOf(0L); private Long millisPerUpdate = Long.valueOf(100L); private ArrayList found = new ArrayList(); private static int distanceShortest = -1; private int distanceMax = 8; private int[] vectorShortest = new int[3]; private int distancePerLevel; public ItemCoalMeter(String name) { super(); this.maxStackSize=1; this.setCreativeTab(CreativeTabs.tabTools); this.setUnlocalizedName(name); GameRegistry.registerItem(this, name); writeline.s("hamit.txt", "x1"); initProps(); } @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister reg) { for (int x=0; x < 5; x++) { iconIndexes[x] = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + x); } // iconIndexes[0] = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_0"); this.itemIcon = iconIndexes[0]; } public void initProps() { Minecraft mc = FMLClientHandler.instance().getClient(); //ModLoader.getMinecraftInstance(); writeline.s("hamit.txt", "x2"); update(mc); } @SideOnly(Side.CLIENT) public void onUpdate(ItemStack stack, World world, EntityPlayer player, int par4, boolean par5) { Minecraft mc = FMLClientHandler.instance().getClient(); writeline.s("hamit.txt", "x3"); update(mc); } @SideOnly(Side.CLIENT) public void update(Minecraft mc) { writeline.s("hamit.txt", "x4"); if (new Date().getTime() <= lastUpdate.longValue() + millisPerUpdate.longValue()) { return ; } lastUpdate = Long.valueOf(new Date().getTime()); found.clear(); distanceShortest = -1; EntityPlayer player = mc.thePlayer; World world = mc.theWorld; if ((player == null) || (world == null)) { return; } double cur_x = player.posX; double cur_y = player.posY; double cur_z = player.posZ; writeline.d("hamit.txt", player.posX); writeline.d("hamit.txt", player.posY); writeline.d("hamit.txt", player.posZ); int min_x = (int)cur_x - distanceMax - 1; int min_y = (int)cur_y - distanceMax; int min_z = (int)cur_z - distanceMax; int max_x = (int)cur_x + distanceMax; int max_y = (int)cur_y + distanceMax; int max_z = (int)cur_z + distanceMax + 1; writeline.i("hamit.txt", min_x); writeline.i("hamit.txt", min_y); writeline.i("hamit.txt", min_z); writeline.i("hamit.txt", max_x); writeline.i("hamit.txt", max_y); writeline.i("hamit.txt", max_z); for (int z1 = min_z; z1 < max_z; z1++) { for (int x1 = min_x; x1 < max_x; x1++) { for (int y1 = min_y; y1 < max_y; y1++) { if (world.getBlock(x1, y1, z1) == Blocks.coal_ore) { found.add(new int[] { x1, y1, z1 }); writeline.s("hamit.txt", "Bulundu!"); } } } } for (int i = 0; i < found.size(); i++) { int[] block = (int[])found.get(i); double distanceX = block[0] - cur_x; double distanceY = block[1] - cur_y + 1.0D; double distanceZ = block[2] - cur_z; distanceX += (distanceX > 0.0D ? 1.0D : 0.0D); distanceZ += (distanceZ > 0.0D ? 1.0D : 0.0D); double distance2D = Math.sqrt(Math.pow(distanceX, 2.0D) + Math.pow(distanceZ, 2.0D)); double distance3D = Math.sqrt(Math.pow(distance2D, 2.0D) + Math.pow(distanceY, 2.0D)); if ((int)distance3D > distanceMax) { found.remove(i); i--; } else if ((distanceShortest > distance3D) || (distanceShortest == -1)) { distanceShortest = (int)distance3D; vectorShortest = new int[] { block[0], block[1], block[2] }; } } distancePerLevel = distanceMax / 4; if (distancePerLevel < 1) { distancePerLevel = 1; } if (distanceShortest > -1) { int level = (distanceMax - distanceShortest + 1) / distancePerLevel; if (distanceMax < 4) { level +=4 - distanceMax; } this.itemIcon = iconIndexes[level]; } else { this.itemIcon = iconIndexes[0]; } } @SideOnly(Side.CLIENT) public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player) { return true; } } But its not working and Hamit.txt; x1 x2 x4 --> x3 (which is onUpdate) never typed in txt
August 30, 201411 yr Author I solved it with TickHandler onPlayerTick... I tried; @EventHandler public void init(FMLInitializationEvent event) { // proxy.registerRenders(); // FMLCommonHandler.instance().bus().register(new ServerTickHandler()); FMLCommonHandler.instance().bus().register(new NewTickHandler()); // proxy.registerServerTickHandler(); MinecraftForge.EVENT_BUS.register(new ModEntityHandler()); MinecraftForge.EVENT_BUS.register(new DropHandler()); // MinecraftForge.EVENT_BUS.register(new SoundLoadHandler()); EntityRegistry.registerModEntity(EntityNewFishHook.class, "Entity New Fish Hook", 216, this, 75, 1, true); } public class NewTickHandler { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { EntityPlayer player = event.player; InventoryPlayer inventory = player.inventory; if (inventory.hasItem(itemref.coalMeter)) { ((ItemCoalMeter)itemref.coalMeter).initProps(); } } //Called when the client ticks. @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { } //Called when the server ticks. Usually 20 ticks a second. @SubscribeEvent public void onServerTick(TickEvent.ServerTickEvent event) { } //Called when a new frame is displayed (See fps) @SubscribeEvent public void onRenderTick(TickEvent.RenderTickEvent event) { } //Called when the world ticks @SubscribeEvent public void onWorldTick(TickEvent.WorldTickEvent event) { } }
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.