1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

Increase the distance from which we drop items

I was having issues where dropped items would clip into blocks when
dropped, and then phase upwards through the turtle instead. This makes
things a little more consistent with dispenser behaviour.
This commit is contained in:
Jonathan Coates 2023-01-01 14:51:47 +00:00
parent 230c7ee904
commit 7b6caf76e4
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
5 changed files with 31 additions and 24 deletions

View File

@ -251,7 +251,7 @@ private void ejectContents() {
if (stack.isEmpty()) return;
setDiskStack(ItemStack.EMPTY);
WorldUtil.dropItemStack(stack, getLevel(), getBlockPos(), getDirection());
WorldUtil.dropItemStack(getLevel(), getBlockPos(), getDirection(), stack);
getLevel().levelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, getBlockPos(), 0);
}

View File

@ -46,7 +46,7 @@ public static ContainerTransfer getSelectedSlot(ITurtleAccess turtle) {
public static void storeItemOrDrop(ITurtleAccess turtle, ItemStack stack) {
if (stack.isEmpty()) return;
if (turtle.isRemoved()) {
WorldUtil.dropItemStack(stack, turtle.getLevel(), turtle.getPosition(), null);
WorldUtil.dropItemStack(turtle.getLevel(), turtle.getPosition(), null, stack);
return;
}
@ -54,7 +54,7 @@ public static void storeItemOrDrop(ITurtleAccess turtle, ItemStack stack) {
var remainder = InventoryUtil.storeItemsFromOffset(turtle.getInventory(), stack, turtle.getSelectedSlot());
if (remainder.isEmpty()) return;
WorldUtil.dropItemStack(remainder, turtle.getLevel(), turtle.getPosition(), turtle.getDirection().getOpposite());
WorldUtil.dropItemStack(turtle.getLevel(), turtle.getPosition(), turtle.getDirection().getOpposite(), remainder);
}
public static Function<ItemStack, ItemStack> dropConsumer(ITurtleAccess turtle) {

View File

@ -58,7 +58,7 @@ public TurtleCommandResult execute(ITurtleAccess turtle) {
turtle.getInventory().setChanged();
transferred = stack.getCount();
WorldUtil.dropItemStack(stack, world, oldPosition, direction);
WorldUtil.dropItemStack(world, oldPosition, direction, stack);
world.globalLevelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, newPosition, 0);
}
}

View File

@ -61,7 +61,7 @@ public static List<ItemStack> clear() {
public static void clearAndDrop(Level world, BlockPos pos, @Nullable Direction direction) {
var remainingDrops = clear();
for (var remaining : remainingDrops) WorldUtil.dropItemStack(remaining, world, pos, direction);
for (var remaining : remainingDrops) WorldUtil.dropItemStack(world, pos, direction, remaining);
}
private static void handleDrops(ItemStack stack) {

View File

@ -8,6 +8,8 @@
import dan200.computercraft.shared.platform.PlatformHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
@ -118,11 +120,21 @@ public static Vec3 getRayEnd(Player player) {
return getRayStart(player).add(look.x * reach, look.y * reach, look.z * reach);
}
public static void dropItemStack(ItemStack stack, Level world, BlockPos pos) {
dropItemStack(stack, world, pos, null);
}
private static final double DROP_SPEED = 0.0172275 * 6;
public static void dropItemStack(ItemStack stack, Level world, BlockPos pos, @Nullable Direction direction) {
/**
* Drop an item stack into the world from a block.
* <p>
* This behaves similarly to {@link DefaultDispenseItemBehavior#spawnItem(Level, ItemStack, int, Direction, Position)},
* though supports a {@code null} direction (in which case the item will have no velocity) and produces a slightly
* different arc.
*
* @param level The level to drop the item in.
* @param pos The position to drop the stack from.
* @param direction The direction to drop in, or {@code null}.
* @param stack The stack to drop.
*/
public static void dropItemStack(Level level, BlockPos pos, @Nullable Direction direction, ItemStack stack) {
double xDir;
double yDir;
double zDir;
@ -136,25 +148,20 @@ public static void dropItemStack(ItemStack stack, Level world, BlockPos pos, @Nu
zDir = 0.0;
}
var xPos = pos.getX() + 0.5 + xDir * 0.4;
var yPos = pos.getY() + 0.5 + yDir * 0.4;
var zPos = pos.getZ() + 0.5 + zDir * 0.4;
dropItemStack(stack, world, new Vec3(xPos, yPos, zPos), xDir, yDir, zDir);
}
var xPos = pos.getX() + 0.5 + xDir * 0.7;
var yPos = pos.getY() + 0.5 + yDir * 0.7;
var zPos = pos.getZ() + 0.5 + zDir * 0.7;
public static void dropItemStack(ItemStack stack, Level world, Vec3 pos) {
dropItemStack(stack, world, pos, 0.0, 0.0, 0.0);
}
public static void dropItemStack(ItemStack stack, Level world, Vec3 pos, double xDir, double yDir, double zDir) {
var item = new ItemEntity(world, pos.x, pos.y, pos.z, stack.copy());
var item = new ItemEntity(level, xPos, yPos, zPos, stack.copy());
var baseSpeed = level.random.nextDouble() * 0.1 + 0.2;
item.setDeltaMovement(
xDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1,
yDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1,
zDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1
level.random.triangle(xDir * baseSpeed, DROP_SPEED),
// Vanilla ignores the yDir and does a constant 0.2, but that gives the item a higher arc than we want.
level.random.triangle(yDir * baseSpeed, DROP_SPEED),
level.random.triangle(zDir * baseSpeed, DROP_SPEED)
);
item.setDefaultPickUpDelay();
world.addFreshEntity(item);
level.addFreshEntity(item);
}
/**