net.minecraft.util.ItemScatterer Java Examples

The following examples show how to use net.minecraft.util.ItemScatterer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CavernousVineBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void onBreak(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
    super.onBreak(world, blockPos, blockState, playerEntity);

    if (playerEntity.getActiveItem().getItem() instanceof ShearsItem) {
        ItemScatterer.spawn(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), new ItemStack(this.asItem(), 1));
    }
}
 
Example #2
Source File: HallowedTreasureChestEntity.java    From the-hallow with MIT License 5 votes vote down vote up
private void dropLoot(ServerWorld serverWorld) {
	// set up loot objects
	LootTable supplier = serverWorld.getServer().getLootManager().getSupplier(new Identifier(TheHallow.MOD_ID, "gameplay/treasure_chest_common"));
	LootContext.Builder builder =
		new LootContext.Builder(serverWorld)
			.setRandom(serverWorld.random)
			.put(LootContextParameters.POSITION, getBlockPos());
	
	// build & add loot to output
	List<ItemStack> stacks = supplier.getDrops(builder.build(LootContextTypes.CHEST));
	stacks.forEach(stack -> ItemScatterer.spawn(world, getBlockPos(), new BasicInventory(stack)));
}
 
Example #3
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onBlockRemoved(BlockState state1, World world, BlockPos pos, BlockState state2, boolean flag) {
	if (state1.getBlock() != state2.getBlock()) {
		BlockEntity be = world.getBlockEntity(pos);
		if (be instanceof TinyPumpkinBlockEntity) {
			ItemScatterer.spawn(world, pos, ((TinyPumpkinBlockEntity) be).getAllItems());
			world.updateHorizontalAdjacent(pos, this);
		}
		
		super.onBlockRemoved(state1, world, pos, state2, flag);
	}
}
 
Example #4
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}