Search in sources :

Example 16 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class BeltTileEntity method tryInsertingFromSide.

private ItemStack tryInsertingFromSide(TransportedItemStack transportedStack, Direction side, boolean simulate) {
    BeltTileEntity nextBeltController = getControllerTE();
    ItemStack inserted = transportedStack.stack;
    ItemStack empty = ItemStack.EMPTY;
    if (nextBeltController == null)
        return inserted;
    BeltInventory nextInventory = nextBeltController.getInventory();
    if (nextInventory == null)
        return inserted;
    BlockEntity teAbove = level.getBlockEntity(worldPosition.above());
    if (teAbove instanceof BrassTunnelTileEntity) {
        BrassTunnelTileEntity tunnelTE = (BrassTunnelTileEntity) teAbove;
        if (tunnelTE.hasDistributionBehaviour()) {
            if (!tunnelTE.getStackToDistribute().isEmpty())
                return inserted;
            if (!tunnelTE.testFlapFilter(side.getOpposite(), inserted))
                return inserted;
            if (!simulate) {
                BeltTunnelInteractionHandler.flapTunnel(nextInventory, index, side.getOpposite(), true);
                tunnelTE.setStackToDistribute(inserted);
            }
            return empty;
        }
    }
    if (getSpeed() == 0)
        return inserted;
    if (getMovementFacing() == side.getOpposite())
        return inserted;
    if (!nextInventory.canInsertAtFromSide(index, side))
        return inserted;
    if (simulate)
        return empty;
    transportedStack = transportedStack.copy();
    transportedStack.beltPosition = index + .5f - Math.signum(getDirectionAwareBeltMovementSpeed()) / 16f;
    Direction movementFacing = getMovementFacing();
    if (!side.getAxis().isVertical()) {
        if (movementFacing != side) {
            transportedStack.sideOffset = side.getAxisDirection().getStep() * .35f;
            if (side.getAxis() == Axis.X)
                transportedStack.sideOffset *= -1;
        } else
            transportedStack.beltPosition = getDirectionAwareBeltMovementSpeed() > 0 ? index : index + 1;
    }
    transportedStack.prevSideOffset = transportedStack.sideOffset;
    transportedStack.insertedAt = index;
    transportedStack.insertedFrom = side;
    transportedStack.prevBeltPosition = transportedStack.beltPosition;
    BeltTunnelInteractionHandler.flapTunnel(nextInventory, index, side.getOpposite(), true);
    nextInventory.addItem(transportedStack);
    nextBeltController.setChanged();
    nextBeltController.sendData();
    return empty;
}
Also used : BrassTunnelTileEntity(com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity) BeltInventory(com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory) ItemStack(net.minecraft.world.item.ItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 17 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class ChromaticCompoundItem method onEntityItemUpdate.

@Override
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
    double y = entity.getY();
    double yMotion = entity.getDeltaMovement().y;
    Level world = entity.level;
    CompoundTag data = entity.getPersistentData();
    CompoundTag itemData = entity.getItem().getOrCreateTag();
    Vec3 positionVec = entity.position();
    CRecipes config = AllConfigs.SERVER.recipes;
    if (world.isClientSide) {
        int light = itemData.getInt("CollectingLight");
        if (world.random.nextInt(config.lightSourceCountForRefinedRadiance.get() + 20) < light) {
            Vec3 start = VecHelper.offsetRandomly(positionVec, world.random, 3);
            Vec3 motion = positionVec.subtract(start).normalize().scale(.2f);
            world.addParticle(ParticleTypes.END_ROD, start.x, start.y, start.z, motion.x, motion.y, motion.z);
        }
        return false;
    }
    // Convert to Shadow steel if in void
    if (y < 0 && y - yMotion < -10 && config.enableShadowSteelRecipe.get()) {
        ItemStack newStack = AllItems.SHADOW_STEEL.asStack();
        newStack.setCount(stack.getCount());
        data.putBoolean("JustCreated", true);
        entity.setItem(newStack);
    }
    if (!config.enableRefinedRadianceRecipe.get())
        return false;
    // Convert to Refined Radiance if eaten enough light sources
    if (itemData.getInt("CollectingLight") >= config.lightSourceCountForRefinedRadiance.get()) {
        ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
        ItemEntity newEntity = new ItemEntity(world, entity.getX(), entity.getY(), entity.getZ(), newStack);
        newEntity.setDeltaMovement(entity.getDeltaMovement());
        newEntity.getPersistentData().putBoolean("JustCreated", true);
        itemData.remove("CollectingLight");
        world.addFreshEntity(newEntity);
        stack.split(1);
        entity.setItem(stack);
        if (stack.isEmpty())
            entity.discard();
        return false;
    }
    // Is inside beacon beam?
    boolean isOverBeacon = false;
    int entityX = Mth.floor(entity.getX());
    int entityZ = Mth.floor(entity.getZ());
    int localWorldHeight = world.getHeight(Heightmap.Types.WORLD_SURFACE, entityX, entityZ);
    BlockPos.MutableBlockPos testPos = new BlockPos.MutableBlockPos(entityX, Math.min(Mth.floor(entity.getY()), localWorldHeight), entityZ);
    while (testPos.getY() > 0) {
        testPos.move(Direction.DOWN);
        BlockState state = world.getBlockState(testPos);
        if (state.getLightBlock(world, testPos) >= 15 && state.getBlock() != Blocks.BEDROCK)
            break;
        if (state.getBlock() == Blocks.BEACON) {
            BlockEntity te = world.getBlockEntity(testPos);
            if (!(te instanceof BeaconBlockEntity))
                break;
            BeaconBlockEntity bte = (BeaconBlockEntity) te;
            if (!bte.beamSections.isEmpty())
                isOverBeacon = true;
            break;
        }
    }
    if (isOverBeacon) {
        ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
        newStack.setCount(stack.getCount());
        data.putBoolean("JustCreated", true);
        entity.setItem(newStack);
        return false;
    }
    // Find a light source and eat it.
    Random r = world.random;
    int range = 3;
    float rate = 1 / 2f;
    if (r.nextFloat() > rate)
        return false;
    BlockPos randomOffset = new BlockPos(VecHelper.offsetRandomly(positionVec, r, range));
    BlockState state = world.getBlockState(randomOffset);
    TransportedItemStackHandlerBehaviour behaviour = TileEntityBehaviour.get(world, randomOffset, TransportedItemStackHandlerBehaviour.TYPE);
    // Find a placed light source
    if (behaviour == null) {
        if (checkLight(stack, entity, world, itemData, positionVec, randomOffset, state))
            world.destroyBlock(randomOffset, false);
        return false;
    }
    // Find a light source from a depot/belt (chunk rebuild safe)
    MutableBoolean success = new MutableBoolean(false);
    behaviour.handleProcessingOnAllItems(ts -> {
        ItemStack heldStack = ts.stack;
        if (!(heldStack.getItem() instanceof BlockItem))
            return TransportedResult.doNothing();
        BlockItem blockItem = (BlockItem) heldStack.getItem();
        if (blockItem.getBlock() == null)
            return TransportedResult.doNothing();
        BlockState stateToCheck = blockItem.getBlock().defaultBlockState();
        if (!success.getValue() && checkLight(stack, entity, world, itemData, positionVec, randomOffset, stateToCheck)) {
            success.setTrue();
            if (ts.stack.getCount() == 1)
                return TransportedResult.removeItem();
            TransportedItemStack left = ts.copy();
            left.stack.shrink(1);
            return TransportedResult.convertTo(left);
        }
        return TransportedResult.doNothing();
    });
    return false;
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) CRecipes(com.simibubi.create.foundation.config.CRecipes) BlockItem(net.minecraft.world.item.BlockItem) TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) Vec3(net.minecraft.world.phys.Vec3) BeaconBlockEntity(net.minecraft.world.level.block.entity.BeaconBlockEntity) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag) BeaconBlockEntity(net.minecraft.world.level.block.entity.BeaconBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 18 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class BeltDeployerCallbacks method onItemReceived.

public static ProcessingResult onItemReceived(TransportedItemStack s, TransportedItemStackHandlerBehaviour i, DeployerTileEntity deployerTileEntity) {
    if (deployerTileEntity.getSpeed() == 0)
        return ProcessingResult.PASS;
    if (deployerTileEntity.mode == Mode.PUNCH)
        return ProcessingResult.PASS;
    BlockState blockState = deployerTileEntity.getBlockState();
    if (!blockState.hasProperty(FACING) || blockState.getValue(FACING) != Direction.DOWN)
        return ProcessingResult.PASS;
    if (deployerTileEntity.state != State.WAITING)
        return ProcessingResult.HOLD;
    if (deployerTileEntity.redstoneLocked)
        return ProcessingResult.PASS;
    DeployerFakePlayer player = deployerTileEntity.getPlayer();
    ItemStack held = player == null ? ItemStack.EMPTY : player.getMainHandItem();
    if (held.isEmpty())
        return ProcessingResult.HOLD;
    if (deployerTileEntity.getRecipe(s.stack) == null)
        return ProcessingResult.PASS;
    deployerTileEntity.start();
    return ProcessingResult.HOLD;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 19 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class ItemDrainItemHandler method extractItem.

@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    TransportedItemStack held = te.heldItem;
    if (held == null)
        return ItemStack.EMPTY;
    ItemStack stack = held.stack.copy();
    ItemStack extracted = stack.split(amount);
    if (!simulate) {
        te.heldItem.stack = stack;
        if (stack.isEmpty())
            te.heldItem = null;
        te.notifyUpdate();
    }
    return extracted;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 20 with TransportedItemStack

use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.

the class ItemDrainItemHandler method insertItem.

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
    if (!te.getHeldItemStack().isEmpty())
        return stack;
    ItemStack returned = ItemStack.EMPTY;
    if (stack.getCount() > 1 && EmptyingByBasin.canItemBeEmptied(te.getLevel(), stack)) {
        returned = ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1);
        stack = ItemHandlerHelper.copyStackWithSize(stack, 1);
    }
    if (!simulate) {
        TransportedItemStack heldItem = new TransportedItemStack(stack);
        heldItem.prevBeltPosition = 0;
        te.setHeldItem(heldItem, side.getOpposite());
        te.notifyUpdate();
    }
    return returned;
}
Also used : TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)26 ItemStack (net.minecraft.world.item.ItemStack)20 BlockState (net.minecraft.world.level.block.state.BlockState)8 Vec3 (net.minecraft.world.phys.Vec3)8 BlockPos (net.minecraft.core.BlockPos)6 Direction (net.minecraft.core.Direction)6 BeltInventory (com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory)3 ProcessingResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.BeltProcessingBehaviour.ProcessingResult)3 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)3 TransportedResult (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 Entity (net.minecraft.world.entity.Entity)3 ItemEntity (net.minecraft.world.entity.item.ItemEntity)3 Level (net.minecraft.world.level.Level)3 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)2 Create (com.simibubi.create.Create)2 InWorldProcessing (com.simibubi.create.content.contraptions.processing.InWorldProcessing)2 BeltHelper (com.simibubi.create.content.contraptions.relays.belt.BeltHelper)2 List (java.util.List)2