| 1 | package net.minecraft.world;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.NonNullList;
|
| 5 | import net.minecraft.util.RandomSource;
|
| 6 | import net.minecraft.world.entity.Entity;
|
| 7 | import net.minecraft.world.entity.EntityTypes;
|
| 8 | import net.minecraft.world.entity.item.ItemEntity;
|
| 9 | import net.minecraft.world.item.ItemStack;
|
| 10 | import net.minecraft.world.level.Level;
|
| 11 | import net.minecraft.world.level.block.state.BlockState;
|
| 12 |
|
| 13 | public class Containers {
|
| 14 | public static void dropContents(final Level level, final BlockPos pos, final Container container) {
|
| 15 | dropContents(level, pos.getX(), pos.getY(), pos.getZ(), container);
|
| 16 | }
|
| 17 |
|
| 18 | public static void dropContents(final Level level, final Entity entity, final Container container) {
|
| 19 | dropContents(level, entity.getX(), entity.getY(), entity.getZ(), container);
|
| 20 | }
|
| 21 |
|
| 22 | private static void dropContents(final Level level, final double x, final double y, final double z, final Container container) {
|
| 23 | for (int i = 0; i < container.getContainerSize(); i++) {
|
| 24 | dropItemStack(level, x, y, z, container.getItem(i));
|
| 25 | }
|
| 26 | }
|
| 27 |
|
| 28 | public static void dropContents(final Level level, final BlockPos pos, final NonNullList<ItemStack> list) {
|
| 29 | list.forEach(itemStack -> dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), itemStack));
|
| 30 | }
|
| 31 |
|
| 32 | public static void dropItemStack(final Level level, final double x, final double y, final double z, final ItemStack itemStack) {
|
| 33 | double size = EntityTypes.ITEM.getWidth();
|
| 34 | double centerRange = 1.0 - size;
|
| 35 | double halfSize = size / 2.0;
|
| 36 | RandomSource random = level.getRandom();
|
| 37 | double xo = Math.floor(x) + random.nextDouble() * centerRange + halfSize;
|
| 38 | double yo = Math.floor(y) + random.nextDouble() * centerRange;
|
| 39 | double zo = Math.floor(z) + random.nextDouble() * centerRange + halfSize;
|
| 40 |
|
| 41 | while (!itemStack.isEmpty()) {
|
| 42 | ItemEntity entity = new ItemEntity(level, xo, yo, zo, itemStack.split(random.nextInt(21) + 10));
|
| 43 | float pow = 0.05F;
|
| 44 | entity.setDeltaMovement(random.triangle(0.0, 0.11485000171139836), random.triangle(0.2, 0.11485000171139836), random.triangle(0.0, 0.11485000171139836));
|
| 45 | level.addFreshEntity(entity);
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | public static void updateNeighboursAfterDestroy(final BlockState state, final Level level, final BlockPos pos) {
|
| 50 | level.updateNeighbourForOutputSignal(pos, state.getBlock());
|
| 51 | }
|
| 52 | }
|
| 53 |
|