use of pneumaticCraft.common.tileentity.TileEntitySecurityStation in project PneumaticCraft by MineMaarten.
the class ItemRemote method onUpdate.
@Override
public void onUpdate(ItemStack remote, World worl, Entity entity, int slot, boolean holdingItem) {
if (!worl.isRemote) {
NBTTagCompound tag = remote.getTagCompound();
if (tag != null) {
if (tag.hasKey("securityX")) {
int x = tag.getInteger("securityX");
int y = tag.getInteger("securityY");
int z = tag.getInteger("securityZ");
int dimensionId = tag.getInteger("securityDimension");
WorldServer world = null;
for (WorldServer w : MinecraftServer.getServer().worldServers) {
if (w.provider.dimensionId == dimensionId) {
world = w;
break;
}
}
if (world != null) {
TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof TileEntitySecurityStation)) {
tag.removeTag("securityX");
tag.removeTag("securityY");
tag.removeTag("securityZ");
tag.removeTag("securityDimension");
}
}
}
}
}
}
use of pneumaticCraft.common.tileentity.TileEntitySecurityStation in project PneumaticCraft by MineMaarten.
the class ItemRemote method isAllowedToEdit.
private boolean isAllowedToEdit(EntityPlayer player, ItemStack remote) {
NBTTagCompound tag = remote.getTagCompound();
if (tag != null) {
if (tag.hasKey("securityX")) {
int x = tag.getInteger("securityX");
int y = tag.getInteger("securityY");
int z = tag.getInteger("securityZ");
int dimensionId = tag.getInteger("securityDimension");
WorldServer world = null;
for (WorldServer w : MinecraftServer.getServer().worldServers) {
if (w.provider.dimensionId == dimensionId) {
world = w;
break;
}
}
if (world != null) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntitySecurityStation) {
boolean canAccess = ((TileEntitySecurityStation) te).doesAllowPlayer(player);
if (!canAccess) {
player.addChatComponentMessage(new ChatComponentTranslation("gui.remote.noEditRights", x, y, z));
}
return canAccess;
}
}
}
}
return true;
}
use of pneumaticCraft.common.tileentity.TileEntitySecurityStation in project PneumaticCraft by MineMaarten.
the class BlockSecurityStation method onBlockPlacedBy.
/**
* Called when the block is placed in the world.
*/
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack iStack) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntitySecurityStation && entityLiving != null) {
((TileEntitySecurityStation) te).sharedUsers.add(((EntityPlayer) entityLiving).getGameProfile());
}
super.onBlockPlacedBy(world, x, y, z, entityLiving, iStack);
}
use of pneumaticCraft.common.tileentity.TileEntitySecurityStation in project PneumaticCraft by MineMaarten.
the class ItemRemote method onItemUseFirst.
/**
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
*/
@Override
public boolean onItemUseFirst(ItemStack remote, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && !player.isSneaking() && isAllowedToEdit(player, remote)) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntitySecurityStation) {
if (((TileEntitySecurityStation) te).doesAllowPlayer(player)) {
NBTTagCompound tag = remote.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
remote.setTagCompound(tag);
}
tag.setInteger("securityX", x);
tag.setInteger("securityY", y);
tag.setInteger("securityZ", z);
tag.setInteger("securityDimension", world.provider.dimensionId);
player.addChatComponentMessage(new ChatComponentTranslation("gui.remote.boundSecurityStation", x, y, z));
return true;
} else {
player.addChatComponentMessage(new ChatComponentTranslation("gui.remote.cantBindSecurityStation"));
}
}
}
return false;
}
use of pneumaticCraft.common.tileentity.TileEntitySecurityStation in project PneumaticCraft by MineMaarten.
the class PneumaticCraftUtils method getSecurityStations.
public static Iterable<TileEntitySecurityStation> getSecurityStations(final World world, final int x, final int y, final int z, final boolean placementRange) {
return new Iterable<TileEntitySecurityStation>() {
@Override
public Iterator<TileEntitySecurityStation> iterator() {
return new Iterator<TileEntitySecurityStation>() {
private final int range = placementRange ? 32 : 16;
private int i = x - range;
private int j = z - range;
private TileEntitySecurityStation curStation;
private int chunkTileEntityIndex = -1;
@Override
public boolean hasNext() {
if (curStation != null)
return true;
for (; i <= x + range; i += 16) {
for (; j <= z + range; j += 16) {
Chunk chunk = world.getChunkFromBlockCoords(i, j);
int curIndex = 0;
for (TileEntity te : (Iterable<TileEntity>) chunk.chunkTileEntityMap.values()) {
if (curIndex > chunkTileEntityIndex && te instanceof TileEntitySecurityStation) {
TileEntitySecurityStation station = (TileEntitySecurityStation) te;
if (station.hasValidNetwork()) {
if (Math.abs(station.xCoord - x) <= station.getSecurityRange() + (placementRange ? 16 : 0) && Math.abs(station.yCoord - y) <= station.getSecurityRange() + (placementRange ? 16 : 0) && Math.abs(station.zCoord - z) <= station.getSecurityRange() + (placementRange ? 16 : 0)) {
curStation = station;
chunkTileEntityIndex = curIndex;
return true;
}
}
}
curIndex++;
}
chunkTileEntityIndex = -1;
}
j = z - range;
}
return false;
}
@Override
public TileEntitySecurityStation next() {
if (hasNext()) {
TileEntitySecurityStation station = curStation;
curStation = null;
return station;
} else {
throw new NoSuchElementException();
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
Aggregations