Search in sources :

Example 16 with Coordinate

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

the class PacketGetChamberInfo method onMessage.

@Override
public PacketChamberInfoReady onMessage(PacketGetChamberInfo message, MessageContext ctx) {
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    ItemStack cardItem = player.getHeldItem();
    if (cardItem == null || cardItem.getTagCompound() == null) {
        return null;
    }
    int channel = cardItem.getTagCompound().getInteger("channel");
    if (channel == -1) {
        return null;
    }
    SpaceChamberRepository repository = SpaceChamberRepository.getChannels(player.worldObj);
    SpaceChamberRepository.SpaceChamberChannel chamberChannel = repository.getChannel(channel);
    if (chamberChannel == null) {
        return null;
    }
    int dimension = chamberChannel.getDimension();
    World world = DimensionManager.getWorld(dimension);
    if (world == null) {
        return null;
    }
    Counter<BlockMeta> blocks = new Counter<BlockMeta>();
    Counter<BlockMeta> costs = new Counter<BlockMeta>();
    Coordinate minCorner = chamberChannel.getMinCorner();
    Coordinate maxCorner = chamberChannel.getMaxCorner();
    for (int x = minCorner.getX(); x <= maxCorner.getX(); x++) {
        for (int y = minCorner.getY(); y <= maxCorner.getY(); y++) {
            for (int z = minCorner.getZ(); z <= maxCorner.getZ(); z++) {
                Block block = world.getBlock(x, y, z);
                if (!BuilderTileEntity.isEmpty(block)) {
                    int meta = world.getBlockMetadata(x, y, z);
                    BlockMeta bm = new BlockMeta(block, meta);
                    blocks.increment(bm);
                    TileEntity te = world.getTileEntity(x, y, z);
                    SpaceProjectorSetup.BlockInformation info = BuilderTileEntity.getBlockInformation(world, x, y, z, block, te);
                    if (info.getBlockLevel() == SupportBlock.STATUS_ERROR) {
                        costs.put(bm, -1);
                    } else {
                        costs.increment(bm, (int) (SpaceProjectorConfiguration.builderRfPerOperation * info.getCostFactor()));
                    }
                }
            }
        }
    }
    Counter<String> entitiesWithCount = new Counter<String>();
    Counter<String> entitiesWithCost = new Counter<String>();
    List entities = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(minCorner.getX(), minCorner.getY(), minCorner.getZ(), maxCorner.getX() + 1, maxCorner.getY() + 1, maxCorner.getZ() + 1));
    for (Object o : entities) {
        Entity entity = (Entity) o;
        String canonicalName = entity.getClass().getCanonicalName();
        entitiesWithCount.increment(canonicalName);
        if (entity instanceof EntityPlayer) {
            entitiesWithCost.increment(canonicalName, SpaceProjectorConfiguration.builderRfPerPlayer);
        } else {
            entitiesWithCost.increment(canonicalName, SpaceProjectorConfiguration.builderRfPerEntity);
        }
    }
    return new PacketChamberInfoReady(blocks, costs, entitiesWithCount, entitiesWithCost);
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) Counter(mcjty.lib.varia.Counter) Coordinate(mcjty.lib.varia.Coordinate) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) BlockMeta(mcjty.lib.varia.BlockMeta)

Example 17 with Coordinate

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

the class MatterBeamerRenderer method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
    ResourceLocation txt;
    boolean blending = GL11.glIsEnabled(GL11.GL_BLEND);
    Tessellator tessellator = Tessellator.instance;
    MatterBeamerTileEntity matterBeamerTileEntity = (MatterBeamerTileEntity) tileEntity;
    Coordinate destination = matterBeamerTileEntity.getDestination();
    if (destination != null) {
        int meta = tileEntity.getWorldObj().getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
        if ((meta & BlockTools.MASK_REDSTONE) != 0) {
            tessellator.startDrawingQuads();
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
            tessellator.setColorRGBA(255, 255, 255, 128);
            tessellator.setBrightness(240);
            GL11.glPushMatrix();
            this.bindTexture(redglow);
            Minecraft mc = Minecraft.getMinecraft();
            EntityClientPlayerMP p = mc.thePlayer;
            double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * f;
            double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * f;
            double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * f;
            GL11.glTranslated(-doubleX, -doubleY, -doubleZ);
            RenderHelper.Vector start = new RenderHelper.Vector(tileEntity.xCoord + .5f, tileEntity.yCoord + .5f, tileEntity.zCoord + .5f);
            RenderHelper.Vector end = new RenderHelper.Vector(destination.getX() + .5f, destination.getY() + .5f, destination.getZ() + .5f);
            RenderHelper.Vector player = new RenderHelper.Vector((float) doubleX, (float) doubleY, (float) doubleZ);
            RenderHelper.drawBeam(start, end, player, (meta & 1) != 0 ? .1f : .05f);
            tessellator.draw();
            GL11.glPopMatrix();
        }
    }
    Coordinate coord = new Coordinate(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
    if (coord.equals(RFTools.instance.clientInfo.getSelectedTE())) {
        txt = redglow;
    } else if (coord.equals(RFTools.instance.clientInfo.getDestinationTE())) {
        txt = blueglow;
    } else {
        txt = null;
    }
    if (txt != null) {
        this.bindTexture(txt);
        GL11.glPushMatrix();
        GL11.glTranslated(x, y, z);
        tessellator.startDrawingQuads();
        tessellator.setColorRGBA(255, 255, 255, 128);
        tessellator.setBrightness(240);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.UP.ordinal(), 1.1f, -0.05f);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.DOWN.ordinal(), 1.1f, -0.05f);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.NORTH.ordinal(), 1.1f, -0.05f);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.SOUTH.ordinal(), 1.1f, -0.05f);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.WEST.ordinal(), 1.1f, -0.05f);
        DefaultISBRH.addSideFullTexture(tessellator, ForgeDirection.EAST.ordinal(), 1.1f, -0.05f);
        tessellator.draw();
        GL11.glPopMatrix();
    }
    if (!blending) {
        GL11.glDisable(GL11.GL_BLEND);
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) RenderHelper(mcjty.lib.gui.RenderHelper) Coordinate(mcjty.lib.varia.Coordinate) ResourceLocation(net.minecraft.util.ResourceLocation) Minecraft(net.minecraft.client.Minecraft)

Example 18 with Coordinate

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

the class SpawnerTileEntity method useWrench.

// private int countEntitiesWithinAABB(AxisAlignedBB aabb) {
// int i = MathHelper.floor_double((aabb.minX - World.MAX_ENTITY_RADIUS) / 16.0D);
// int j = MathHelper.floor_double((aabb.maxX + World.MAX_ENTITY_RADIUS) / 16.0D);
// int k = MathHelper.floor_double((aabb.minZ - World.MAX_ENTITY_RADIUS) / 16.0D);
// int l = MathHelper.floor_double((aabb.maxZ + World.MAX_ENTITY_RADIUS) / 16.0D);
// 
// int cnt = 0;
// for (int i1 = i; i1 <= j; ++i1) {
// for (int j1 = k; j1 <= l; ++j1) {
// if (worldObj.getChunkProvider().chunkExists(i1, j1)) {
// cnt += countEntitiesWithinChunkAABB(worldObj.getChunkFromChunkCoords(i1, j1), aabb);
// }
// }
// }
// return cnt;
// }
// 
// private int countEntitiesWithinChunkAABB(Chunk chunk, AxisAlignedBB aabb) {
// int cnt = 0;
// int i = MathHelper.floor_double((aabb.minY - World.MAX_ENTITY_RADIUS) / 16.0D);
// int j = MathHelper.floor_double((aabb.maxY + World.MAX_ENTITY_RADIUS) / 16.0D);
// i = MathHelper.clamp_int(i, 0, chunk.entityLists.length - 1);
// j = MathHelper.clamp_int(j, 0, chunk.entityLists.length - 1);
// 
// for (int k = i; k <= j; ++k) {
// List entityList = chunk.entityLists[k];
// cnt += entityList.size();
// }
// return cnt;
// }
// 
// 
// Called from client side when a wrench is used.
public void useWrench(EntityPlayer player) {
    Coordinate coord = RFTools.instance.clientInfo.getSelectedTE();
    if (coord == null) {
        // Nothing to do.
        return;
    }
    Coordinate thisCoord = new Coordinate(xCoord, yCoord, zCoord);
    TileEntity tileEntity = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
    double d = Vec3.createVectorHelper(coord.getX(), coord.getY(), coord.getZ()).distanceTo(Vec3.createVectorHelper(xCoord, yCoord, zCoord));
    if (d > SpawnerConfiguration.maxBeamDistance) {
        Logging.message(player, "Destination distance is too far!");
    } else if (tileEntity instanceof MatterBeamerTileEntity) {
        MatterBeamerTileEntity matterBeamerTileEntity = (MatterBeamerTileEntity) tileEntity;
        matterBeamerTileEntity.setDestination(thisCoord);
        Logging.message(player, "Destination set!");
    }
    RFTools.instance.clientInfo.setSelectedTE(null);
    RFTools.instance.clientInfo.setDestinationTE(null);
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Coordinate(mcjty.lib.varia.Coordinate)

Example 19 with Coordinate

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

the class ProxyBlock method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float sidex, float sidey, float sidez) {
    if (!world.isRemote) {
        ProxyBlockTileEntity proxyBlockTileEntity = (ProxyBlockTileEntity) world.getTileEntity(x, y, z);
        final Coordinate oc = proxyBlockTileEntity.getOrigCoordinate();
        int dim = proxyBlockTileEntity.getDimension();
        final WorldServer w = DimensionManager.getWorld(dim);
        final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
        // FakePlayer fakePlayer = FakePlayerFactory.getMinecraft(w);
        FakePlayer fakePlayer = new FakePlayer(w, new GameProfile(UUID.fromString("41C82C87-7AfB-4024-BA57-13D2C99CAE77"), "[Minecraft]")) {

            @Override
            public void openGui(Object mod, int modGuiId, World world, int x, int y, int z) {
                entityPlayerMP.openGui(mod, modGuiId, w, oc.getX(), oc.getY(), oc.getZ());
            }
        };
        fakePlayer.getPlayerCoordinates().posX = oc.getX();
        fakePlayer.getPlayerCoordinates().posY = oc.getY();
        fakePlayer.getPlayerCoordinates().posZ = oc.getZ();
        fakePlayer.playerNetServerHandler = entityPlayerMP.playerNetServerHandler;
        fakePlayer.inventory = entityPlayerMP.inventory;
        fakePlayer.dimension = dim;
        // World oldWorld = entityPlayerMP.worldObj;
        // int oldPosX = entityPlayerMP.getPlayerCoordinates().posX;
        // int oldPosY = entityPlayerMP.getPlayerCoordinates().posY;
        // int oldPosZ = entityPlayerMP.getPlayerCoordinates().posZ;
        // entityPlayerMP.worldObj = w;
        // entityPlayerMP.getPlayerCoordinates().posX = oc.getX();
        // entityPlayerMP.getPlayerCoordinates().posY = oc.getY();
        // entityPlayerMP.getPlayerCoordinates().posZ = oc.getZ();
        entityPlayerMP.theItemInWorldManager.activateBlockOrUseItem(fakePlayer, w, null, oc.getX(), oc.getY(), oc.getZ(), side, sidex, sidey, sidez);
    // entityPlayerMP.worldObj = oldWorld;
    // entityPlayerMP.getPlayerCoordinates().posX = oldPosX;
    // entityPlayerMP.getPlayerCoordinates().posY = oldPosY;
    // entityPlayerMP.getPlayerCoordinates().posZ = oldPosZ;
    }
    return true;
}
Also used : Coordinate(mcjty.lib.varia.Coordinate) GameProfile(com.mojang.authlib.GameProfile) WorldServer(net.minecraft.world.WorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) World(net.minecraft.world.World) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 20 with Coordinate

use of mcjty.lib.varia.Coordinate 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)

Aggregations

Coordinate (mcjty.lib.varia.Coordinate)181 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)63 TileEntity (net.minecraft.tileentity.TileEntity)30 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)19 Block (net.minecraft.block.Block)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)13 World (net.minecraft.world.World)12 NBTTagList (net.minecraft.nbt.NBTTagList)11 Callback (li.cil.oc.api.machine.Callback)10 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)10 Panel (mcjty.lib.gui.widgets.Panel)10 ItemStack (net.minecraft.item.ItemStack)10 ArrayList (java.util.ArrayList)9 Label (mcjty.lib.gui.widgets.Label)8 BlockInfo (mcjty.rftools.BlockInfo)7 SyncedCoordinate (mcjty.lib.entity.SyncedCoordinate)5 ChoiceEvent (mcjty.lib.gui.events.ChoiceEvent)4 TeleportDestinationClientInfo (mcjty.rftools.blocks.teleporter.TeleportDestinationClientInfo)4