Search in sources :

Example 11 with MultiblockControllerBase

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

the class MetaTileEntityMultiblockPart method onRemoval.

@Override
public void onRemoval() {
    super.onRemoval();
    MultiblockControllerBase controller = getController();
    if (!getWorld().isRemote && controller != null) {
        controller.invalidateStructure();
    }
}
Also used : MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase)

Example 12 with MultiblockControllerBase

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

the class MetaTileEntityMultiblockPart method writeInitialSyncData.

@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    MultiblockControllerBase controller = getController();
    buf.writeBoolean(controller != null);
    if (controller != null) {
        buf.writeBlockPos(controller.getPos());
    }
}
Also used : MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase)

Example 13 with MultiblockControllerBase

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

the class IParallelableRecipeLogicTest method initEBF.

private MetaTileEntityElectricBlastFurnace initEBF(int id) {
    World world = DummyWorld.INSTANCE;
    mbt = MetaTileEntities.registerMetaTileEntity(id, new MetaTileEntityElectricBlastFurnace(// super function calls the world, which equal null in test
    new ResourceLocation(GTValues.MODID, "electric_blast_furnace")) {

        @Override
        public boolean canBeDistinct() {
            return false;
        }

        @Override
        public void reinitializeStructurePattern() {
        }

        // function checks for the temperature of the recipe against the coils
        @Override
        public boolean checkRecipe(@Nonnull Recipe recipe, boolean consumeIfSuccess) {
            return true;
        }

        // ignore maintenance problems
        @Override
        public boolean hasMaintenanceMechanics() {
            return false;
        }
    });
    try {
        Field field = MetaTileEntityElectricBlastFurnace.class.getSuperclass().getDeclaredField("recipeMapWorkable");
        field.setAccessible(true);
        Object recipeMapWorkableField = field.get(mbt);
        Method setParallelLimitMethod = recipeMapWorkableField.getClass().getSuperclass().getSuperclass().getDeclaredMethod("setParallelLimit", int.class);
        setParallelLimitMethod.setAccessible(true);
        setParallelLimitMethod.invoke(recipeMapWorkableField, 4);
    } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        e.printStackTrace();
    }
    // isValid() check in the dirtying logic requires both a metatileentity and a holder
    try {
        Field field = MetaTileEntity.class.getDeclaredField("holder");
        field.setAccessible(true);
        field.set(mbt, new MetaTileEntityHolder());
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    try {
        Field field = MetaTileEntityHolder.class.getDeclaredField("metaTileEntity");
        field.setAccessible(true);
        field.set(mbt.getHolder(), mbt);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    mbt.getHolder().setWorld(world);
    // Controller and isAttachedToMultiBlock need the world so we fake it here.
    importItemBus = new MetaTileEntityItemBus(gregtechId("item_bus.export.lv"), 1, false) {

        @Override
        public boolean isAttachedToMultiBlock() {
            return true;
        }

        @Override
        public MultiblockControllerBase getController() {
            return mbt;
        }
    };
    exportItemBus = new MetaTileEntityItemBus(gregtechId("item_bus.export.lv"), 1, true) {

        @Override
        public boolean isAttachedToMultiBlock() {
            return true;
        }

        @Override
        public MultiblockControllerBase getController() {
            return mbt;
        }
    };
    importFluidBus = new MetaTileEntityFluidHatch(gregtechId("fluid_hatch.import.lv"), 1, false) {

        @Override
        public boolean isAttachedToMultiBlock() {
            return true;
        }

        @Override
        public MultiblockControllerBase getController() {
            return mbt;
        }
    };
    exportFluidBus = new MetaTileEntityFluidHatch(gregtechId("fluid_hatch.export.lv"), 1, true) {

        @Override
        public boolean isAttachedToMultiBlock() {
            return true;
        }

        @Override
        public MultiblockControllerBase getController() {
            return mbt;
        }
    };
    // Controller is a private field but we need that information
    try {
        Field field = MetaTileEntityMultiblockPart.class.getDeclaredField("controllerTile");
        field.setAccessible(true);
        field.set(importItemBus, mbt);
        field.set(exportItemBus, mbt);
        field.set(importFluidBus, mbt);
        field.set(exportFluidBus, mbt);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return (MetaTileEntityElectricBlastFurnace) mbt;
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) Nonnull(javax.annotation.Nonnull) Recipe(gregtech.api.recipes.Recipe) MetaTileEntityFluidHatch(gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityFluidHatch) Method(java.lang.reflect.Method) DummyWorld(gregtech.api.util.world.DummyWorld) World(net.minecraft.world.World) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) MetaTileEntityElectricBlastFurnace(gregtech.common.metatileentities.multi.electric.MetaTileEntityElectricBlastFurnace) ResourceLocation(net.minecraft.util.ResourceLocation) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntityItemBus(gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityItemBus)

Example 14 with MultiblockControllerBase

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

the class CoverDigitalInterface method getItemCapability.

public IItemHandler getItemCapability() {
    TileEntity te = getCoveredTE();
    IItemHandler capability = te == null ? null : te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getCoveredFacing());
    if (capability == null && this.coverHolder instanceof MultiblockControllerBase) {
        List<IItemHandlerModifiable> input = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.IMPORT_ITEMS);
        List<IItemHandlerModifiable> output = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.EXPORT_ITEMS);
        List<IItemHandlerModifiable> list = new ArrayList<>();
        if (input.size() > 0) {
            list.addAll(input);
        }
        if (output.size() > 0) {
            list.addAll(output);
        }
        capability = new ItemHandlerList(list);
    }
    return capability;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) ArrayList(java.util.ArrayList)

Example 15 with MultiblockControllerBase

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

the class MetaTileEntityMonitorScreen method onRightClick.

@Override
public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) {
    if (!(!playerIn.isSneaking() && playerIn.getHeldItemMainhand().hasCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null)) && !MetaTileEntities.MONITOR_SCREEN.getStackForm().isItemEqual(playerIn.getHeldItemMainhand())) {
        if (playerIn.world.getTotalWorldTime() - lastClickTime < 2 && playerIn.getPersistentID().equals(lastClickUUID)) {
            return true;
        }
        lastClickTime = playerIn.world.getTotalWorldTime();
        lastClickUUID = playerIn.getPersistentID();
        MultiblockControllerBase controller = this.getController();
        if (controller instanceof MetaTileEntityCentralMonitor && ((MetaTileEntityCentralMonitor) controller).isActive() && controller.getFrontFacing() == facing) {
            return handleHitResultWithScale(playerIn, hand, facing, true, hitResult);
        }
    }
    return false;
}
Also used : MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase)

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