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

So I am creating a Teleporter type mod, which adds two types of teleporters. The 'Main Teleporter' which can be used to teleport to any connected 'Teleporter', and The 'Teleporter' which can only be connected to the 'Main Teleporter'. What I am wondering is what would be the best way to make a certain Item be able to link the 'Main Teleporter' and 'Teleporter' so that the owner can teleport between the two.

I''m guessing you're using tile entities for the teleporters? I'd say use the item to link via a string tag per entity and then use that in a map as keys for the locations. The item wouldn't even need to store the data in this case.

I think its my java of the variables.

  • Author

Another thing I am wondering is how would I make it so that only the person who placed the block is able to destroy it, and what would be a good way to make an item to link the teleporters, yes I am using TileEntities for the teleporters.

Another thing I am wondering is how would I make it so that only the person who placed the block is able to destroy it, and what would be a good way to make an item to link the teleporters, yes I am using TileEntities for the teleporters.

 

override getBlockRelativePlayerHardness (iirc the method name correctly, search the Block class)

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.

  • Author

So I have this in the tileentity class:

 

 

public class TileEntityMainTeleporter extends TileEntity

{

protected UUID ownerUUID = null;

protected String ownerUsername = "";

 

public void readFromNBT(NBTTagCompound compound)

{

if (compound.hasKey("UUIDLeast", 4) && compound.hasKey("UUIDMost", 4))

{

this.ownerUUID = new UUID(compound.getLong("UUIDLeast"), compound.getLong("UUIDMost"));

}

else

{

this.ownerUUID = null;

}

}

 

public void writeToNBT(NBTTagCompound compound)

{

super.writeToNBT(compound);

 

if (this.ownerUUID != null)

{

compound.setLong("UUIDLeast", this.ownerUUID.getLeastSignificantBits());

compound.setLong("UUIDMost", this.ownerUUID.getMostSignificantBits());

}

}

 

public void setTeleporterOwner(EntityPlayer entityplayer)

{

this.ownerUUID = entityplayer.getUniqueID();

}

 

public UUID getTeleporterOwnerUUID()

{

return this.ownerUUID;

}

}

 

 

and these in the block class:

 

 

public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)

{

TileEntity tileentity = world.getTileEntity(pos);

 

if (tileentity instanceof TileEntityMainTeleporter)

{

((TileEntityMainTeleporter) tileentity).setTeleporterOwner((EntityPlayer) placer);

}

}

 

public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, BlockPos pos)

{

TileEntity tileentity = world.getTileEntity(pos);

 

if (tileentity instanceof TileEntityMainTeleporter)

{

TileEntityMainTeleporter tileentitymainteleporter = (TileEntityMainTeleporter) tileentity;

boolean flag = tileentitymainteleporter.getTeleporterOwnerUUID() != null && tileentitymainteleporter.getTeleporterOwnerUUID().equals(player.getUniqueID());

 

if (flag || player.capabilities.isCreativeMode)

{

return super.getPlayerRelativeBlockHardness(player, world, pos);

}

}

 

return -1.0F;

}

 

 

 

Now this works, except every time I log out of the world and come back in, I cannot break the block unless I go into creative.

You're going to have to debug.  It looks like the UUID isn't saving or loading properly so it ends up as null.

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.

Well, when you right-click the block with the item, store data in the stack's NBT tag.

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.

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.