Search in sources :

Example 16 with DirectBeltInputBehaviour

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

the class CrushingWheelControllerTileEntity method tick.

@Override
public void tick() {
    super.tick();
    if (searchForEntity) {
        searchForEntity = false;
        List<Entity> search = level.getEntities((Entity) null, new AABB(getBlockPos()), e -> entityUUID.equals(e.getUUID()));
        if (search.isEmpty())
            clear();
        else
            processingEntity = search.get(0);
    }
    if (!isOccupied())
        return;
    if (crushingspeed == 0)
        return;
    if (level.isClientSide)
        DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.tickAudio());
    float speed = crushingspeed * 4;
    Vec3 centerPos = VecHelper.getCenterOf(worldPosition);
    Direction facing = getBlockState().getValue(CrushingWheelControllerBlock.FACING);
    int offset = facing.getAxisDirection().getStep();
    Vec3 outSpeed = new Vec3((facing.getAxis() == Axis.X ? 0.25D : 0.0D) * offset, // Increased upwards speed so upwards
    offset == 1 ? (facing.getAxis() == Axis.Y ? 0.5D : 0.0D) : 0.0D, // properly.
    (facing.getAxis() == Axis.Z ? 0.25D : 0.0D) * // No downwards speed, so downwards crushing wheels
    offset);
    // drop the items as before.
    Vec3 outPos = centerPos.add((facing.getAxis() == Axis.X ? .55f * offset : 0f), (facing.getAxis() == Axis.Y ? .55f * offset : 0f), (facing.getAxis() == Axis.Z ? .55f * offset : 0f));
    if (!hasEntity()) {
        float processingSpeed = Mth.clamp((speed) / (!inventory.appliedRecipe ? Mth.log2(inventory.getStackInSlot(0).getCount()) : 1), .25f, 20);
        inventory.remainingTime -= processingSpeed;
        spawnParticles(inventory.getStackInSlot(0));
        if (level.isClientSide)
            return;
        if (inventory.remainingTime < 20 && !inventory.appliedRecipe) {
            applyRecipe();
            inventory.appliedRecipe = true;
            level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 2 | 16);
            return;
        }
        if (inventory.remainingTime > 0) {
            return;
        }
        inventory.remainingTime = 0;
        // Output Items
        if (facing != Direction.UP) {
            Direction inputDir = facing.getOpposite();
            BlockPos nextPos = worldPosition.offset(facing.getAxis() == Axis.X ? 1f * offset : 0f, (-1f), facing.getAxis() == Axis.Z ? 1f * offset : 0f);
            DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(level, nextPos, DirectBeltInputBehaviour.TYPE);
            if (behaviour != null) {
                boolean changed = false;
                if (!behaviour.canInsertFromSide(inputDir))
                    return;
                for (int slot = 0; slot < inventory.getSlots(); slot++) {
                    ItemStack stack = inventory.getStackInSlot(slot);
                    if (stack.isEmpty())
                        continue;
                    ItemStack remainder = behaviour.handleInsertion(stack, inputDir, false);
                    if (remainder.equals(stack, false))
                        continue;
                    inventory.setStackInSlot(slot, remainder);
                    changed = true;
                }
                if (changed) {
                    setChanged();
                    sendData();
                }
                return;
            }
        }
        // Eject Items
        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(outSpeed);
            entityIn.getPersistentData().put("BypassCrushingWheel", NbtUtils.writeBlockPos(worldPosition));
            level.addFreshEntity(entityIn);
        }
        inventory.clear();
        level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 2 | 16);
        return;
    }
    if (!processingEntity.isAlive() || !processingEntity.getBoundingBox().intersects(new AABB(worldPosition).inflate(.5f))) {
        clear();
        return;
    }
    double xMotion = ((worldPosition.getX() + .5f) - processingEntity.getX()) / 2f;
    double zMotion = ((worldPosition.getZ() + .5f) - processingEntity.getZ()) / 2f;
    if (processingEntity.isShiftKeyDown())
        xMotion = zMotion = 0;
    double movement = Math.max(-speed / 4f, -.5f) * -offset;
    processingEntity.setDeltaMovement(new // Do
    Vec3(// Do
    facing.getAxis() == Axis.X ? movement : xMotion, // Do
    facing.getAxis() == Axis.Y ? movement : 0f, // crushers,
    facing.getAxis() == Axis.Z ? movement : // Or they'll only get their feet crushed.
    zMotion));
    if (level.isClientSide)
        return;
    if (!(processingEntity instanceof ItemEntity)) {
        Vec3 entityOutPos = outPos.add(facing.getAxis() == Axis.X ? .5f * offset : 0f, facing.getAxis() == Axis.Y ? .5f * offset : 0f, facing.getAxis() == Axis.Z ? .5f * offset : 0f);
        int crusherDamage = AllConfigs.SERVER.kinetics.crushingDamage.get();
        if (processingEntity instanceof LivingEntity) {
            if (// Takes LivingEntity instances
            (((LivingEntity) processingEntity).getHealth() - crusherDamage <= 0) && // kill them.
            (((LivingEntity) processingEntity).hurtTime <= 0)) {
                // This way it can actually output the items
                // to the right spot.
                processingEntity.setPos(entityOutPos.x, entityOutPos.y, entityOutPos.z);
            }
        }
        processingEntity.hurt(CrushingWheelTileEntity.DAMAGE_SOURCE, crusherDamage);
        if (!processingEntity.isAlive()) {
            processingEntity.setPos(entityOutPos.x, entityOutPos.y, entityOutPos.z);
        }
        return;
    }
    ItemEntity itemEntity = (ItemEntity) processingEntity;
    itemEntity.setPickUpDelay(20);
    if (facing.getAxis() == Axis.Y) {
        if (processingEntity.getY() * -offset < (centerPos.y - .25f) * -offset) {
            intakeItem(itemEntity);
        }
    } else if (facing.getAxis() == Axis.Z) {
        if (processingEntity.getZ() * -offset < (centerPos.z - .25f) * -offset) {
            intakeItem(itemEntity);
        }
    } else {
        if (processingEntity.getX() * -offset < (centerPos.x - .25f) * -offset) {
            intakeItem(itemEntity);
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) Entity(net.minecraft.world.entity.Entity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Direction(net.minecraft.core.Direction) LivingEntity(net.minecraft.world.entity.LivingEntity) 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) AABB(net.minecraft.world.phys.AABB)

Example 17 with DirectBeltInputBehaviour

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

the class BasinTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(this));
    filtering = new FilteringBehaviour(this, new BasinValueBox()).moveText(new Vec3(2, -8, 0)).withCallback(newFilter -> contentsChanged = true).forRecipes();
    behaviours.add(filtering);
    inputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.INPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true);
    outputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.OUTPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true).forbidInsertion();
    behaviours.add(inputTank);
    behaviours.add(outputTank);
    fluidCapability = LazyOptional.of(() -> {
        LazyOptional<? extends IFluidHandler> inputCap = inputTank.getCapability();
        LazyOptional<? extends IFluidHandler> outputCap = outputTank.getCapability();
        return new CombinedTankWrapper(inputCap.orElse(null), outputCap.orElse(null));
    });
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) LazyOptional(net.minecraftforge.common.util.LazyOptional) Vec3(net.minecraft.world.phys.Vec3) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper)

Example 18 with DirectBeltInputBehaviour

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

the class FunnelTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    invManipulation = new InvManipulationBehaviour(this, (w, p, s) -> new BlockFace(p, AbstractFunnelBlock.getFunnelFacing(s).getOpposite()));
    behaviours.add(invManipulation);
    filtering = new FilteringBehaviour(this, new FunnelFilterSlotPositioning());
    filtering.showCountWhen(this::supportsAmountOnFilter);
    filtering.onlyActiveWhen(this::supportsFiltering);
    behaviours.add(filtering);
    behaviours.add(new DirectBeltInputBehaviour(this).onlyInsertWhen(this::supportsDirectBeltInput).setInsertionHandler(this::handleDirectBeltInput));
}
Also used : InstancedRenderDispatcher(com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher) AllPackets(com.simibubi.create.foundation.networking.AllPackets) IHaveHoveringInformation(com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation) VecHelper(com.simibubi.create.foundation.utility.VecHelper) AABB(net.minecraft.world.phys.AABB) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) BeltHelper(com.simibubi.create.content.contraptions.relays.belt.BeltHelper) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) Dist(net.minecraftforge.api.distmarker.Dist) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) AllConfigs(com.simibubi.create.foundation.config.AllConfigs) BlockFace(com.simibubi.create.foundation.utility.BlockFace) WeakReference(java.lang.ref.WeakReference) AllBlocks(com.simibubi.create.AllBlocks) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) TileEntityBehaviour(com.simibubi.create.foundation.tileEntity.TileEntityBehaviour) DistExecutor(net.minecraftforge.fml.DistExecutor) BeltTileEntity(com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) Vec3(net.minecraft.world.phys.Vec3) Shape(com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock.Shape) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) FunnelFlapPacket(com.simibubi.create.content.logistics.packet.FunnelFlapPacket) ItemStack(net.minecraft.world.item.ItemStack) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) AllSoundEvents(com.simibubi.create.AllSoundEvents) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BlockFace(com.simibubi.create.foundation.utility.BlockFace) InvManipulationBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour)

Example 19 with DirectBeltInputBehaviour

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

the class SharedDepotBlockMethods method onLanded.

public static void onLanded(BlockGetter worldIn, Entity entityIn) {
    if (!(entityIn instanceof ItemEntity))
        return;
    if (!entityIn.isAlive())
        return;
    if (entityIn.level.isClientSide)
        return;
    ItemEntity itemEntity = (ItemEntity) entityIn;
    DirectBeltInputBehaviour inputBehaviour = TileEntityBehaviour.get(worldIn, entityIn.blockPosition(), DirectBeltInputBehaviour.TYPE);
    if (inputBehaviour == null)
        return;
    ItemStack remainder = inputBehaviour.handleInsertion(itemEntity.getItem(), Direction.DOWN, false);
    itemEntity.setItem(remainder);
    if (remainder.isEmpty())
        itemEntity.discard();
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) TransportedItemStack(com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 20 with DirectBeltInputBehaviour

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

the class MechanicalCrafterTileEntity method tryInsert.

public void tryInsert() {
    if (!inserting.hasInventory() && !isTargetingBelt()) {
        ejectWholeGrid();
        return;
    }
    boolean chagedPhase = phase != Phase.INSERTING;
    final List<Pair<Integer, Integer>> inserted = new LinkedList<>();
    DirectBeltInputBehaviour behaviour = getTargetingBelt();
    for (Entry<Pair<Integer, Integer>, ItemStack> entry : groupedItems.grid.entrySet()) {
        Pair<Integer, Integer> pair = entry.getKey();
        ItemStack stack = entry.getValue();
        BlockFace face = getTargetFace(level, worldPosition, getBlockState());
        ItemStack remainder = behaviour == null ? inserting.insert(stack.copy()) : behaviour.handleInsertion(stack, face.getFace(), false);
        if (!remainder.isEmpty()) {
            stack.setCount(remainder.getCount());
            continue;
        }
        inserted.add(pair);
    }
    inserted.forEach(groupedItems.grid::remove);
    if (groupedItems.grid.isEmpty())
        ejectWholeGrid();
    else
        phase = Phase.INSERTING;
    if (!inserted.isEmpty() || chagedPhase)
        sendData();
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) BlockFace(com.simibubi.create.foundation.utility.BlockFace) ItemStack(net.minecraft.world.item.ItemStack) LinkedList(java.util.LinkedList) Pair(org.apache.commons.lang3.tuple.Pair)

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