Skip to content

Commit

Permalink
Start port 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 12, 2023
1 parent dcafb04 commit 52dd20f
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.tonimatasdev.krystalcraft.blockentity.util.EnergyProcessingBlockEntity;
Expand Down Expand Up @@ -68,20 +69,20 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CombiningRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
Optional<RecipeHolder<CombiningRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64;
}

private void craft(Level level) {
Optional<CombiningRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
Optional<RecipeHolder<CombiningRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT1_SLOT, 1);
removeItem(INPUT2_SLOT, 1);
ItemStack result = match.get().getResultItem(level.registryAccess());
ItemStack result = match.get().value().getResultItem(level.registryAccess());
setItem(RESULT_SLOT, new ItemStack(result.getItem(), getItem(RESULT_SLOT).getCount() + result.getCount()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.tonimatasdev.krystalcraft.blockentity.util.BurnProcessingBlockEntity;
Expand Down Expand Up @@ -65,20 +66,20 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CombiningRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
Optional<RecipeHolder<CombiningRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64;
}

private void craft(Level level) {
Optional<CombiningRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);
Optional<RecipeHolder<CombiningRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.COMBINING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT1_SLOT, 1);
removeItem(INPUT2_SLOT, 1);
ItemStack result = match.get().getResultItem(level.registryAccess());
ItemStack result = match.get().value().getResultItem(level.registryAccess());
setItem(RESULT_SLOT, new ItemStack(result.getItem(), getItem(RESULT_SLOT).getCount() + result.getCount()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.tonimatasdev.krystalcraft.blockentity.util.EnergyProcessingBlockEntity;
Expand Down Expand Up @@ -68,19 +69,19 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CrushingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
Optional<RecipeHolder<CrushingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64;
}

private void craft(Level level) {
Optional<CrushingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
Optional<RecipeHolder<CrushingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT_SLOT, 1);
setItem(RESULT_SLOT, new ItemStack(match.get().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
setItem(RESULT_SLOT, new ItemStack(match.get().value().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.tonimatasdev.krystalcraft.blockentity.util.BurnProcessingBlockEntity;
Expand Down Expand Up @@ -63,19 +64,19 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CrushingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
Optional<RecipeHolder<CrushingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64;
}

private void craft(Level level) {
Optional<CrushingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);
Optional<RecipeHolder<CrushingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CRUSHING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT_SLOT, 1);
setItem(RESULT_SLOT, new ItemStack(match.get().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
setItem(RESULT_SLOT, new ItemStack(match.get().value().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
Expand Down Expand Up @@ -100,19 +101,19 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CuttingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
Optional<RecipeHolder<CuttingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || (resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64);
}

private void craft(Level level) {
Optional<CuttingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
Optional<RecipeHolder<CuttingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT_SLOT, 1);
setItem(RESULT_SLOT, new ItemStack(match.get().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
setItem(RESULT_SLOT, new ItemStack(match.get().value().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
Expand Down Expand Up @@ -92,19 +93,19 @@ public void tick() {
}

private boolean hasRecipe(Level level) {
Optional<CuttingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
Optional<RecipeHolder<CuttingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
if (match.isEmpty()) return false;

ItemStack resultItem = match.get().getResultItem(level.registryAccess());
ItemStack resultItem = match.get().value().getResultItem(level.registryAccess());
return (resultItem.is(resultItem.getItem()) || (resultItem.isEmpty()) && (resultItem.getCount() + getItem(RESULT_SLOT).getCount()) <= 64);
}

private void craft(Level level) {
Optional<CuttingRecipe> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);
Optional<RecipeHolder<CuttingRecipe>> match = level.getRecipeManager().getRecipeFor(ModRecipes.CUTTING.get(), this, level);

if (match.isPresent()) {
removeItem(INPUT_SLOT, 1);
setItem(RESULT_SLOT, new ItemStack(match.get().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
setItem(RESULT_SLOT, new ItemStack(match.get().value().getResultItem(level.registryAccess()).getItem(), getItem(RESULT_SLOT).getCount() + 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, in

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
renderBackground(Objects.requireNonNull(guiGraphics));
renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);
renderTooltip(guiGraphics, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mezz.jei.api.registration.IRecipeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.tonimatasdev.krystalcraft.KrystalCraft;
import net.tonimatasdev.krystalcraft.recipe.CombiningRecipe;
Expand All @@ -17,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.stream.Collectors;

@JeiPlugin
public class JEIKrystalCraftModPlugin implements IModPlugin {
Expand All @@ -40,8 +42,8 @@ public void registerCategories(IRecipeCategoryRegistration registration) {
public void registerRecipes(IRecipeRegistration registration) {
RecipeManager manager = Objects.requireNonNull(Minecraft.getInstance().level).getRecipeManager();

registration.addRecipes(CUTTING, manager.getAllRecipesFor(ModRecipes.CUTTING.get()));
registration.addRecipes(CRUSHING, manager.getAllRecipesFor(ModRecipes.CRUSHING.get()));
registration.addRecipes(COMBINING, manager.getAllRecipesFor(ModRecipes.COMBINING.get()));
registration.addRecipes(CUTTING, manager.getAllRecipesFor(ModRecipes.CUTTING.get()).stream().map(RecipeHolder::value).collect(Collectors.toList()));
registration.addRecipes(CRUSHING, manager.getAllRecipesFor(ModRecipes.CRUSHING.get()).stream().map(RecipeHolder::value).collect(Collectors.toList()));
registration.addRecipes(COMBINING, manager.getAllRecipesFor(ModRecipes.COMBINING.get()).stream().map(RecipeHolder::value).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
import org.jetbrains.annotations.NotNull;

public class CombiningRecipe implements Recipe<Container> {

final ResourceLocation id;
private final NonNullList<Ingredient> inputs;
private final ItemStack output;

public CombiningRecipe(ResourceLocation id, NonNullList<Ingredient> inputs, ItemStack output) {
this.id = id;
public CombiningRecipe(NonNullList<Ingredient> inputs, ItemStack output) {
this.inputs = inputs;
this.output = output;
}
Expand Down Expand Up @@ -54,11 +51,6 @@ public boolean canCraftInDimensions(int width, int height) {
return this.output.copy();
}

@Override
public @NotNull ResourceLocation getId() {
return id;
}

@Override
public @NotNull RecipeSerializer<?> getSerializer() {
return ModRecipeSerializers.COMBINING_SERIALIZER.get();
Expand All @@ -79,31 +71,31 @@ public boolean isSpecial() {
return true;
}

public static class Serializer implements RecipeSerializer<CombiningRecipe> {
@Override
public @NotNull CombiningRecipe fromJson(ResourceLocation id, JsonObject json) {
final var ingredients = RecipeUtils.deserializeIngredients(GsonHelper.getAsJsonArray(json, "ingredients"));
if (ingredients.isEmpty()) {
throw new JsonParseException("No ingredients for Combining");
} else if (ingredients.size() > 2) {
throw new JsonParseException("Too many ingredients for Combining");
} else {
return new CombiningRecipe(id, ingredients, ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result")));
}
}

@Override
public @NotNull CombiningRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
final var ingredients = NonNullList.withSize(buf.readVarInt(), Ingredient.EMPTY);
ingredients.replaceAll(ignored -> Ingredient.fromNetwork(buf));
return new CombiningRecipe(id, ingredients, buf.readItem());
}

@Override
public void toNetwork(FriendlyByteBuf buf, CombiningRecipe recipe) {
buf.writeVarInt(recipe.inputs.size());
recipe.inputs.forEach(entry -> entry.toNetwork(buf));
buf.writeItem(recipe.output);
}
}
//public static class Serializer implements RecipeSerializer<CombiningRecipe> { TODO: Finish port
// @Override
// public @NotNull CombiningRecipe fromJson(ResourceLocation id, JsonObject json) {
// final var ingredients = RecipeUtils.deserializeIngredients(GsonHelper.getAsJsonArray(json, "ingredients"));
// if (ingredients.isEmpty()) {
// throw new JsonParseException("No ingredients for Combining");
// } else if (ingredients.size() > 2) {
// throw new JsonParseException("Too many ingredients for Combining");
// } else {
// return new CombiningRecipe(id, ingredients, ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result")));
// }
// }
//
// @Override
// public @NotNull CombiningRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
// final var ingredients = NonNullList.withSize(buf.readVarInt(), Ingredient.EMPTY);
// ingredients.replaceAll(ignored -> Ingredient.fromNetwork(buf));
// return new CombiningRecipe(id, ingredients, buf.readItem());
// }
//
// @Override
// public void toNetwork(FriendlyByteBuf buf, CombiningRecipe recipe) {
// buf.writeVarInt(recipe.inputs.size());
// recipe.inputs.forEach(entry -> entry.toNetwork(buf));
// buf.writeItem(recipe.output);
// }
//}
}
Loading

0 comments on commit 52dd20f

Please sign in to comment.