Search in sources :

Example 1 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class ItemDrainTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(this).allowingBeltFunnels().setInsertionHandler(this::tryInsertingFromSide));
    behaviours.add(internalTank = SmartFluidTankBehaviour.single(this, 1500).allowExtraction().forbidInsertion());
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)

Example 2 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class BasinBlock method canOutputTo.

public static boolean canOutputTo(BlockGetter world, BlockPos basinPos, Direction direction) {
    BlockPos neighbour = basinPos.relative(direction);
    BlockPos output = neighbour.below();
    BlockState blockState = world.getBlockState(neighbour);
    if (FunnelBlock.isFunnel(blockState)) {
        if (FunnelBlock.getFunnelFacing(blockState) == direction)
            return false;
    } else if (!blockState.getCollisionShape(world, neighbour).isEmpty()) {
        return false;
    } else {
        BlockEntity tileEntity = world.getBlockEntity(output);
        if (tileEntity instanceof BeltTileEntity) {
            BeltTileEntity belt = (BeltTileEntity) tileEntity;
            return belt.getSpeed() == 0 || belt.getMovementFacing() != direction.getOpposite();
        }
    }
    DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(world, output, DirectBeltInputBehaviour.TYPE);
    if (directBeltInputBehaviour != null)
        return directBeltInputBehaviour.canInsertFromSide(direction);
    return false;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class SawTileEntity method tick.

@Override
public void tick() {
    if (shouldRun() && ticksUntilNextProgress < 0)
        destroyNextTick();
    super.tick();
    if (!canProcess())
        return;
    if (getSpeed() == 0)
        return;
    if (inventory.remainingTime == -1) {
        if (!inventory.isEmpty() && !inventory.appliedRecipe)
            start(inventory.getStackInSlot(0));
        return;
    }
    float processingSpeed = Mth.clamp(Math.abs(getSpeed()) / 24, 1, 128);
    inventory.remainingTime -= processingSpeed;
    if (inventory.remainingTime > 0)
        spawnParticles(inventory.getStackInSlot(0));
    if (inventory.remainingTime < 5 && !inventory.appliedRecipe) {
        if (level.isClientSide && !isVirtual())
            return;
        playEvent = inventory.getStackInSlot(0);
        applyRecipe();
        inventory.appliedRecipe = true;
        inventory.recipeDuration = 20;
        inventory.remainingTime = 20;
        sendData();
        return;
    }
    Vec3 itemMovement = getItemMovementVec();
    Direction itemMovementFacing = Direction.getNearest(itemMovement.x, itemMovement.y, itemMovement.z);
    if (inventory.remainingTime > 0)
        return;
    inventory.remainingTime = 0;
    for (int slot = 0; slot < inventory.getSlots(); slot++) {
        ItemStack stack = inventory.getStackInSlot(slot);
        if (stack.isEmpty())
            continue;
        ItemStack tryExportingToBeltFunnel = getBehaviour(DirectBeltInputBehaviour.TYPE).tryExportingToBeltFunnel(stack, itemMovementFacing.getOpposite(), false);
        if (tryExportingToBeltFunnel != null) {
            if (tryExportingToBeltFunnel.getCount() != stack.getCount()) {
                inventory.setStackInSlot(slot, tryExportingToBeltFunnel);
                notifyUpdate();
                return;
            }
            if (!tryExportingToBeltFunnel.isEmpty())
                return;
        }
    }
    BlockPos nextPos = worldPosition.offset(itemMovement.x, itemMovement.y, itemMovement.z);
    DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(level, nextPos, DirectBeltInputBehaviour.TYPE);
    if (behaviour != null) {
        boolean changed = false;
        if (!behaviour.canInsertFromSide(itemMovementFacing))
            return;
        if (level.isClientSide && !isVirtual())
            return;
        for (int slot = 0; slot < inventory.getSlots(); slot++) {
            ItemStack stack = inventory.getStackInSlot(slot);
            if (stack.isEmpty())
                continue;
            ItemStack remainder = behaviour.handleInsertion(stack, itemMovementFacing, false);
            if (remainder.equals(stack, false))
                continue;
            inventory.setStackInSlot(slot, remainder);
            changed = true;
        }
        if (changed) {
            setChanged();
            sendData();
        }
        return;
    }
    // Eject Items
    Vec3 outPos = VecHelper.getCenterOf(worldPosition).add(itemMovement.scale(.5f).add(0, .5, 0));
    Vec3 outMotion = itemMovement.scale(.0625).add(0, .125, 0);
    for (int slot = 0; slot < inventory.getSlots(); slot++) {
        ItemStack stack = inventory.getStackInSlot(slot);
        if (stack.isEmpty())
            continue;
        ItemEntity entityIn = new ItemEntity(level, outPos.x, outPos.y, outPos.z, stack);
        entityIn.setDeltaMovement(outMotion);
        level.addFreshEntity(entityIn);
    }
    inventory.clear();
    level.updateNeighbourForOutputSignal(worldPosition, getBlockState().getBlock());
    inventory.remainingTime = -1;
    sendData();
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Example 4 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class MillstoneTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(this));
    super.addBehaviours(behaviours);
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)

Example 5 with DirectBeltInputBehaviour

use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.

the class BeltTunnelBlock method hasValidOutput.

private boolean hasValidOutput(BlockGetter world, BlockPos pos, Direction side) {
    BlockState blockState = world.getBlockState(pos.relative(side));
    if (AllBlocks.BELT.has(blockState))
        return blockState.getValue(BeltBlock.HORIZONTAL_FACING).getAxis() == side.getAxis();
    DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(world, pos.relative(side), DirectBeltInputBehaviour.TYPE);
    return behaviour != null && behaviour.canInsertFromSide(side);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)

Aggregations

DirectBeltInputBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour)24 ItemStack (net.minecraft.world.item.ItemStack)14 BlockPos (net.minecraft.core.BlockPos)11 Direction (net.minecraft.core.Direction)11 ItemEntity (net.minecraft.world.entity.item.ItemEntity)8 BlockState (net.minecraft.world.level.block.state.BlockState)8 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)7 Vec3 (net.minecraft.world.phys.Vec3)7 BeltTileEntity (com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity)4 Level (net.minecraft.world.level.Level)3 SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)2 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)2 FilteringBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)2 BlockFace (com.simibubi.create.foundation.utility.BlockFace)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 AABB (net.minecraft.world.phys.AABB)2 InstancedRenderDispatcher (com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllSoundEvents (com.simibubi.create.AllSoundEvents)1 IHaveHoveringInformation (com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation)1