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);
}
}
}
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));
});
}
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));
}
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();
}
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();
}
Aggregations