Search in sources :

Example 6 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class MultiblockControllerBase method checkStructurePattern.

protected void checkStructurePattern() {
    EnumFacing facing = getFrontFacing().getOpposite();
    PatternMatchContext context = structurePattern.checkPatternAt(getWorld(), getPos(), facing);
    if (context != null && !structureFormed) {
        Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
        ArrayList<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
        parts.sort(Comparator.comparing(it -> ((MetaTileEntity) it).getPos().hashCode()));
        for (IMultiblockPart part : parts) {
            if (part.isAttachedToMultiBlock()) {
                // stop here without attempting to register abilities
                return;
            }
        }
        Map<MultiblockAbility<Object>, List<Object>> abilities = new HashMap<>();
        for (IMultiblockPart multiblockPart : parts) {
            if (multiblockPart instanceof IMultiblockAbilityPart) {
                IMultiblockAbilityPart<Object> abilityPart = (IMultiblockAbilityPart<Object>) multiblockPart;
                List<Object> abilityInstancesList = abilities.computeIfAbsent(abilityPart.getAbility(), k -> new ArrayList<>());
                abilityPart.registerAbilities(abilityInstancesList);
            }
        }
        if (checkStructureComponents(parts, abilities)) {
            parts.forEach(part -> part.addToMultiBlock(this));
            this.multiblockParts.addAll(parts);
            this.multiblockAbilities.putAll(abilities);
            this.structureFormed = true;
            writeCustomData(400, buf -> buf.writeBoolean(true));
            formStructure(context);
        }
    } else if (context == null && structureFormed) {
        invalidateStructure();
    }
}
Also used : Matrix4(codechicken.lib.vec.Matrix4) Textures(gregtech.api.render.Textures) java.util(java.util) IPatternCenterPredicate(gregtech.api.multiblock.IPatternCenterPredicate) BiFunction(java.util.function.BiFunction) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) BlockWorldState(gregtech.api.multiblock.BlockWorldState) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Block(net.minecraft.block.Block) Pair(org.apache.commons.lang3.tuple.Pair) PatternMatchContext(gregtech.api.multiblock.PatternMatchContext) ICubeRenderer(gregtech.api.render.ICubeRenderer) OrientedOverlayRenderer(gregtech.api.render.OrientedOverlayRenderer) Nonnull(javax.annotation.Nonnull) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) CCRenderState(codechicken.lib.render.CCRenderState) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPattern(gregtech.api.multiblock.BlockPattern) TileEntity(net.minecraft.tileentity.TileEntity) GTUtility(gregtech.api.util.GTUtility) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) PacketBuffer(net.minecraft.network.PacketBuffer) EnumFacing(net.minecraft.util.EnumFacing) PatternMatchContext(gregtech.api.multiblock.PatternMatchContext)

Example 7 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity 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 8 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method getCollisionBox.

private List<IndexedCuboid6> getCollisionBox(IBlockAccess blockAccess, BlockPos pos) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(blockAccess, pos);
    if (metaTileEntity == null)
        return EMPTY_COLLISION_BOX;
    ArrayList<IndexedCuboid6> collisionList = new ArrayList<>();
    metaTileEntity.addCollisionBoundingBox(collisionList);
    metaTileEntity.addCoverCollisionBoundingBox(collisionList);
    return collisionList;
}
Also used : IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) ArrayList(java.util.ArrayList) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 9 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    if (metaTileEntity != null) {
        if (!metaTileEntity.keepsInventory()) {
            NonNullList<ItemStack> inventoryContents = NonNullList.create();
            metaTileEntity.clearMachineInventory(inventoryContents);
            for (ItemStack itemStack : inventoryContents) {
                Block.spawnAsEntity(worldIn, pos, itemStack);
            }
        }
        metaTileEntity.dropAllCovers();
        metaTileEntity.onRemoval();
        tileEntities.set(metaTileEntity);
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 10 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method rotateBlock.

@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
    if (metaTileEntity == null || !metaTileEntity.isValidFrontFacing(axis) || metaTileEntity.getFrontFacing() == axis || !metaTileEntity.hasFrontFacing())
        return false;
    metaTileEntity.setFrontFacing(axis);
    return true;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Aggregations

MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)25 IFastRenderMetaTileEntity (gregtech.api.metatileentity.IFastRenderMetaTileEntity)6 CCRenderState (codechicken.lib.render.CCRenderState)5 ItemStack (net.minecraft.item.ItemStack)5 Matrix4 (codechicken.lib.vec.Matrix4)4 IRenderMetaTileEntity (gregtech.api.metatileentity.IRenderMetaTileEntity)4 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ArrayList (java.util.ArrayList)3 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)2 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)2 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)2 ITieredMetaTileEntity (gregtech.api.metatileentity.ITieredMetaTileEntity)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Vector3 (codechicken.lib.vec.Vector3)1