Search in sources :

Example 1 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class MachineSceneWidget method updateScene.

private void updateScene() {
    if (!mte.isValid())
        return;
    World world = mte.getWorld();
    if (worldSceneRenderer != null) {
        worldSceneRenderer.releaseFBO();
    }
    worldSceneRenderer = new FBOWorldSceneRenderer(world, 1080, 1080);
    worldSceneRenderer.setAfterWorldRender(this::renderBlockOverLay);
    cores = new HashSet<>();
    around = new HashSet<>();
    cores.add(pos);
    if (mte instanceof MultiblockControllerBase) {
        PatternMatchContext context = ((MultiblockControllerBase) mte).structurePattern.checkPatternFastAt(world, pos, mte.getFrontFacing().getOpposite());
        if (context != null) {
            List<BlockPos> validPos = ((MultiblockControllerBase) mte).structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toList());
            Set<IMultiblockPart> parts = context.getOrCreate("MultiblockParts", HashSet::new);
            for (IMultiblockPart part : parts) {
                if (part instanceof MetaTileEntity) {
                    cores.add(((MetaTileEntity) part).getPos());
                }
            }
            for (EnumFacing facing : EnumFacing.VALUES) {
                cores.forEach(pos -> around.add(pos.offset(facing)));
            }
            int minX = Integer.MAX_VALUE;
            int minY = Integer.MAX_VALUE;
            int minZ = Integer.MAX_VALUE;
            int maxX = Integer.MIN_VALUE;
            int maxY = Integer.MIN_VALUE;
            int maxZ = Integer.MIN_VALUE;
            for (BlockPos vPos : validPos) {
                around.add(vPos);
                minX = Math.min(minX, vPos.getX());
                minY = Math.min(minY, vPos.getY());
                minZ = Math.min(minZ, vPos.getZ());
                maxX = Math.max(maxX, vPos.getX());
                maxY = Math.max(maxY, vPos.getY());
                maxZ = Math.max(maxZ, vPos.getZ());
            }
            around.removeAll(cores);
            center = new Vector3f((minX + maxX) / 2f, (minY + maxY) / 2f, (minZ + maxZ) / 2f);
        } else {
            for (EnumFacing facing : EnumFacing.VALUES) {
                around.add(pos.offset(facing));
            }
            center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
        }
    } else {
        for (EnumFacing facing : EnumFacing.VALUES) {
            around.add(pos.offset(facing));
        }
        center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
    }
    worldSceneRenderer.addRenderedBlocks(cores, null);
    worldSceneRenderer.addRenderedBlocks(around, this::aroundBlocksRenderHook);
    worldSceneRenderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
Also used : FBOWorldSceneRenderer(gregtech.client.renderer.scene.FBOWorldSceneRenderer) EnumFacing(net.minecraft.util.EnumFacing) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) World(net.minecraft.world.World) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) Vector3f(javax.vecmath.Vector3f) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 2 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class CoverDigitalInterface method getFluidCapability.

public IFluidHandler getFluidCapability() {
    TileEntity te = getCoveredTE();
    IFluidHandler capability = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getCoveredFacing());
    if (capability == null && this.coverHolder instanceof MultiblockControllerBase) {
        List<IFluidTank> input = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.IMPORT_FLUIDS);
        List<IFluidTank> output = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.EXPORT_FLUIDS);
        List<IFluidTank> list = new ArrayList<>();
        if (input.size() > 0) {
            list.addAll(input);
        }
        if (output.size() > 0) {
            list.addAll(output);
        }
        capability = new FluidTankList(true, list);
    }
    return capability;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 3 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class CoverDigitalInterface method getEnergyCapability.

public IEnergyContainer getEnergyCapability() {
    TileEntity te = getCoveredTE();
    IEnergyContainer capability = te == null ? null : te.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, getCoveredFacing());
    if (capability == null && this.coverHolder instanceof MultiblockControllerBase) {
        List<IEnergyContainer> input = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.INPUT_ENERGY);
        List<IEnergyContainer> output = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.OUTPUT_ENERGY);
        List<IEnergyContainer> list = new ArrayList<>();
        if (input.size() > 0) {
            list.addAll(input);
        }
        if (output.size() > 0) {
            list.addAll(output);
        }
        capability = new EnergyContainerList(list);
    } else if (capability == null && te != null) {
        IEnergyStorage fe = te.getCapability(CapabilityEnergy.ENERGY, getCoveredFacing());
        if (fe != null) {
            return new IEnergyContainer() {

                public long acceptEnergyFromNetwork(EnumFacing enumFacing, long l, long l1) {
                    return 0;
                }

                public boolean inputsEnergy(EnumFacing enumFacing) {
                    return false;
                }

                public long changeEnergy(long l) {
                    return 0;
                }

                public long getEnergyStored() {
                    return FeCompat.toEu(fe.getEnergyStored(), FeCompat.ratio(false));
                }

                public long getEnergyCapacity() {
                    return FeCompat.toEu(fe.getMaxEnergyStored(), FeCompat.ratio(false));
                }

                public long getInputAmperage() {
                    return 0;
                }

                public long getInputVoltage() {
                    return 0;
                }
            };
        }
    }
    return capability;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) ArrayList(java.util.ArrayList) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage)

Example 4 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class FakeGuiPluginBehavior method getRealMTE.

public MetaTileEntity getRealMTE() {
    MetaTileEntity target = this.holder.getMetaTileEntity();
    if (target instanceof MultiblockControllerBase && partIndex > 0) {
        if (partPos != null) {
            TileEntity entity = this.screen.getWorld().getTileEntity(partPos);
            if (entity instanceof MetaTileEntityHolder) {
                return ((MetaTileEntityHolder) entity).getMetaTileEntity();
            } else {
                partPos = null;
                return null;
            }
        }
        PatternMatchContext context = ((MultiblockControllerBase) target).structurePattern.checkPatternFastAt(target.getWorld(), target.getPos(), target.getFrontFacing().getOpposite());
        if (context == null) {
            return null;
        }
        Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
        List<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
        parts.sort(Comparator.comparing((it) -> ((MetaTileEntity) it).getPos().hashCode()));
        if (parts.size() > partIndex - 1 && parts.get(partIndex - 1) instanceof MetaTileEntity) {
            target = (MetaTileEntity) parts.get(partIndex - 1);
            partPos = target.getPos();
        } else {
            return null;
        }
    }
    return target;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) java.util(java.util) FakeModularGui(gregtech.api.gui.impl.FakeModularGui) EnumHand(net.minecraft.util.EnumHand) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerMainInvWrapper(net.minecraftforge.items.wrapper.PlayerMainInvWrapper) RayTraceResult(net.minecraft.util.math.RayTraceResult) Widget(gregtech.api.gui.Widget) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior) IUIHolder(gregtech.api.gui.IUIHolder) gregtech.api.gui.widgets(gregtech.api.gui.widgets) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) Side(net.minecraftforge.fml.relauncher.Side) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) GregtechDataCodes(gregtech.api.capability.GregtechDataCodes) Method(java.lang.reflect.Method) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) WidgetPluginConfig(gregtech.common.gui.widget.monitor.WidgetPluginConfig) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) GTLog(gregtech.api.util.GTLog) ProxyHolderPluginBehavior(gregtech.api.items.behavior.ProxyHolderPluginBehavior) GlStateManager(net.minecraft.client.renderer.GlStateManager) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) GuiTextures(gregtech.api.gui.GuiTextures) FakeModularUIPluginContainer(gregtech.common.gui.impl.FakeModularUIPluginContainer) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) GregFakePlayer(gregtech.api.util.GregFakePlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) ModularUI(gregtech.api.gui.ModularUI) TileEntity(net.minecraft.tileentity.TileEntity) PacketBuffer(net.minecraft.network.PacketBuffer) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) PatternMatchContext(gregtech.api.pattern.PatternMatchContext)

Example 5 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method checkLookingAt.

@SideOnly(Side.CLIENT)
public double[] checkLookingAt(RayTraceResult rayTraceResult) {
    if (this.getWorld() != null) {
        MultiblockControllerBase controller = this.getController();
        if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && controller != null && rayTraceResult.sideHit == controller.getFrontFacing()) {
            int i, j;
            TileEntity tileEntity = this.getWorld().getTileEntity(rayTraceResult.getBlockPos());
            if (tileEntity instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) tileEntity).getMetaTileEntity() instanceof MetaTileEntityMonitorScreen) {
                MetaTileEntityMonitorScreen screenHit = (MetaTileEntityMonitorScreen) ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
                if (controller == screenHit.getController()) {
                    i = ((MetaTileEntityMonitorScreen) ((MetaTileEntityHolder) tileEntity).getMetaTileEntity()).getX() - this.getX();
                    j = ((MetaTileEntityMonitorScreen) ((MetaTileEntityHolder) tileEntity).getMetaTileEntity()).getY() - this.getY();
                    double[] pos = handleRayTraceResult(rayTraceResult);
                    if ((i >= 0 && j >= 0)) {
                        pos[0] = (pos[0] + i) / this.scale;
                        pos[1] = (pos[1] + j) / this.scale;
                        if (pos[0] >= 0 && pos[0] <= 1 && pos[1] >= 0 && pos[1] <= 1)
                            return new double[] { pos[0], pos[1] };
                    }
                }
            }
        }
    }
    return null;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)22 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)11 TileEntity (net.minecraft.tileentity.TileEntity)10 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)9 BlockPos (net.minecraft.util.math.BlockPos)7 World (net.minecraft.world.World)7 EnumFacing (net.minecraft.util.EnumFacing)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 java.util (java.util)4 IBlockState (net.minecraft.block.state.IBlockState)4 GlStateManager (net.minecraft.client.renderer.GlStateManager)4 ItemStack (net.minecraft.item.ItemStack)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4 Side (net.minecraftforge.fml.relauncher.Side)4 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)3 MonitorPluginBaseBehavior (gregtech.api.items.behavior.MonitorPluginBaseBehavior)3 ProxyHolderPluginBehavior (gregtech.api.items.behavior.ProxyHolderPluginBehavior)3 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)3 BlockInfo (gregtech.api.util.BlockInfo)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3