use of net.minecraft.inventory.Inventory in project VariousOddities by Lyinginbedmon.
the class EntityWarg method initWargChest.
public void initWargChest() {
Inventory inventory = this.wargChest;
this.wargChest = new Inventory(getSizeInventory());
if (inventory != null) {
inventory.removeListener(this);
int i = Math.min(inventory.getSizeInventory(), this.wargChest.getSizeInventory());
for (int j = 0; j < i; ++j) {
ItemStack stack = inventory.getStackInSlot(j);
if (!stack.isEmpty())
this.wargChest.setInventorySlotContents(j, stack.copy());
}
}
this.wargChest.addListener(this);
}
use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.
the class StoveBlock method use.
@Override
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
ItemStack heldStack = player.getItemInHand(handIn);
Item heldItem = heldStack.getItem();
if (state.getValue(LIT)) {
if (heldStack.getToolTypes().contains(ToolType.SHOVEL)) {
extinguish(state, worldIn, pos);
heldStack.hurtAndBreak(1, player, action -> action.broadcastBreakEvent(handIn));
return ActionResultType.SUCCESS;
} else if (heldItem == Items.WATER_BUCKET) {
if (!worldIn.isClientSide()) {
worldIn.playSound(null, pos, SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
extinguish(state, worldIn, pos);
if (!player.isCreative()) {
player.setItemInHand(handIn, new ItemStack(Items.BUCKET));
}
return ActionResultType.SUCCESS;
}
} else {
if (heldItem instanceof FlintAndSteelItem) {
worldIn.playSound(player, pos, SoundEvents.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, MathUtils.RAND.nextFloat() * 0.4F + 0.8F);
worldIn.setBlock(pos, state.setValue(BlockStateProperties.LIT, Boolean.TRUE), 11);
heldStack.hurtAndBreak(1, player, action -> action.broadcastBreakEvent(handIn));
return ActionResultType.SUCCESS;
} else if (heldItem instanceof FireChargeItem) {
worldIn.playSound(null, pos, SoundEvents.FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (MathUtils.RAND.nextFloat() - MathUtils.RAND.nextFloat()) * 0.2F + 1.0F);
worldIn.setBlock(pos, state.setValue(BlockStateProperties.LIT, Boolean.TRUE), 11);
if (!player.isCreative()) {
heldStack.shrink(1);
}
return ActionResultType.SUCCESS;
}
}
TileEntity tileEntity = worldIn.getBlockEntity(pos);
if (tileEntity instanceof StoveTileEntity) {
StoveTileEntity stoveEntity = (StoveTileEntity) tileEntity;
int stoveSlot = stoveEntity.getNextEmptySlot();
if (stoveSlot < 0 || stoveEntity.isStoveBlockedAbove()) {
return ActionResultType.PASS;
}
Optional<CampfireCookingRecipe> recipe = stoveEntity.getMatchingRecipe(new Inventory(heldStack), stoveSlot);
if (recipe.isPresent()) {
if (!worldIn.isClientSide && stoveEntity.addItem(player.abilities.instabuild ? heldStack.copy() : heldStack, recipe.get(), stoveSlot)) {
return ActionResultType.SUCCESS;
}
return ActionResultType.CONSUME;
}
}
return ActionResultType.PASS;
}
use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.
the class SkilletTileEntity method addItemToCook.
public ItemStack addItemToCook(ItemStack addedStack, @Nullable PlayerEntity player) {
Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(new Inventory(addedStack));
if (recipe.isPresent()) {
cookingTimeTotal = SkilletBlock.getSkilletCookingTime(recipe.get().getCookingTime(), fireAspectLevel);
boolean wasEmpty = getStoredStack().isEmpty();
ItemStack remainderStack = inventory.insertItem(0, addedStack.copy(), false);
if (!ItemStack.matches(remainderStack, addedStack)) {
lastRecipeID = recipe.get().getId();
cookingTime = 0;
if (wasEmpty && level != null && isHeated(level, worldPosition)) {
level.playSound(null, worldPosition.getX() + 0.5F, worldPosition.getY() + 0.5F, worldPosition.getZ() + 0.5F, ModSounds.BLOCK_SKILLET_ADD_FOOD.get(), SoundCategory.BLOCKS, 0.8F, 1.0F);
}
return remainderStack;
}
} else if (player != null) {
player.displayClientMessage(TextUtils.getTranslation("block.skillet.invalid_item"), true);
}
return addedStack;
}
use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.
the class SkilletTileEntity method cookAndOutputItems.
private void cookAndOutputItems(ItemStack cookingStack) {
if (level == null)
return;
++cookingTime;
if (cookingTime >= cookingTimeTotal) {
Inventory wrapper = new Inventory(cookingStack);
Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(wrapper);
if (recipe.isPresent()) {
ItemStack resultStack = recipe.get().assemble(wrapper);
Direction direction = getBlockState().getValue(SkilletBlock.FACING).getClockWise();
ItemUtils.spawnItemEntity(level, resultStack.copy(), worldPosition.getX() + 0.5, worldPosition.getY() + 0.3, worldPosition.getZ() + 0.5, direction.getStepX() * 0.08F, 0.25F, direction.getStepZ() * 0.08F);
cookingTime = 0;
inventory.extractItem(0, 1, false);
}
}
}
use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.
the class StoveTileEntity method cookAndOutputItems.
private void cookAndOutputItems() {
if (level == null)
return;
boolean didInventoryChange = false;
for (int i = 0; i < inventory.getSlots(); ++i) {
ItemStack stoveStack = inventory.getStackInSlot(i);
if (!stoveStack.isEmpty()) {
++cookingTimes[i];
if (cookingTimes[i] >= cookingTimesTotal[i]) {
IInventory inventoryWrapper = new Inventory(stoveStack);
Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(inventoryWrapper, i);
if (recipe.isPresent()) {
ItemStack resultStack = recipe.get().getResultItem();
if (!resultStack.isEmpty()) {
ItemUtils.spawnItemEntity(level, resultStack.copy(), worldPosition.getX() + 0.5, worldPosition.getY() + 1.0, worldPosition.getZ() + 0.5, level.random.nextGaussian() * (double) 0.01F, 0.1F, level.random.nextGaussian() * (double) 0.01F);
}
}
inventory.setStackInSlot(i, ItemStack.EMPTY);
didInventoryChange = true;
}
}
}
if (didInventoryChange) {
inventoryChanged();
}
}
Aggregations