Search in sources :

Example 31 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class MatterTransmitterTileEntity method setTeleportDestination.

public void setTeleportDestination(TeleportDestination teleportDestination, boolean once) {
    this.teleportDestination = null;
    this.teleportId = null;
    this.once = once;
    if (teleportDestination != null) {
        TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
        Integer id = destinations.getIdForCoordinate(new GlobalCoordinate(teleportDestination.getCoordinate(), teleportDestination.getDimension()));
        if (id == null) {
            this.teleportDestination = teleportDestination;
        } else {
            this.teleportId = id;
        }
    }
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    markDirty();
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 32 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class SimpleDialerItemBlock method checkReceiverAccess.

private boolean checkReceiverAccess(EntityPlayer player, World world, Integer id) {
    boolean access = true;
    TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
    GlobalCoordinate coordinate = destinations.getCoordinateForId(id);
    if (coordinate != null) {
        TeleportDestination destination = destinations.getDestination(coordinate);
        if (destination != null) {
            World worldForDimension = RfToolsDimensionManager.getWorldForDimension(destination.getDimension());
            if (worldForDimension != null) {
                TileEntity recTe = worldForDimension.getTileEntity(destination.getCoordinate().getX(), destination.getCoordinate().getY(), destination.getCoordinate().getZ());
                if (recTe instanceof MatterReceiverTileEntity) {
                    MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) recTe;
                    if (!matterReceiverTileEntity.checkAccess(player.getDisplayName())) {
                        access = false;
                    }
                }
            }
        }
    }
    return access;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World)

Example 33 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class SimpleDialerTileEntity method checkStateServer.

@Override
protected void checkStateServer() {
    // Update is called manuall which is why canUpdate() returns false.
    super.checkStateServer();
    if (transmitter == null) {
        return;
    }
    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    int newvalue = BlockTools.getRedstoneSignalIn(meta) ? 1 : 0;
    if (newvalue != prevValue) {
        prevValue = newvalue;
        if (newvalue == 1) {
            TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
            Coordinate coordinate = null;
            int dim = 0;
            if (receiver != null) {
                GlobalCoordinate gc = destinations.getCoordinateForId(receiver);
                if (gc != null) {
                    coordinate = gc.getCoordinate();
                    dim = gc.getDimension();
                }
            }
            int dial = TeleportationTools.dial(worldObj, null, null, transmitter.getCoordinate(), transmitter.getDimension(), coordinate, dim, onceMode);
            if (dial != DialingDeviceTileEntity.DIAL_OK) {
            // @todo some way to report error
            }
        }
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 34 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class TeleportDestinations method writeDestinationsToNBT.

private static void writeDestinationsToNBT(NBTTagCompound tagCompound, Collection<TeleportDestination> destinations, Map<GlobalCoordinate, Integer> coordinateToInteger) {
    NBTTagList lst = new NBTTagList();
    for (TeleportDestination destination : destinations) {
        NBTTagCompound tc = new NBTTagCompound();
        Coordinate c = destination.getCoordinate();
        tc.setInteger("x", c.getX());
        tc.setInteger("y", c.getY());
        tc.setInteger("z", c.getZ());
        tc.setInteger("dim", destination.getDimension());
        tc.setString("name", destination.getName());
        if (coordinateToInteger != null) {
            Integer id = coordinateToInteger.get(new GlobalCoordinate(c, destination.getDimension()));
            if (id != null) {
                tc.setInteger("id", id);
            }
        }
        lst.appendTag(tc);
    }
    tagCompound.setTag("destinations", lst);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 35 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class TeleportDestinations method getValidDestinations.

// Server side only
public Collection<TeleportDestinationClientInfo> getValidDestinations(World worldObj, String playerName) {
    PlayerExtendedProperties properties = null;
    if (playerName != null) {
        List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
        for (Object player : list) {
            EntityPlayerMP entityplayermp = (EntityPlayerMP) player;
            if (playerName.equals(entityplayermp.getDisplayName())) {
                properties = PlayerExtendedProperties.getProperties(entityplayermp);
                break;
            }
        }
    }
    List<TeleportDestinationClientInfo> result = new ArrayList<TeleportDestinationClientInfo>();
    for (TeleportDestination destination : destinations.values()) {
        TeleportDestinationClientInfo destinationClientInfo = new TeleportDestinationClientInfo(destination);
        Coordinate c = destination.getCoordinate();
        World world = DimensionManager.getWorld(destination.getDimension());
        String dimName = null;
        if (world != null) {
            dimName = DimensionManager.getProvider(destination.getDimension()).getDimensionName();
        }
        DimensionInformation information = RfToolsDimensionManager.getDimensionManager(worldObj).getDimensionInformation(destination.getDimension());
        if (information != null) {
            dimName = information.getName();
        }
        if (dimName == null || dimName.trim().isEmpty()) {
            dimName = "Id " + destination.getDimension();
        } else {
            dimName = dimName + " (" + destination.getDimension() + ")";
        }
        destinationClientInfo.setDimensionName(dimName);
        if (world != null) {
            TileEntity te = world.getTileEntity(c.getX(), c.getY(), c.getZ());
            if (te instanceof MatterReceiverTileEntity) {
                MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) te;
                if (playerName != null && !matterReceiverTileEntity.checkAccess(playerName)) {
                    // No access.
                    continue;
                }
            }
        }
        if (properties != null) {
            destinationClientInfo.setFavorite(properties.getFavoriteDestinationsProperties().isDestinationFavorite(new GlobalCoordinate(c, destination.getDimension())));
        }
        result.add(destinationClientInfo);
    }
    Collections.sort(result);
    return result;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DimensionInformation(mcjty.rftools.dimension.DimensionInformation)

Aggregations

GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)78 Coordinate (mcjty.lib.varia.Coordinate)33 TileEntity (net.minecraft.tileentity.TileEntity)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 World (net.minecraft.world.World)13 NBTTagList (net.minecraft.nbt.NBTTagList)7 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)6 ArrayList (java.util.ArrayList)5 TeleportDestination (mcjty.rftools.blocks.teleporter.TeleportDestination)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)4 MovingSound (net.minecraft.client.audio.MovingSound)4 BlockProtectorTileEntity (mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity)3 PlayerExtendedProperties (mcjty.rftools.playerprops.PlayerExtendedProperties)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 WorldServer (net.minecraft.world.WorldServer)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3