mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +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:
parent
230c7ee904
commit
7b6caf76e4
@ -251,7 +251,7 @@ public final class DiskDriveBlockEntity extends AbstractContainerBlockEntity {
|
|||||||
if (stack.isEmpty()) return;
|
if (stack.isEmpty()) return;
|
||||||
setDiskStack(ItemStack.EMPTY);
|
setDiskStack(ItemStack.EMPTY);
|
||||||
|
|
||||||
WorldUtil.dropItemStack(stack, getLevel(), getBlockPos(), getDirection());
|
WorldUtil.dropItemStack(getLevel(), getBlockPos(), getDirection(), stack);
|
||||||
getLevel().levelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, getBlockPos(), 0);
|
getLevel().levelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, getBlockPos(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class TurtleUtil {
|
|||||||
public static void storeItemOrDrop(ITurtleAccess turtle, ItemStack stack) {
|
public static void storeItemOrDrop(ITurtleAccess turtle, ItemStack stack) {
|
||||||
if (stack.isEmpty()) return;
|
if (stack.isEmpty()) return;
|
||||||
if (turtle.isRemoved()) {
|
if (turtle.isRemoved()) {
|
||||||
WorldUtil.dropItemStack(stack, turtle.getLevel(), turtle.getPosition(), null);
|
WorldUtil.dropItemStack(turtle.getLevel(), turtle.getPosition(), null, stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public class TurtleUtil {
|
|||||||
var remainder = InventoryUtil.storeItemsFromOffset(turtle.getInventory(), stack, turtle.getSelectedSlot());
|
var remainder = InventoryUtil.storeItemsFromOffset(turtle.getInventory(), stack, turtle.getSelectedSlot());
|
||||||
if (remainder.isEmpty()) return;
|
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) {
|
public static Function<ItemStack, ItemStack> dropConsumer(ITurtleAccess turtle) {
|
||||||
|
@ -58,7 +58,7 @@ public class TurtleDropCommand implements TurtleCommand {
|
|||||||
turtle.getInventory().setChanged();
|
turtle.getInventory().setChanged();
|
||||||
transferred = stack.getCount();
|
transferred = stack.getCount();
|
||||||
|
|
||||||
WorldUtil.dropItemStack(stack, world, oldPosition, direction);
|
WorldUtil.dropItemStack(world, oldPosition, direction, stack);
|
||||||
world.globalLevelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, newPosition, 0);
|
world.globalLevelEvent(LevelEvent.SOUND_DISPENSER_DISPENSE, newPosition, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public final class DropConsumer {
|
|||||||
|
|
||||||
public static void clearAndDrop(Level world, BlockPos pos, @Nullable Direction direction) {
|
public static void clearAndDrop(Level world, BlockPos pos, @Nullable Direction direction) {
|
||||||
var remainingDrops = clear();
|
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) {
|
private static void handleDrops(ItemStack stack) {
|
||||||
|
@ -8,6 +8,8 @@ package dan200.computercraft.shared.util;
|
|||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
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.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
@ -118,11 +120,21 @@ public final class WorldUtil {
|
|||||||
return getRayStart(player).add(look.x * reach, look.y * reach, look.z * reach);
|
return getRayStart(player).add(look.x * reach, look.y * reach, look.z * reach);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dropItemStack(ItemStack stack, Level world, BlockPos pos) {
|
private static final double DROP_SPEED = 0.0172275 * 6;
|
||||||
dropItemStack(stack, world, pos, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 xDir;
|
||||||
double yDir;
|
double yDir;
|
||||||
double zDir;
|
double zDir;
|
||||||
@ -136,25 +148,20 @@ public final class WorldUtil {
|
|||||||
zDir = 0.0;
|
zDir = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var xPos = pos.getX() + 0.5 + xDir * 0.4;
|
var xPos = pos.getX() + 0.5 + xDir * 0.7;
|
||||||
var yPos = pos.getY() + 0.5 + yDir * 0.4;
|
var yPos = pos.getY() + 0.5 + yDir * 0.7;
|
||||||
var zPos = pos.getZ() + 0.5 + zDir * 0.4;
|
var zPos = pos.getZ() + 0.5 + zDir * 0.7;
|
||||||
dropItemStack(stack, world, new Vec3(xPos, yPos, zPos), xDir, yDir, zDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void dropItemStack(ItemStack stack, Level world, Vec3 pos) {
|
var item = new ItemEntity(level, xPos, yPos, zPos, stack.copy());
|
||||||
dropItemStack(stack, world, pos, 0.0, 0.0, 0.0);
|
var baseSpeed = level.random.nextDouble() * 0.1 + 0.2;
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
item.setDeltaMovement(
|
item.setDeltaMovement(
|
||||||
xDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1,
|
level.random.triangle(xDir * baseSpeed, DROP_SPEED),
|
||||||
yDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1,
|
// Vanilla ignores the yDir and does a constant 0.2, but that gives the item a higher arc than we want.
|
||||||
zDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1
|
level.random.triangle(yDir * baseSpeed, DROP_SPEED),
|
||||||
|
level.random.triangle(zDir * baseSpeed, DROP_SPEED)
|
||||||
);
|
);
|
||||||
item.setDefaultPickUpDelay();
|
item.setDefaultPickUpDelay();
|
||||||
world.addFreshEntity(item);
|
level.addFreshEntity(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user