Search in sources :

Example 1 with TileEntitySecurityStation

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");
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySecurityStation(pneumaticCraft.common.tileentity.TileEntitySecurityStation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer)

Example 2 with TileEntitySecurityStation

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySecurityStation(pneumaticCraft.common.tileentity.TileEntitySecurityStation) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer)

Example 3 with TileEntitySecurityStation

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySecurityStation(pneumaticCraft.common.tileentity.TileEntitySecurityStation)

Example 4 with TileEntitySecurityStation

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySecurityStation(pneumaticCraft.common.tileentity.TileEntitySecurityStation) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with TileEntitySecurityStation

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();
                }
            };
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySecurityStation(pneumaticCraft.common.tileentity.TileEntitySecurityStation) Iterator(java.util.Iterator) Chunk(net.minecraft.world.chunk.Chunk) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)5 TileEntitySecurityStation (pneumaticCraft.common.tileentity.TileEntitySecurityStation)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)2 WorldServer (net.minecraft.world.WorldServer)2 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Chunk (net.minecraft.world.chunk.Chunk)1