Search in sources :

Example 1 with CoverStack

use of muramasa.antimatter.cover.CoverStack in project GT-4-Reimagined by Trinsdar.

the class CoverConveyor method onUpdate.

@Override
public void onUpdate(CoverStack<?> instance, Direction side) {
    if (instance.getTile() == null || instance.getTile().getWorld().getGameTime() % (speeds.get(tier)) != 0)
        return;
    boolean isMachine = instance.getTile() instanceof TileEntityMachine;
    BlockState state = instance.getTile().getWorld().getBlockState(instance.getTile().getPos().offset(side));
    // Drop into world.
    if (state == Blocks.AIR.getDefaultState() && isMachine) {
        World world = instance.getTile().getWorld();
        BlockPos pos = instance.getTile().getPos();
        ItemStack stack = ((TileEntityMachine) instance.getTile()).itemHandler.map(ih -> Utils.extractAny(ih.getOutputHandler())).orElse(ItemStack.EMPTY);
        if (stack.isEmpty())
            return;
        world.addEntity(new ItemEntity(world, pos.getX() + side.getXOffset(), pos.getY() + side.getYOffset(), pos.getZ() + side.getZOffset(), stack));
    }
    if (!(state.hasTileEntity()))
        return;
    TileEntity adjTile = instance.getTile().getWorld().getTileEntity(instance.getTile().getPos().offset(side));
    if (adjTile == null) {
        return;
    }
    if (isMachine) {
        ((TileEntityMachine) instance.getTile()).itemHandler.ifPresent(ih -> adjTile.getCapability(ITEM_HANDLER_CAPABILITY).ifPresent(other -> Utils.transferItems(ih.getOutputHandler(), other, true)));
    } else {
        Utils.transferItemsOnCap(instance.getTile(), adjTile, true);
    }
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) CoverTiered(muramasa.antimatter.cover.CoverTiered) Utils(muramasa.antimatter.util.Utils) Blocks(net.minecraft.block.Blocks) ItemStack(net.minecraft.item.ItemStack) Tier(muramasa.antimatter.machine.Tier) Map(java.util.Map) CoverStack(muramasa.antimatter.cover.CoverStack) TileEntity(net.minecraft.tileentity.TileEntity) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) Ref(trinsdar.gt4r.Ref) BlockState(net.minecraft.block.BlockState) ItemEntity(net.minecraft.entity.item.ItemEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) BlockState(net.minecraft.block.BlockState) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 CoverStack (muramasa.antimatter.cover.CoverStack)1 CoverTiered (muramasa.antimatter.cover.CoverTiered)1 Tier (muramasa.antimatter.machine.Tier)1 TileEntityMachine (muramasa.antimatter.tile.TileEntityMachine)1 Utils (muramasa.antimatter.util.Utils)1 BlockState (net.minecraft.block.BlockState)1 Blocks (net.minecraft.block.Blocks)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Direction (net.minecraft.util.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 ITEM_HANDLER_CAPABILITY (net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)1 Ref (trinsdar.gt4r.Ref)1