Posted August 25, 201510 yr Im trying to connect on Block with another by rightclicking on them with an item. that item stores the last clicked tileentity and sets the connected field in the second clicked tileentity as the first tileentity. Im wondering if im doing it right: package itsamysterious.mods.reallifemod.core.items; import itsamysterious.mods.reallifemod.core.blocks.electrisity.BlockPowerLine; import itsamysterious.mods.reallifemod.core.blocks.tiles.TileEntity_PowerLine; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; public class ItemCable extends Item{ private TileEntity_PowerLine lastTile; public ItemCable() { setUnlocalizedName("ItemCable"); GameRegistry.registerItem(this, getUnlocalizedName().substring(5)); } @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); if(world.getBlockState(pos).getBlock() instanceof BlockPowerLine){ TileEntity_PowerLine toConnectTile = (TileEntity_PowerLine) world.getTileEntity(pos); if(lastTile!=null){ lastTile.connected=toConnectTile; System.out.println("Connected to " + toConnectTile.getPos().toString()); this.lastTile=toConnectTile; lastTile.connected=null; } else{ player.addChatMessage(new ChatComponentText("Now in "+EnumChatFormatting.GREEN+"Connection Mode"+EnumChatFormatting.RESET+"To stop connecting, hold SHIFT+RIGHTCLICK! ")); this.lastTile = toConnectTile; } }else { this.lastTile=null; } return stack; } }
August 25, 201510 yr dont save the lastclicked inside the item. u need to use nbt for that, bc everything inside the item class is shared for all items.
August 25, 201510 yr u could save the x,y,z position of the te in the nbt and then get the te if u need it via world.getTileEntity
August 25, 201510 yr thats a terrible idea to be honest. ClientProxy is for Client Stuff, checking which TE's are to get connected should be a decision made on server side, so u cant hack.
August 25, 201510 yr instead of the line where you have this.lastTile = toConnect you would use this: NBTTagCompound nbt = (stack.hasTagCompound()) ? stack.getTagCompound() : new NBTTagCompound(); nbt.setIntegerArray("lastTile",new int[]{toConnectTile.xCoord, toConnectTile.yCoord, toConnectTile.zCoord}; stack.setTagCompound(nbt); when you need to get the last tile entity: int[] position = stack.getTagCompound().getIntegerArray("lastTile"); TileEntity lastTE = MinecraftServer.getServer().getWorld().getTileEntityAt(position[0], position[1], position[2]); I might have some of the method names wrong because I don't have an IDE right now, but you should be doing something like this, but you will want to add in some more checks to make sure you only use applicable TE's. Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
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.