use of net.minecraft.inventory.SimpleInventory in project CopperEquipment by Redy1aye.
the class DryerBlockEntity method hasRecipe.
private static boolean hasRecipe(DryerBlockEntity entity) {
World world = entity.world;
SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
for (int i = 0; i < entity.inventory.size(); i++) {
inventory.setStack(i, entity.getStack(i));
}
assert world != null;
Optional<DryerRecipes> match = world.getRecipeManager().getFirstMatch(DryerRecipes.Type.INSTANCE, inventory, world);
return match.isPresent() && canInsertAmountIntoOutputSlot(inventory) && canInsertItemIntoOutputSlot(inventory, match.get().getOutput());
}
use of net.minecraft.inventory.SimpleInventory in project Capybara-Fabricated by ZestyBlaze.
the class CapybaraEntity method interactMob.
@Override
public ActionResult interactMob(PlayerEntity player, Hand hand) {
final ItemStack stack = player.getStackInHand(hand);
if (player.isSneaking()) {
if (stack.getItem() == Blocks.CHEST.asItem()) {
if (inventory == null || inventory.size() < 27) {
inventory = new SimpleInventory(27);
dataTracker.set(CHESTS, 1);
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
}
return ActionResult.SUCCESS;
} else if (inventory.size() < 54) {
Inventory inv = new SimpleInventory(54);
for (int i = 0; i < 27; i++) {
inv.setStack(i, inventory.getStack(i));
}
inventory = inv;
dataTracker.set(CHESTS, 2);
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
}
return ActionResult.SUCCESS;
}
}
if (stack.getItem() == Items.STICK) {
this.setSitting(!this.isSitting());
} else {
player.openHandledScreen(this);
return ActionResult.SUCCESS;
}
} else if (TEMPT_ITEMS.get().contains(stack.getItem()) && !isTamed()) {
if (this.random.nextInt(3) == 0) {
this.setOwner(player);
this.navigation.stop();
this.setTarget(null);
this.setSitting(true);
this.world.sendEntityStatus(this, (byte) 7);
}
if (!player.getAbilities().creativeMode) {
stack.decrement(1);
} else {
this.world.sendEntityStatus(this, (byte) 6);
}
return ActionResult.SUCCESS;
} else if (!this.hasPassengers() && !player.shouldCancelInteraction() && !this.isBaby() && !isInSittingPose()) {
boolean flag = this.isBreedingItem(player.getStackInHand(hand));
if (!flag && !this.hasPassengers() && !player.shouldCancelInteraction()) {
if (!this.world.isClient) {
player.startRiding(this);
}
return ActionResult.SUCCESS;
}
} else if (!this.getPassengerList().isEmpty()) {
removeAllPassengers();
}
return super.interactMob(player, hand);
}
use of net.minecraft.inventory.SimpleInventory in project Capybara-Fabricated by ZestyBlaze.
the class CapybaraEntity method readCustomDataFromNbt.
@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
if (nbt.contains("Inventory")) {
final NbtList inv = nbt.getList("Inventory", 10);
inventory = new SimpleInventory(inv.size());
for (int i = 0; i < inv.size(); i++) {
inventory.setStack(i, ItemStack.fromNbt(inv.getCompound(i)));
}
dataTracker.set(CHESTS, inv.size() > 27 ? 2 : 1);
}
}
use of net.minecraft.inventory.SimpleInventory in project alaskanativecraft by Platymemo.
the class DryingRackBlockEntity method updateItemsBeingDried.
@SuppressWarnings("unused")
public static void updateItemsBeingDried(World world, BlockPos pos, BlockState state, @NotNull DryingRackBlockEntity dryingRackBlockEntity) {
for (int i = 0; i < dryingRackBlockEntity.itemsBeingDried.size(); ++i) {
ItemStack itemStack = dryingRackBlockEntity.itemsBeingDried.get(i);
if (!itemStack.isEmpty()) {
dryingRackBlockEntity.dryingTimes[i]++;
if (dryingRackBlockEntity.dryingTimes[i] >= dryingRackBlockEntity.dryingTotalTimes[i]) {
// Don't want it to keep counting up unnecessarily high
dryingRackBlockEntity.dryingTimes[i] = dryingRackBlockEntity.dryingTotalTimes[i];
Inventory inventory = new SimpleInventory(itemStack);
ItemStack itemStack2 = world.getRecipeManager().getFirstMatch(AlaskaRecipes.DRYING, inventory, world).map((dryingRecipe) -> dryingRecipe.craft(inventory)).orElse(itemStack);
dryingRackBlockEntity.itemsBeingDried.set(i, itemStack2);
dryingRackBlockEntity.updateListeners();
}
}
}
}
use of net.minecraft.inventory.SimpleInventory in project Fabric-Course-118 by Kaupenjoe.
the class OrichalcumBlasterEntity method hasRecipe.
private static boolean hasRecipe(OrichalcumBlasterEntity entity) {
World world = entity.world;
SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
for (int i = 0; i < entity.inventory.size(); i++) {
inventory.setStack(i, entity.getStack(i));
}
Optional<OrichalcumBlasterRecipe> match = world.getRecipeManager().getFirstMatch(OrichalcumBlasterRecipe.Type.INSTANCE, inventory, world);
return match.isPresent() && canInsertAmountIntoOutputSlot(inventory) && canInsertItemIntoOutputSlot(inventory, match.get().getOutput());
}
Aggregations