net.minecraft.inventory.BasicInventory Java Examples

The following examples show how to use net.minecraft.inventory.BasicInventory. 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: 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 #2
Source File: CraftingFluidBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void onEntityCollision(BlockState blockState, World world, BlockPos pos, Entity entity) {
	super.onEntityCollision(blockState, world, pos, entity);
	if(entity instanceof ItemEntity) {
		List<ItemEntity> entities = world.getEntities(ItemEntity.class, new Box(pos), e -> true);
		BasicInventory inventory = new BasicInventory(entities.size());
		
		entities.forEach(itemEntity -> { //required for multi-input recipes
			ItemStack stack = itemEntity.getStack();
			inventory.add(stack);
		});
		
		Optional<FluidRecipe> match = world.getRecipeManager()
			.getFirstMatch(recipeType, inventory, world);

		if (match.isPresent()) {
			spawnCraftingResult(world, pos, match.get().craft(inventory));

			for (Ingredient ingredient : match.get().getIngredients()) {
				for (ItemEntity testEntity : entities) {
					if (ingredient.test(testEntity.getStack())) {
						testEntity.getStack().decrement(1);
						break;
					}
				}
			}
		}
	}
}
 
Example #3
Source File: FluidRecipe.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean matches(BasicInventory inventory, World world) {
	ArrayList<ItemStack> inventoryList = new ArrayList<>();
	for(int i = 0; i < inventory.getInvSize(); i++) {
		inventoryList.add(inventory.getInvStack(i));
	}

	return hasRequiredIngredients(inventoryList);
}
 
Example #4
Source File: FarmerVillagerTask_wartFarmMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "keepRunning", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/inventory/BasicInventory;getInvSize()I"
))
private int plantWart(BasicInventory basicInventory, ServerWorld serverWorld, VillagerEntity villagerEntity, long l)
{
    if (isFarmingCleric) // fill cancel that for loop by setting length to 0
    {
        for(int i = 0; i < basicInventory.getInvSize(); ++i)
        {
            ItemStack itemStack = basicInventory.getInvStack(i);
            boolean bl = false;
            if (!itemStack.isEmpty())
            {
                if (itemStack.getItem() == Items.NETHER_WART)
                {
                    serverWorld.setBlockState(currentTarget, Blocks.NETHER_WART.getDefaultState(), 3);
                    bl = true;
                }
            }

            if (bl)
            {
                serverWorld.playSound(null,
                        currentTarget.getX(), currentTarget.getY(), this.currentTarget.getZ(),
                        SoundEvents.ITEM_NETHER_WART_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F);
                itemStack.decrement(1);
                if (itemStack.isEmpty())
                {
                    basicInventory.setInvStack(i, ItemStack.EMPTY);
                }
                break;
            }
        }
        return 0;

    }
    return basicInventory.getInvSize();
}
 
Example #5
Source File: CmdPeek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getMainHandStack();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ShulkerBoxBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof ChestBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof DispenserBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof HopperBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	List<ItemStack> items = ItemContentUtils.getItemsInContainer(item);
	
	BasicInventory inv = new BasicInventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.openScreen(new ShulkerBoxScreen(
				new ShulkerBoxContainer(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getName()));
	});
}
 
Example #6
Source File: CmdPeek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getMainHandStack();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ShulkerBoxBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof ChestBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof DispenserBlock)
			 && !(((BlockItem) item.getItem()).getBlock() instanceof HopperBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	List<ItemStack> items = ItemContentUtils.getItemsInContainer(item);
	
	BasicInventory inv = new BasicInventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.openScreen(new ShulkerBoxScreen(
				new ShulkerBoxContainer(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getName()));
	});
}
 
Example #7
Source File: FluidRecipe.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public ItemStack craft(BasicInventory inventory) {
	return getOutput().copy();
}