use of gregtech.api.metatileentity.MetaTileEntityHolder in project GregTech by GregTechCE.
the class BlockMachine method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
MetaTileEntityHolder holder = (MetaTileEntityHolder) worldIn.getTileEntity(pos);
MetaTileEntity sampleMetaTileEntity = GregTechAPI.META_TILE_ENTITY_REGISTRY.getObjectById(stack.getItemDamage());
if (holder != null && sampleMetaTileEntity != null) {
MetaTileEntity metaTileEntity = holder.setMetaTileEntity(sampleMetaTileEntity);
if (stack.hasTagCompound()) {
metaTileEntity.initFromItemStackData(stack.getTagCompound());
}
EnumFacing placeFacing = placer.getHorizontalFacing().getOpposite();
if (metaTileEntity.isValidFrontFacing(placeFacing)) {
metaTileEntity.setFrontFacing(placeFacing);
}
}
}
use of gregtech.api.metatileentity.MetaTileEntityHolder in project GregTech by GregTechCE.
the class DebugPipeNetInfoProvider method addProbeInfo.
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
if (mode == ProbeMode.DEBUG && ConfigHolder.debug) {
TileEntity tileEntity = world.getTileEntity(data.getPos());
if (tileEntity instanceof MetaTileEntityHolder) {
MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
if (metaTileEntity != null) {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("MetaTileEntity Id: " + metaTileEntity.metaTileEntityId);
metaTileEntity.addDebugInfo(arrayList);
arrayList.forEach(probeInfo::text);
}
}
if (tileEntity instanceof TileEntityPipeBase) {
IPipeTile<?, ?> pipeTile = (IPipeTile<?, ?>) tileEntity;
BlockPipe<?, ?, ?> blockPipe = pipeTile.getPipeBlock();
PipeNet<?> pipeNet = blockPipe.getWorldPipeNet(world).getNetFromPos(data.getPos());
if (pipeNet != null) {
probeInfo.text("Net: " + pipeNet.hashCode());
probeInfo.text("Node Info: ");
StringBuilder builder = new StringBuilder();
Map<BlockPos, ? extends Node<?>> nodeMap = pipeNet.getAllNodes();
Node<?> node = nodeMap.get(data.getPos());
builder.append("{").append("active: ").append(node.isActive).append(", mark: ").append(node.mark).append(", blocked: ").append(node.blockedConnections).append("}");
probeInfo.text(builder.toString());
}
probeInfo.text("tile blocked: " + pipeTile.getBlockedConnections());
if (blockPipe instanceof BlockFluidPipe) {
if (pipeTile instanceof TileEntityFluidPipeTickable) {
probeInfo.text("tile active: " + ((TileEntityFluidPipeTickable) pipeTile).isActive());
}
}
}
}
}
use of gregtech.api.metatileentity.MetaTileEntityHolder in project GregTech by GregTechCE.
the class GTUtility method findPlayersUsing.
public static List<EntityPlayerMP> findPlayersUsing(MetaTileEntity metaTileEntity, double radius) {
ArrayList<EntityPlayerMP> result = new ArrayList<>();
AxisAlignedBB box = new AxisAlignedBB(metaTileEntity.getPos()).expand(radius, radius, radius).expand(-radius, -radius, -radius);
List<EntityPlayerMP> entities = metaTileEntity.getWorld().getEntitiesWithinAABB(EntityPlayerMP.class, box);
for (EntityPlayerMP player : entities) {
if (player.openContainer instanceof ModularUIContainer) {
ModularUI modularUI = ((ModularUIContainer) player.openContainer).getModularUI();
if (modularUI.holder instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) modularUI.holder).getMetaTileEntity() == metaTileEntity) {
result.add(player);
}
}
}
return result;
}
use of gregtech.api.metatileentity.MetaTileEntityHolder in project GregTech by GregTechCE.
the class LargeTurbineInfo method getMatchingShapes.
@Override
public List<MultiblockShapeInfo> getMatchingShapes() {
MetaTileEntityHolder holder = new MetaTileEntityHolder();
holder.setMetaTileEntity(MetaTileEntities.ROTOR_HOLDER[2]);
holder.getMetaTileEntity().setFrontFacing(EnumFacing.WEST);
ItemStack rotorStack = MetaItems.TURBINE_ROTOR.getStackForm();
// noinspection ConstantConditions
TurbineRotorBehavior.getInstanceFor(rotorStack).setPartMaterial(rotorStack, Materials.Darmstadtium);
((MetaTileEntityRotorHolder) holder.getMetaTileEntity()).getRotorInventory().setStackInSlot(0, rotorStack);
MultiblockShapeInfo.Builder shapeInfo = MultiblockShapeInfo.builder().aisle("CCCC", "CIOC", "CCCC").aisle("CCCC", "R##D", "CCCC").aisle("CCCC", "CSCC", "CCCC").where('S', turbine, EnumFacing.SOUTH).where('C', turbine.turbineType.casingState).where('R', new BlockInfo(MetaBlocks.MACHINE.getDefaultState(), holder)).where('D', MetaTileEntities.ENERGY_OUTPUT_HATCH[GTValues.EV], EnumFacing.EAST).where('#', Blocks.AIR.getDefaultState()).where('I', MetaTileEntities.FLUID_IMPORT_HATCH[GTValues.HV], EnumFacing.NORTH);
if (turbine.turbineType.hasOutputHatch) {
shapeInfo.where('O', MetaTileEntities.FLUID_EXPORT_HATCH[GTValues.EV], EnumFacing.NORTH);
} else {
shapeInfo.where('O', turbine.turbineType.casingState);
}
return Lists.newArrayList(shapeInfo.build());
}
use of gregtech.api.metatileentity.MetaTileEntityHolder in project GregTech by GregTechCE.
the class TransformerInfoProvider method addProbeInfo.
@Override
protected void addProbeInfo(IEnergyContainer capability, IProbeInfo probeInfo, TileEntity tileEntity, EnumFacing sideHit) {
if (tileEntity instanceof MetaTileEntityHolder) {
MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
if (metaTileEntity instanceof MetaTileEntityTransformer) {
MetaTileEntityTransformer mteTransformer = (MetaTileEntityTransformer) metaTileEntity;
String inputVoltageN = GTValues.VN[GTUtility.getTierByVoltage(capability.getInputVoltage())];
String outputVoltageN = GTValues.VN[GTUtility.getTierByVoltage(capability.getOutputVoltage())];
long inputAmperage = capability.getInputAmperage();
long outputAmperage = capability.getOutputAmperage();
IProbeInfo horizontalPane = probeInfo.vertical(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
String transformInfo;
// Step Up/Step Down line
if (mteTransformer.isInverted()) {
transformInfo = "{*gregtech.top.transform_up*} ";
} else {
transformInfo = "{*gregtech.top.transform_down*} ";
}
transformInfo += inputVoltageN + " (" + inputAmperage + "A) -> " + outputVoltageN + " (" + outputAmperage + "A)";
horizontalPane.text(TextStyleClass.INFO + transformInfo);
// Input/Output side line
horizontalPane = probeInfo.vertical(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
if (capability.inputsEnergy(sideHit)) {
transformInfo = "{*gregtech.top.transform_input*} " + inputVoltageN + " (" + inputAmperage + "A)";
horizontalPane.text(TextStyleClass.INFO + transformInfo);
} else if (capability.outputsEnergy(sideHit)) {
transformInfo = "{*gregtech.top.transform_output*} " + outputVoltageN + " (" + outputAmperage + "A)";
horizontalPane.text(TextStyleClass.INFO + transformInfo);
}
}
}
}
Aggregations