Search in sources :

Example 41 with GlobalCoordinate

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

the class ShieldBlock method wrenchSneakSelect.

@Override
protected boolean wrenchSneakSelect(World world, int x, int y, int z, EntityPlayer player) {
    if (!world.isRemote) {
        GlobalCoordinate currentBlock = SmartWrenchItem.getCurrentBlock(player.getHeldItem());
        if (currentBlock == null) {
            SmartWrenchItem.setCurrentBlock(player.getHeldItem(), new GlobalCoordinate(new Coordinate(x, y, z), world.provider.dimensionId));
            Logging.message(player, EnumChatFormatting.YELLOW + "Selected block");
        } else {
            SmartWrenchItem.setCurrentBlock(player.getHeldItem(), null);
            Logging.message(player, EnumChatFormatting.YELLOW + "Cleared selected block");
        }
    }
    return true;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 42 with GlobalCoordinate

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

the class FavoriteDestinationsProperties method writeFavoritesToNBT.

private static void writeFavoritesToNBT(NBTTagCompound tagCompound, Collection<GlobalCoordinate> destinations) {
    NBTTagList lst = new NBTTagList();
    for (GlobalCoordinate 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());
        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 43 with GlobalCoordinate

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

the class FavoriteDestinationsProperties method readCoordinatesFromNBT.

private static void readCoordinatesFromNBT(NBTTagCompound tagCompound, Set<GlobalCoordinate> destinations) {
    NBTTagList lst = tagCompound.getTagList("destinations", net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < lst.tagCount(); i++) {
        NBTTagCompound tc = lst.getCompoundTagAt(i);
        Coordinate c = new Coordinate(tc.getInteger("x"), tc.getInteger("y"), tc.getInteger("z"));
        destinations.add(new GlobalCoordinate(c, tc.getInteger("dim")));
    }
}
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 44 with GlobalCoordinate

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

the class PeacefulAreaManager method isPeaceful.

public static boolean isPeaceful(GlobalCoordinate coordinate) {
    if (areas.isEmpty()) {
        return false;
    }
    List<GlobalCoordinate> toRemove = new ArrayList<GlobalCoordinate>();
    boolean peaceful = false;
    long curtime = System.currentTimeMillis() - 10000;
    for (Map.Entry<GlobalCoordinate, PeacefulArea> entry : areas.entrySet()) {
        PeacefulArea area = entry.getValue();
        GlobalCoordinate entryCoordinate = entry.getKey();
        if (area.in(coordinate, entryCoordinate)) {
            peaceful = true;
        }
        if (area.getLastTouched() < curtime) {
            // Hasn't been touched for at least 10 seconds. Probably no longer valid.
            // To be sure we will first check this by testing if the environmental controller is still active and running.
            WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
            if (world != null) {
                Coordinate c = entryCoordinate.getCoordinate();
                // If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
                if (!world.getChunkProvider().chunkExists(c.getX() >> 4, c.getZ() >> 4)) {
                    boolean removeArea = true;
                    TileEntity te = world.getTileEntity(c.getX(), c.getY(), c.getZ());
                    if (te instanceof EnvironmentalControllerTileEntity) {
                        EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                        for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
                            if (module instanceof PeacefulEModule) {
                                if (((PeacefulEModule) module).isActive()) {
                                    removeArea = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (removeArea) {
                        toRemove.add(entryCoordinate);
                    }
                }
            }
        }
    }
    for (GlobalCoordinate globalCoordinate : toRemove) {
        areas.remove(globalCoordinate);
    }
    return peaceful;
}
Also used : EnvironmentModule(mcjty.rftools.blocks.environmental.modules.EnvironmentModule) ArrayList(java.util.ArrayList) PeacefulEModule(mcjty.rftools.blocks.environmental.modules.PeacefulEModule) WorldServer(net.minecraft.world.WorldServer) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) TileEntity(net.minecraft.tileentity.TileEntity) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) Map(java.util.Map) HashMap(java.util.HashMap)

Example 45 with GlobalCoordinate

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

the class PacketGetDestinationInfo method onMessage.

@Override
public PacketReturnDestinationInfo onMessage(PacketGetDestinationInfo message, MessageContext ctx) {
    World world = ctx.getServerHandler().playerEntity.worldObj;
    TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
    GlobalCoordinate coordinate = destinations.getCoordinateForId(message.receiverId);
    String name;
    if (coordinate == null) {
        name = "?";
    } else {
        TeleportDestination destination = destinations.getDestination(coordinate);
        if (destination == null) {
            name = "?";
        } else {
            name = destination.getName();
            if (name == null || name.isEmpty()) {
                name = destination.getCoordinate() + " (" + destination.getDimension() + ")";
            }
        }
    }
    return new PacketReturnDestinationInfo(message.receiverId, name);
}
Also used : TeleportDestinations(mcjty.rftools.blocks.teleporter.TeleportDestinations) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TeleportDestination(mcjty.rftools.blocks.teleporter.TeleportDestination)

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