Search in sources :

Example 1 with MetaTileEntityHolder

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);
        }
    }
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 2 with MetaTileEntityHolder

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());
                }
            }
        }
    }
}
Also used : IPipeTile(gregtech.api.pipenet.tile.IPipeTile) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) ArrayList(java.util.ArrayList) BlockFluidPipe(gregtech.common.pipelike.fluidpipe.BlockFluidPipe) TileEntityFluidPipeTickable(gregtech.common.pipelike.fluidpipe.tile.TileEntityFluidPipeTickable) TileEntityPipeBase(gregtech.api.pipenet.tile.TileEntityPipeBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with MetaTileEntityHolder

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;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) ModularUI(gregtech.api.gui.ModularUI) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 4 with MetaTileEntityHolder

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());
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) BlockInfo(gregtech.api.util.BlockInfo) MultiblockShapeInfo(gregtech.integration.jei.multiblock.MultiblockShapeInfo) ItemStack(net.minecraft.item.ItemStack)

Example 5 with MetaTileEntityHolder

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);
            }
        }
    }
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MetaTileEntityTransformer(gregtech.common.metatileentities.electric.MetaTileEntityTransformer) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IProbeInfo(mcjty.theoneprobe.api.IProbeInfo)

Aggregations

MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)6 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)3 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ModularUI (gregtech.api.gui.ModularUI)1 ModularUIContainer (gregtech.api.gui.impl.ModularUIContainer)1 IPipeTile (gregtech.api.pipenet.tile.IPipeTile)1 TileEntityPipeBase (gregtech.api.pipenet.tile.TileEntityPipeBase)1 BlockInfo (gregtech.api.util.BlockInfo)1 MetaTileEntityTransformer (gregtech.common.metatileentities.electric.MetaTileEntityTransformer)1 BlockFluidPipe (gregtech.common.pipelike.fluidpipe.BlockFluidPipe)1 TileEntityFluidPipeTickable (gregtech.common.pipelike.fluidpipe.tile.TileEntityFluidPipeTickable)1 MultiblockShapeInfo (gregtech.integration.jei.multiblock.MultiblockShapeInfo)1 ArrayList (java.util.ArrayList)1 IProbeInfo (mcjty.theoneprobe.api.IProbeInfo)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1