use of net.minecraft.inventory.Inventory in project Overloaded by CJ-MC-Mods.
the class EnergyInventoryBasedRecipeProcessor method processRecipeAndStoreOutput.
private ItemStack processRecipeAndStoreOutput(ItemStack stack, boolean simulate) {
Inventory inventory = new Inventory(stack.copy());
List<T> recipesForInput = getRecipe(inventory);
if (recipesForInput.isEmpty()) {
return inventory.getItem(0);
}
T recipe = recipesForInput.get(0);
ItemStack result;
while (!inventory.getItem(0).isEmpty() && !(result = recipe.assemble(inventory)).isEmpty()) {
int energyCost = energyCostPerRecipeOperation(recipe);
if (energyCost != this.extractEnergy(energyCost, true)) {
break;
}
ItemStack outputLeftOvers = insertItem(output, result, true);
if (!outputLeftOvers.isEmpty()) {
break;
}
insertItem(output, result, simulate);
this.extractEnergy(energyCost, simulate);
int deduct = recipe.getIngredients().get(0).getItems()[0].getCount();
inventory.getItem(0).shrink(deduct);
}
return inventory.getItem(0);
// NonNullList<ItemStack> leftOvers = recipe.getRemainingItems(inventory);
//
// if (leftOvers.isEmpty() || leftOvers.stream().allMatch(ItemStack::isEmpty)) {
// return ItemStack.EMPTY;
// }
// if (leftOvers.size() > 1) {
// Overloaded.logger.warn(
// "Deleting Item due to to many recipe leftovers. Items: "
// + leftOvers.subList(1, leftOvers.size() - 1).stream()
// .map(ItemStack::toString)
// .collect(Collectors.joining(",")));
// }
// return leftOvers.get(0);
}
use of net.minecraft.inventory.Inventory in project nbt-crafting by Siphalor.
the class MixinBrewingSlotPotion method canInsert.
@Inject(method = "canInsert(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true)
public void canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (callbackInfoReturnable.getReturnValue() || matches(stack)) {
callbackInfoReturnable.setReturnValue(true);
return;
}
RecipeManagerAccessor recipeManager;
if (inventory instanceof BrewingStandBlockEntity) {
recipeManager = (RecipeManagerAccessor) ((BrewingStandBlockEntity) inventory).getWorld().getRecipeManager();
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
recipeManager = (RecipeManagerAccessor) NbtCraftingClient.getClientRecipeManager();
} else {
NbtCrafting.logError("Failed to get recipe manager in brewing stand container class!");
return;
}
Map<Identifier, Recipe<Inventory>> recipes = recipeManager.callGetAllOfType(NbtCrafting.BREWING_RECIPE_TYPE);
callbackInfoReturnable.setReturnValue(recipes.values().stream().anyMatch(recipe -> recipe instanceof BrewingRecipe && ((BrewingRecipe) recipe).getBase().test(stack)));
}
use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.
the class PcaSyncUtil method sync.
public static void sync(List<Box> boxes) {
ClientWorld world = MinecraftClient.getInstance().world;
if (world == null) {
return;
}
PcaSyncUtil.lastUpdatePos = null;
BlockPos lastUpdatePos = null;
for (Box box : boxes) {
BlockPos pos1 = box.getPos1();
BlockPos pos2 = box.getPos2();
if (pos1 == null || pos2 == null) {
continue;
}
int maxX = Math.max(pos1.getX(), pos2.getX());
int maxY = Math.max(pos1.getY(), pos2.getY());
int maxZ = Math.max(pos1.getZ(), pos2.getZ());
int minX = Math.min(pos1.getX(), pos2.getX());
int minY = Math.min(pos1.getY(), pos2.getY());
int minZ = Math.min(pos1.getZ(), pos2.getZ());
// 参考 PositionUtils。createAABBFrom
List<Entity> entities = world.getOtherEntities(null, PositionUtils.createAABB(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1), EntityUtils.NOT_PLAYER);
for (Entity entity : entities) {
if (entity instanceof Inventory) {
PcaSyncProtocol.syncEntity(entity.getId());
}
}
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
BlockPos pos = new BlockPos(x, y, z);
if (world.getBlockEntity(pos) != null) {
lastUpdatePos = pos;
PcaSyncProtocol.syncBlockEntity(pos);
}
}
}
}
}
PcaSyncProtocol.cancelSyncBlockEntity();
PcaSyncProtocol.cancelSyncEntity();
PcaSyncUtil.lastUpdatePos = lastUpdatePos;
}
use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.
the class MixinRenderUtils method modifyInv.
@ModifyVariable(method = "renderInventoryOverlay", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", ordinal = 0, remap = false), ordinal = 0)
private static Inventory modifyInv(Inventory inv) {
Inventory ret = inv;
Entity traceEntity = TraceUtil.getTraceEntity();
if (Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_SHULKER_BOX_ITEM_ENTITY.getBooleanValue() && ret == null && traceEntity instanceof ItemEntity) {
ItemStack itemStack = ((ItemEntity) traceEntity).getStack();
Item item = itemStack.getItem();
NbtCompound invNbt = itemStack.getSubNbt("BlockEntityTag");
DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) {
ret = new SimpleInventory(27);
if (invNbt != null) {
Inventories.readNbt(invNbt, stacks);
}
for (int i = 0; i < 27; ++i) {
ret.setStack(i, stacks.get(i));
}
}
}
return ret;
}
use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.
the class MixinWorldUtils method checkInventory.
@Inject(method = "handleEasyPlace", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 0), cancellable = true)
private static void checkInventory(MinecraftClient mc, CallbackInfoReturnable<Boolean> cir) {
if (!Configs.Litematica.BETTER_EASY_PLACE_MODE.getBooleanValue() || mc.world == null) {
return;
}
HitResult trace = mc.crosshairTarget;
if (trace != null && trace.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHitResult = (BlockHitResult) trace;
BlockPos pos = blockHitResult.getBlockPos();
Block block = mc.world.getBlockState(pos).getBlock();
if (block == Blocks.BEACON || mc.world.getBlockEntity(pos) instanceof Inventory) {
cir.setReturnValue(false);
}
}
}
Aggregations