Jump to content

[1.8] Creating teleporters


Jedispencer21

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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