Skip to content

Commit

Permalink
wip: Continue port to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 21, 2024
1 parent fa33d40 commit 20992da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean canPlaceItem(int slot, ItemStack itemStack) {
if (slot < 3) {
return !getSmeltingResult(itemStack).isEmpty();
} else if (slot == 3) {
return isItemFuel(itemStack);
return isItemFuel(level, itemStack);
}
return true;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
ItemStack fuelItem = fuelContainer.getItem(i);
if (!fuelItem.isEmpty()) {
currentItemBurnTime = furnaceBurnTime = (int) Math.max(1,
(float) getBurnTime(fuelItem) * CookingForBlockheadsConfig.getActive().ovenFuelTimeMultiplier);
(float) getBurnTime(level, fuelItem) * CookingForBlockheadsConfig.getActive().ovenFuelTimeMultiplier);
if (furnaceBurnTime != 0) {
ItemStack containerItem = Balm.getHooks().getCraftingRemainingItem(fuelItem);
fuelItem.shrink(1);
Expand Down Expand Up @@ -290,10 +290,10 @@ public ItemStack getSmeltingResult(ItemStack itemStack) {
return getSmeltingResult(RecipeType.SMELTING, recipeInput);
}

public <T extends RecipeInput> ItemStack getSmeltingResult(RecipeType<? extends Recipe<T>> recipeType, T container) {
RecipeHolder<?> recipe = level.getServer().getRecipeManager().getRecipeFor(recipeType, container, this.level).orElse(null);
public <T extends RecipeInput> ItemStack getSmeltingResult(RecipeType<? extends Recipe<T>> recipeType, T recipeInput) {
final var recipe = level.getServer().getRecipeManager().getRecipeFor(recipeType, recipeInput, level).orElse(null);
if (recipe != null) {
final var result = recipe.value().assemble(level.registryAccess());
final var result = recipe.value().assemble(recipeInput, level.registryAccess());
if (!result.isEmpty() && result.has(DataComponents.FOOD)) {
return result;
}
Expand All @@ -302,15 +302,15 @@ public <T extends RecipeInput> ItemStack getSmeltingResult(RecipeType<? extends
return ItemStack.EMPTY;
}

public static boolean isItemFuel(ItemStack itemStack) {
public static boolean isItemFuel(Level level, ItemStack itemStack) {
if (CookingForBlockheadsConfig.getActive().ovenRequiresCookingOil) {
return itemStack.is(BalmItemTags.COOKING_OIL);
}

return getBurnTime(itemStack) > 0;
return getBurnTime(level, itemStack) > 0;
}

protected static int getBurnTime(ItemStack itemStack) {
protected static int getBurnTime(Level level, ItemStack itemStack) {
if (itemStack.isEmpty()) {
return 0;
}
Expand All @@ -319,7 +319,7 @@ protected static int getBurnTime(ItemStack itemStack) {
return 800;
}

return Balm.getHooks().getBurnTime(itemStack);
return Balm.getHooks().getBurnTime(level, itemStack);
}

private boolean shouldConsumeFuel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public OvenMenu(int windowId, Inventory playerInventory, OvenBlockEntity oven) {
addSlot(new Slot(container, i, 84 + i * 18 + offsetX, 19));
}

addSlot(new SlotOvenFuel(container, 3, 61 + offsetX, 59));
addSlot(new SlotOvenFuel(this, container, 3, 61 + offsetX, 59));

for (int i = 0; i < 3; i++) {
addSlot(new OvenResultSlot(playerInventory.player, oven, container, i + 4, 142 + offsetX, 41 + i * 18));
Expand Down Expand Up @@ -88,7 +88,7 @@ public ItemStack quickMoveStack(Player player, int slotIndex) {
slot.onQuickCraft(slotStack, itemStack);
} else if (slotIndex >= 20) {
ItemStack smeltingResult = oven.getSmeltingResult(slotStack);
if (OvenBlockEntity.isItemFuel(slotStack)) {
if (isFuel(slotStack)) {
if (!moveItemStackTo(slotStack, 3, 4, false)) {
return ItemStack.EMPTY;
}
Expand Down Expand Up @@ -132,4 +132,8 @@ public boolean stillValid(Player player) {
public boolean isTileEntity(BlockEntity blockEntity) {
return this.oven == blockEntity;
}

public boolean isFuel(ItemStack itemStack) {
return OvenBlockEntity.isItemFuel(oven.getLevel(), itemStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package net.blay09.mods.cookingforblockheads.menu.slot;

import net.blay09.mods.cookingforblockheads.block.entity.OvenBlockEntity;
import net.blay09.mods.cookingforblockheads.menu.OvenMenu;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

public class SlotOvenFuel extends Slot {

public SlotOvenFuel(Container container, int i, int x, int y) {
private final OvenMenu menu;

public SlotOvenFuel(OvenMenu menu, Container container, int i, int x, int y) {
super(container, i, x, y);
this.menu = menu;
}

@Override
public boolean mayPlace(ItemStack itemStack) {
return OvenBlockEntity.isItemFuel(itemStack);
return menu.isFuel(itemStack);
}

}

0 comments on commit 20992da

Please sign in to comment.