use of mcjty.lib.varia.BlockMeta in project RFToolsDimensions by McJty.
the class MapGenRuinedCities method createBlockMap.
private void createBlockMap() {
if (blockMap != null) {
return;
}
blockMap = new HashMap<Character, BlockMeta>();
blockMap.put(' ', null);
blockMap.put('B', new BlockMeta(ModBlocks.dimensionalBlock, 0));
blockMap.put('b', new BlockMeta(ModBlocks.dimensionalBlankBlock, 0));
blockMap.put('p', new BlockMeta(ModBlocks.dimensionalCrossBlock, 2));
blockMap.put('P', new BlockMeta(ModBlocks.dimensionalCrossBlock, 0));
blockMap.put('X', new BlockMeta(ModBlocks.dimensionalPattern1Block, 0));
blockMap.put('x', new BlockMeta(ModBlocks.dimensionalPattern2Block, 0));
blockMap.put('g', new BlockMeta(Blocks.stained_glass, 11));
}
use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.
the class BuilderTileEntity method consumeBlock.
private BlockMeta consumeBlock(Block block, int meta) {
TileEntity te = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
if (te instanceof IInventory) {
BlockMeta b = findAndConsumeBlock((IInventory) te, block, meta);
if (b != null) {
return b;
}
}
te = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if (te instanceof IInventory) {
BlockMeta b = findAndConsumeBlock((IInventory) te, block, meta);
if (b != null) {
return b;
}
}
// }
return null;
}
use of mcjty.lib.varia.BlockMeta 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.BlockMeta in project RFTools by McJty.
the class GuiChamberDetails method populateLists.
private void populateLists() {
blockList.removeChildren();
if (items == null) {
return;
}
int totalCost = 0;
for (Map.Entry<BlockMeta, Integer> entry : items.entrySet()) {
BlockMeta bm = entry.getKey();
int count = entry.getValue();
int cost = costs.get(bm);
Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout()).setDesiredHeight(16);
ItemStack stack = new ItemStack(bm.getBlock(), 0, bm.getMeta());
BlockRender blockRender = new BlockRender(mc, this).setRenderItem(stack).setOffsetX(-1).setOffsetY(-1);
Label nameLabel = new Label(mc, this).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setColor(StyleConfig.colorTextInListNormal);
if (stack.getItem() == null) {
nameLabel.setText("?").setDesiredWidth(160);
} else {
nameLabel.setText(stack.getDisplayName()).setDesiredWidth(160);
}
Label countLabel = new Label(mc, this).setText(String.valueOf(count)).setColor(StyleConfig.colorTextInListNormal);
countLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredWidth(50);
Label costLabel = new Label(mc, this).setColor(StyleConfig.colorTextInListNormal);
costLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
if (cost == -1) {
costLabel.setText("NOT MOVABLE!");
} else {
costLabel.setText("Move Cost " + cost + " RF");
totalCost += cost;
}
panel.addChild(blockRender).addChild(nameLabel).addChild(countLabel).addChild(costLabel);
blockList.addChild(panel);
}
int totalCostEntities = 0;
RenderHelper.rot += .5f;
for (Map.Entry<String, Integer> entry : entities.entrySet()) {
String className = entry.getKey();
Class<?> aClass = null;
try {
aClass = Class.forName(className);
} catch (ClassNotFoundException e) {
}
int count = entry.getValue();
int cost = entityCosts.get(className);
Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout()).setDesiredHeight(16);
Entity entity = null;
try {
entity = (Entity) aClass.getConstructor(World.class).newInstance(mc.theWorld);
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
}
BlockRender blockRender = new BlockRender(mc, this).setRenderItem(entity).setOffsetX(-1).setOffsetY(-1);
Label nameLabel = new Label(mc, this).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
nameLabel.setText(aClass.getSimpleName()).setDesiredWidth(160);
Label countLabel = new Label(mc, this).setText(String.valueOf(count));
countLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredWidth(50);
Label costLabel = new Label(mc, this);
costLabel.setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT);
if (cost == -1) {
costLabel.setText("NOT MOVABLE!");
} else {
costLabel.setText("Move Cost " + cost + " RF");
totalCostEntities += cost;
}
panel.addChild(blockRender).addChild(nameLabel).addChild(countLabel).addChild(costLabel);
blockList.addChild(panel);
}
infoLabel.setText("Total cost blocks: " + totalCost + " RF");
info2Label.setText("Total cost entities: " + totalCostEntities + " RF");
}
use of mcjty.lib.varia.BlockMeta in project RFTools by McJty.
the class PacketChamberInfoReady method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
blocks = new HashMap<BlockMeta, Integer>(size);
costs = new HashMap<BlockMeta, Integer>(size);
for (int i = 0; i < size; i++) {
int id = buf.readInt();
byte meta = buf.readByte();
int count = buf.readInt();
int cost = buf.readInt();
Block block = (Block) Block.blockRegistry.getObjectById(id);
BlockMeta bm = new BlockMeta(block, meta);
blocks.put(bm, count);
costs.put(bm, cost);
}
size = buf.readInt();
entities = new HashMap<String, Integer>(size);
entityCosts = new HashMap<String, Integer>(size);
for (int i = 0; i < size; i++) {
String className = NetworkTools.readString(buf);
int count = buf.readInt();
int cost = buf.readInt();
entities.put(className, count);
entityCosts.put(className, cost);
}
}
Aggregations