Search in sources :

Example 21 with GlobalCoordinate

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

the class BlockProtectorTileEntity method toggleCoordinate.

// Toggle a coordinate to be protected or not. The coordinate given here is absolute.
public void toggleCoordinate(GlobalCoordinate c) {
    if (c.getDimension() != worldObj.provider.dimensionId) {
        // Wrong dimension. Don't do anything.
        return;
    }
    Coordinate relative = absoluteToRelative(c.getCoordinate());
    if (protectedBlocks.contains(relative)) {
        protectedBlocks.remove(relative);
    } else {
        protectedBlocks.add(relative);
    }
    markDirty();
    notifyBlockUpdate();
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate)

Example 22 with GlobalCoordinate

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

the class BlockProtectorTileEntity method getOrCalculateID.

public int getOrCalculateID() {
    if (id == -1) {
        BlockProtectors protectors = BlockProtectors.getProtectors(worldObj);
        GlobalCoordinate gc = new GlobalCoordinate(new Coordinate(xCoord, yCoord, zCoord), worldObj.provider.dimensionId);
        id = protectors.getNewId(gc);
        protectors.save(worldObj);
        setId(id);
    }
    return id;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 23 with GlobalCoordinate

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

the class RenderWorldLastEventHandler method renderProtectedBlocks.

private static void renderProtectedBlocks(RenderWorldLastEvent evt) {
    Minecraft mc = Minecraft.getMinecraft();
    EntityClientPlayerMP p = mc.thePlayer;
    ItemStack heldItem = p.getHeldItem();
    if (heldItem == null) {
        return;
    }
    if (heldItem.getItem() == ModItems.smartWrenchItem) {
        if (SmartWrenchItem.getCurrentMode(heldItem) == SmartWrenchMode.MODE_SELECT) {
            GlobalCoordinate current = SmartWrenchItem.getCurrentBlock(heldItem);
            if (current != null) {
                if (current.getDimension() == mc.theWorld.provider.dimensionId) {
                    TileEntity te = mc.theWorld.getTileEntity(current.getCoordinate().getX(), current.getCoordinate().getY(), current.getCoordinate().getZ());
                    if (te instanceof BlockProtectorTileEntity) {
                        BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
                        Set<Coordinate> coordinates = blockProtectorTileEntity.getProtectedBlocks();
                        if (!coordinates.isEmpty()) {
                            renderHighlightedBlocks(evt, p, new Coordinate(te.xCoord, te.yCoord, te.zCoord), coordinates);
                        }
                    }
                }
            }
        }
    } else if (heldItem.getItem() == ModItems.shapeCardItem) {
        int mode = ShapeCardItem.getMode(heldItem);
        if (mode == ShapeCardItem.MODE_CORNER1 || mode == ShapeCardItem.MODE_CORNER2) {
            GlobalCoordinate current = ShapeCardItem.getCurrentBlock(heldItem);
            if (current != null && current.getDimension() == mc.theWorld.provider.dimensionId) {
                Set<Coordinate> coordinates = new HashSet<Coordinate>();
                coordinates.add(new Coordinate(0, 0, 0));
                if (mode == ShapeCardItem.MODE_CORNER2) {
                    Coordinate cur = current.getCoordinate();
                    Coordinate c = ShapeCardItem.getCorner1(heldItem);
                    if (c != null) {
                        coordinates.add(new Coordinate(c.getX() - cur.getX(), c.getY() - cur.getY(), c.getZ() - cur.getZ()));
                    }
                }
                renderHighlightedBlocks(evt, p, current.getCoordinate(), coordinates);
            }
        }
    }
}
Also used : BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) Set(java.util.Set) HashSet(java.util.HashSet) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft)

Example 24 with GlobalCoordinate

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

the class ChargedPorterItem method startTeleport.

private void startTeleport(ItemStack stack, EntityPlayer player, World world) {
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound == null || (!tagCompound.hasKey("target")) || tagCompound.getInteger("target") == -1) {
        if (world.isRemote) {
            Logging.message(player, EnumChatFormatting.RED + "The charged porter has no target.");
        }
        return;
    }
    if (!world.isRemote) {
        IExtendedEntityProperties properties = player.getExtendedProperties(PlayerExtendedProperties.ID);
        PlayerExtendedProperties playerExtendedProperties = (PlayerExtendedProperties) properties;
        if (playerExtendedProperties.getPorterProperties().isTeleporting()) {
            Logging.message(player, EnumChatFormatting.RED + "Already teleporting!");
            return;
        }
        int target = tagCompound.getInteger("target");
        TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
        GlobalCoordinate coordinate = destinations.getCoordinateForId(target);
        if (coordinate == null) {
            Logging.message(player, EnumChatFormatting.RED + "Something went wrong! The target has disappeared!");
            TeleportationTools.applyEffectForSeverity(player, 3, false);
            return;
        }
        TeleportDestination destination = destinations.getDestination(coordinate);
        if (!TeleportationTools.checkValidTeleport(player, world.provider.dimensionId, destination.getDimension())) {
            return;
        }
        Coordinate playerCoordinate = new Coordinate((int) player.posX, (int) player.posY, (int) player.posZ);
        int cost = TeleportationTools.calculateRFCost(world, playerCoordinate, destination);
        cost *= 1.5f;
        int energy = getEnergyStored(stack);
        if (cost > energy) {
            Logging.message(player, EnumChatFormatting.RED + "Not enough energy to start the teleportation!");
            return;
        }
        extractEnergyNoMax(stack, cost, false);
        int ticks = TeleportationTools.calculateTime(world, playerCoordinate, destination);
        ticks /= getSpeedBonus();
        playerExtendedProperties.getPorterProperties().startTeleport(target, ticks);
        Logging.message(player, EnumChatFormatting.YELLOW + "Start teleportation!");
    }
}
Also used : PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IExtendedEntityProperties(net.minecraftforge.common.IExtendedEntityProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 25 with GlobalCoordinate

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

the class SmartWrenchItem method getCurrentBlock.

public static GlobalCoordinate getCurrentBlock(ItemStack itemStack) {
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound != null && tagCompound.hasKey("selectedX")) {
        int x = tagCompound.getInteger("selectedX");
        int y = tagCompound.getInteger("selectedY");
        int z = tagCompound.getInteger("selectedZ");
        int dim = tagCompound.getInteger("selectedDim");
        return new GlobalCoordinate(new Coordinate(x, y, z), dim);
    }
    return null;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

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