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);
}
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);
}
}
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);
}
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;
}
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!");
}
}
Aggregations