Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;

}

}

 

 

 

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.

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

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.