Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2013 22:02
Show Gist options
  • Save anonymous/7295390 to your computer and use it in GitHub Desktop.
Save anonymous/7295390 to your computer and use it in GitHub Desktop.
package mods.astro.enderscience.tileentities;
import java.util.List;
import mods.astro.enderscience.EnderScience;
import mods.astro.enderscience.blocks.TeleportBlock;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.World;
public class TeleporterTileEntity extends TileEntity
{
String playername;
public boolean hasTarget = false;
public boolean hasStored = false;
public int targetx;
public int targety;
public int targetz;
public void pair(EntityPlayer player, World world, int x, int y, int z)
{
playername = player.getEntityName();
readFromNBT(EnderScience.teleporter);
if(player.getCurrentEquippedItem() != null)
{
if(player.getCurrentEquippedItem().itemID == EnderScience.teleporterPairer.itemID && !hasStored)
{
hasStored = true;
hasTarget = false;
targetx = x;
targety = y;
targetz = z;
writeToNBT(EnderScience.teleporter);
ChatMessageComponent chat = new ChatMessageComponent().createFromText("Teleporter at " + targetx + ", " + targety + ", " + targetz + " has been selected.");
player.sendChatToPlayer(chat);
}
else if(player.getCurrentEquippedItem().itemID == EnderScience.teleporterPairer.itemID && hasStored)
{
ChatMessageComponent chat = new ChatMessageComponent().createFromText(
"The teleporter at " + x + ", " + y + ", " + z +
" has been paired with the teleporter at " + targetx + ", " + targety + ", " + targetz + ".");
player.sendChatToPlayer(chat);
hasStored = false;
hasTarget = true;
//Insert code to load the chunk that Block #1 is at.
TeleporterTileEntity t = (TeleporterTileEntity)world.getBlockTileEntity(targetx, targety, targetz);
t.targetx = x;
t.targety = y;
t.targetz = z;
t.hasStored = false;
t.hasTarget = true;
writeToNBT(EnderScience.teleporter);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger(playername + "blockx", targetx);
nbt.setInteger(playername + "blocky", targety);
nbt.setInteger(playername + "blockz", targetz);
nbt.setBoolean(playername + "hasStored", hasStored);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.targetx = nbt.getInteger(playername + "blockx");
this.targety = nbt.getInteger(playername + "blocky");
this.targetz = nbt.getInteger(playername + "blockz");
this.hasStored = nbt.getBoolean(playername + "hasStored");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment