Skip to content

Commit

Permalink
1.21.3 is one of the worst updates ever
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Jan 28, 2025
1 parent bc9d573 commit dd729b6
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void search() {
List<Item> items = new ArrayList<>();
searchable.findAll(string.toLowerCase(Locale.ROOT)).forEach(itemStack -> items.add(itemStack.getItem()));
this.handler.getSortedRecipes().forEach(furnitureRecipe -> {
if (items.contains(furnitureRecipe.result().getItem())) {
if (items.contains(furnitureRecipe.getRecipeOuput().getItem())) {
this.handler.getSearchableRecipes().add(furnitureRecipe);
}
});
Expand Down Expand Up @@ -205,15 +205,15 @@ protected void drawMouseoverTooltip(DrawContext context, int x, int y) {
if (this.handler.searching) {
iCopy = this.handler.getSortedRecipes().indexOf(this.handler.getSearchableRecipes().get(iCopy));
}
tooltip.add(getTooltipFromItem(this.handler.getSortedRecipes().get(iCopy).result()).get(0));
tooltip.add(getTooltipFromItem(this.handler.getSortedRecipes().get(iCopy).getRecipeOuput()).get(0));
tooltip.add(Text.translatable("container.pfm.working_table.ingredient_required").setStyle(Style.EMPTY.withItalic(true)));
HashMap<Item, Integer> itemStackCountMap = new HashMap<>();
for (Ingredient ingredient : this.handler.getSortedRecipes().get(iCopy).getIngredients()) {
for (RegistryEntry<Item> item : ingredient.getMatchingItems()) {
if (!itemStackCountMap.containsKey(item.value())) {
itemStackCountMap.put(item.value(), stack.getCount());
itemStackCountMap.put(item.value(), 1);
} else {
itemStackCountMap.put(item.value(), itemStackCountMap.get(item.value()) + stack.getCount());
itemStackCountMap.put(item.value(), itemStackCountMap.get(item.value()) + 1);
}
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ private void renderRecipeIcons(DrawContext context, int x, int y, int scrollOffs
if (this.handler.searching) {
iCopy = this.handler.getSortedRecipes().indexOf(this.handler.getSearchableRecipes().get(iCopy));
}
context.drawItem(this.handler.getSortedRecipes().get(iCopy).result(), xOffset, yOffset);
context.drawItem(this.handler.getSortedRecipes().get(iCopy).getRecipeOuput(), xOffset, yOffset);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
int x = (width - logoWidth) / 2;
int y = (height - logoHeight) / 2;
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
context.drawTexture(identifier -> RenderLayer.getMojangLogo(), pfmLogo, x, y, 0, 0, logoWidth, logoHeight, logoWidth, logoHeight);
context.drawTexture(identifier -> RenderLayer.getGuiTexturedOverlay(pfmLogo), pfmLogo, x, y, 0, 0, logoWidth, logoHeight, logoWidth, logoHeight);

try (Closeable ignored1 = glText.gltBeginDraw()) {
float textScale = (float) (client.getWindow().getScaleFactor() / 2.0f) * 1.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<Widget> setupDisplay(FurnitureDisplay display, Rectangle bounds) {
int recipeIndex = 0;
for (EntryIngredient ingredient : display.getOutputEntries()) {
output.entries(ingredient);
stackToSlotIndex.put(ingredient.get(0), recipeIndex);
stackToSlotIndex.put(ingredient.getFirst(), recipeIndex);
recipeIndex++;
}

Expand All @@ -77,6 +77,7 @@ public List<Widget> setupDisplay(FurnitureDisplay display, Rectangle bounds) {
}
}));
}

widgets.addAll(slots);
return widgets;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
* SOFTWARE.
*/

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.recipes.FurnitureRecipe;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.display.DisplaySerializer;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.Item;
Expand All @@ -47,62 +49,63 @@
public class FurnitureDisplay implements Display {
public static final CategoryIdentifier<FurnitureDisplay> IDENTIFIER = CategoryIdentifier.of(Identifier.of(PaladinFurnitureMod.MOD_ID, "furniture"));
private int itemsPerInnerRecipe;
public FurnitureDisplay(RecipeEntry<FurnitureRecipe> entry) {
this.recipe = entry;
this.itemsPerInnerRecipe = entry.value().getIngredients().size();
public List<EntryIngredient> input;
public List<EntryIngredient> output;
public Optional<Identifier> location;
public FurnitureDisplay(RecipeEntry<FurnitureRecipe> recipeEntry) {
this(recipeEntry.value());
this.location = Optional.of(recipeEntry.id().getValue());
}

private final List<EntryIngredient> inputs = new ArrayList<>();
public FurnitureDisplay(List<EntryIngredient> input, List<EntryIngredient> output, Optional<Identifier> location, int itemsPerInnerRecipe) {
this.input = input;
this.output = output;
this.location = location;
this.itemsPerInnerRecipe = itemsPerInnerRecipe;
}

@Override
public List<EntryIngredient> getInputEntries() {
if (!inputs.isEmpty()) return inputs;
public FurnitureDisplay(FurnitureRecipe recipe) {
input = new ArrayList<>();
output = new ArrayList<>();
List<EntryIngredient> inputEntries = new ArrayList<>();
this.itemsPerInnerRecipe = recipe.getMaxInnerRecipeSize();
for (FurnitureRecipe.CraftableFurnitureRecipe innerRecipe: recipe.getInnerRecipes()) {
Map<Item, Integer> containedItems = innerRecipe.getItemCounts();

List<Ingredient> inputEntries = new ArrayList<>();
this.itemsPerInnerRecipe = recipe.value().getMaxInnerRecipeSize();
for (FurnitureRecipe.CraftableFurnitureRecipe innerRecipe: recipe.value().getInnerRecipes()) {
List<Ingredient> ingredients = innerRecipe.getIngredients();
HashMap<Item, Integer> containedItems = new HashMap<>();
for (Ingredient ingredient : ingredients) {
for (ItemStack stack : ingredient.getMatchingStacks()) {
if (!containedItems.containsKey(stack.getItem())) {
containedItems.put(stack.getItem(), stack.getCount());
} else {
containedItems.put(stack.getItem(), containedItems.get(stack.getItem()) + stack.getCount());
}
}
}
List<Ingredient> finalList = new ArrayList<>();
List<ItemStack> finalList = new ArrayList<>();
for (Map.Entry<Item, Integer> entry: containedItems.entrySet()) {
finalList.add(Ingredient.ofStacks(new ItemStack(entry.getKey(), entry.getValue())));
finalList.add(new ItemStack(entry.getKey(), entry.getValue()));
}
finalList.sort(Comparator.comparing(o -> o.getMatchingStacks()[0].getItem().toString()));
finalList.sort(Comparator.comparing(ItemStack::toString));

if (finalList.size() != itemsPerInnerRecipe) {
while (finalList.size() != itemsPerInnerRecipe) {
finalList.add(Ingredient.EMPTY);
finalList.add(ItemStack.EMPTY);
}
}
inputEntries.addAll(finalList);
}
for (Ingredient ingredient : inputEntries) {
if (!ingredient.isEmpty())
inputs.add(EntryIngredients.ofIngredient(ingredient));
else
inputs.add(EntryIngredient.empty());
List<EntryIngredient> entryIngredients = new ArrayList<>();
for (final ItemStack stack : finalList) {
entryIngredients.add(EntryIngredients.of(stack));
}
inputEntries.addAll(entryIngredients);
}
return inputs;
input.addAll(inputEntries);
output.addAll(recipe.getInnerRecipes().stream().map(FurnitureRecipe.CraftableFurnitureRecipe::getRecipeOuput).map(EntryIngredients::of).toList());
location = Optional.empty();
}

@Override
public List<EntryIngredient> getInputEntries() {
return input;
}

public int itemsPerInnerRecipe() {
return itemsPerInnerRecipe;
}

private final List<EntryIngredient> outputs = new ArrayList<>();
@Override
public List<EntryIngredient> getOutputEntries() {
if (outputs.isEmpty())
outputs.addAll(recipe.value().getInnerRecipes().stream().map(FurnitureRecipe.CraftableFurnitureRecipe::getRecipeOuput).map(EntryIngredients::of).toList());
return outputs;
return output;
}

@Override
Expand All @@ -124,7 +127,8 @@ public Optional<Identifier> getDisplayLocation() {
RecordCodecBuilder.mapCodec(instance -> instance.group(
EntryIngredient.codec().listOf().fieldOf("inputs").forGetter(FurnitureDisplay::getInputEntries),
EntryIngredient.codec().listOf().fieldOf("outputs").forGetter(FurnitureDisplay::getOutputEntries),
Identifier.CODEC.optionalFieldOf("location").forGetter(FurnitureDisplay::getDisplayLocation)
Identifier.CODEC.optionalFieldOf("location").forGetter(FurnitureDisplay::getDisplayLocation),
Codec.INT.fieldOf("itemsPerInnerRecipe").forGetter(FurnitureDisplay::itemsPerInnerRecipe)
).apply(instance, FurnitureDisplay::new)),
PacketCodec.tuple(
EntryIngredient.streamCodec().collect(PacketCodecs.toList()),
Expand All @@ -133,6 +137,8 @@ public Optional<Identifier> getDisplayLocation() {
FurnitureDisplay::getOutputEntries,
PacketCodecs.optional(Identifier.PACKET_CODEC),
FurnitureDisplay::getDisplayLocation,
PacketCodecs.INTEGER,
FurnitureDisplay::itemsPerInnerRecipe,
FurnitureDisplay::new
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Optional<StoneVariant> getVariantFromBlock(Block baseBlock, Identifier bl
String path = blockId.getPath();
if (blockId.getNamespace().equals("tfc")) {
if (path.contains("rock/polished/")) {
Optional<Block> cobble = Registries.BLOCK.getOrEmpty(
Optional<Block> cobble = Registries.BLOCK.getOptionalValue(
Identifier.of(blockId.getNamespace(), path.replace("polished", "raw")));
if (cobble.isPresent()) {
Identifier id = Identifier.of(blockId.getNamespace(), path.replace("rock/polished/", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
public class WorkbenchScreenHandler extends ScreenHandler {
private final ScreenHandlerContext context;
private final List<FurnitureRecipe.CraftableFurnitureRecipe> availableRecipes = Lists.newArrayList();
public static ArrayList<FurnitureRecipe.CraftableFurnitureRecipe> ALL_RECIPES = Lists.newArrayList();
public static ArrayList<FurnitureRecipe> ALL_RECIPES = Lists.newArrayList();
public static ArrayList<FurnitureRecipe.CraftableFurnitureRecipe> CRAFTABLE_RECIPES = Lists.newArrayList();
private final List<FurnitureRecipe.CraftableFurnitureRecipe> sortedRecipes = Lists.newArrayList();
private final List<FurnitureRecipe.CraftableFurnitureRecipe> searchableRecipes = Lists.newArrayList();

Expand Down Expand Up @@ -85,11 +86,18 @@ public void onTakeItem(PlayerEntity player, ItemStack stack) {
}
this.addProperty(this.selectedRecipe);
if (world instanceof ServerWorld) {
world.getRecipeManager().listAllOfType(RecipeTypes.FURNITURE_RECIPE).stream().map(RecipeEntry::value).forEach(recipe -> {
ALL_RECIPES.addAll(recipe.getInnerRecipes());
});
ALL_RECIPES.sort(FurnitureRecipe.CraftableFurnitureRecipe::compareTo);
if (ALL_RECIPES.isEmpty()) {
((ServerRecipeManagerAccessor)((ServerWorld)world).getRecipeManager()).getPreparedRecipes().getAll(RecipeTypes.FURNITURE_RECIPE).stream().map(RecipeEntry::value).forEach(recipe -> {
ALL_RECIPES.add(recipe);
CRAFTABLE_RECIPES.addAll(recipe.getInnerRecipes());
});
} else {
for (FurnitureRecipe recipe : ALL_RECIPES) {
CRAFTABLE_RECIPES.addAll(recipe.getInnerRecipes());
}
}
sendSyncRecipesPayload(playerInventory.player, world, ALL_RECIPES);
CRAFTABLE_RECIPES.sort(FurnitureRecipe.CraftableFurnitureRecipe::compareTo);
}
this.updateInput();
selectedRecipe.set(-1);
Expand All @@ -101,7 +109,12 @@ public static void sendSyncRecipesPayload(PlayerEntity player, World world, Arra
}

public void setAllRecipes(List<FurnitureRecipe> recipes) {
allRecipes = new ArrayList<>(recipes);
ALL_RECIPES = new ArrayList<>(recipes);
CRAFTABLE_RECIPES = new ArrayList<>();
for (FurnitureRecipe recipe : ALL_RECIPES) {
CRAFTABLE_RECIPES.addAll(recipe.getInnerRecipes());
}
CRAFTABLE_RECIPES.sort(FurnitureRecipe.CraftableFurnitureRecipe::compareTo);
}

boolean craft() {
Expand Down Expand Up @@ -156,7 +169,7 @@ public List<FurnitureRecipe.CraftableFurnitureRecipe> getSortedRecipes() {
}

public List<FurnitureRecipe.CraftableFurnitureRecipe> getAllRecipes() {
return ALL_RECIPES;
return CRAFTABLE_RECIPES;
}

public int getAvailableRecipeCount() {
Expand All @@ -182,11 +195,11 @@ public void updateInput() {
}
// Reset the available recipes list and add all recipes that can be crafted
this.availableRecipes.clear();
this.availableRecipes.addAll(ALL_RECIPES.stream().filter(newFurnitureRecipe -> newFurnitureRecipe.matches(input, world)).toList());
this.availableRecipes.addAll(CRAFTABLE_RECIPES.stream().filter(newFurnitureRecipe -> newFurnitureRecipe.matches(input, world)).toList());
// Clear the visible recipe list and add the craft-able recipes first, then add the rest, checking that it's not present already so that it's not overridden.
this.sortedRecipes.clear();
this.sortedRecipes.addAll(availableRecipes);
this.sortedRecipes.addAll(ALL_RECIPES.stream().filter(furnitureRecipe -> !sortedRecipes.contains(furnitureRecipe)).toList());
this.sortedRecipes.addAll(CRAFTABLE_RECIPES.stream().filter(furnitureRecipe -> !sortedRecipes.contains(furnitureRecipe)).toList());
}

public boolean canCraft() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.unlikepaladin.pfm.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.tracy.TracyFrameCapturer;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(MinecraftClient.class)
public interface PFMMinecraftClientAcccessor {
@Nullable
@Accessor("tracyFrameCapturer")
TracyFrameCapturer getFrameCapturer();
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package com.unlikepaladin.pfm.networking;

import com.unlikepaladin.pfm.recipes.DynamicFurnitureRecipe;
import com.unlikepaladin.pfm.recipes.FurnitureRecipe;
import com.unlikepaladin.pfm.recipes.SimpleFurnitureRecipe;
import com.unlikepaladin.pfm.registry.NetworkIDs;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;

import java.util.ArrayList;
import java.util.Objects;

public record SyncRecipesPayload(ArrayList<FurnitureRecipe> recipes) implements CustomPayload {
public final class SyncRecipesPayload implements CustomPayload {
public static final PacketCodec<RegistryByteBuf, SyncRecipesPayload> PACKET_CODEC = CustomPayload.codecOf(SyncRecipesPayload::write, SyncRecipesPayload::new);
private final ArrayList<FurnitureRecipe> recipes;

public SyncRecipesPayload(ArrayList<FurnitureRecipe> recipes) {
this.recipes = recipes;
}

public SyncRecipesPayload(RegistryByteBuf buf) {
this((ArrayList<FurnitureRecipe>) buf.readCollection(ArrayList::new, buf1 -> FurnitureRecipe.Serializer.read(buf)));
int recipeCount = buf.readInt();
this.recipes = new ArrayList<>(recipeCount);
for (int i = 0; i < recipeCount; i++) {
int j = buf.readInt();
if (j == 0) {
recipes.add(SimpleFurnitureRecipe.Serializer.read(buf));
} else {
recipes.add(DynamicFurnitureRecipe.Serializer.read(buf));
}
}
}

@Override
Expand All @@ -21,10 +38,43 @@ public Id<? extends CustomPayload> getId() {
}

public void write(RegistryByteBuf buf) {
buf.writeCollection(recipes, (registry, recipe) -> FurnitureRecipe.Serializer.write((RegistryByteBuf) registry, recipe));
buf.writeInt(recipes.size());
for (FurnitureRecipe recipe : recipes) {
if (recipe instanceof DynamicFurnitureRecipe) {
buf.writeInt(1);
recipe.write(buf);
} else {
buf.writeInt(0);
recipe.write(buf);
}
}
}

public void handle() {
ClientSyncRecipesPayloadHandler.handlePacket(this.recipes);
}

public ArrayList<FurnitureRecipe> recipes() {
return recipes;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (SyncRecipesPayload) obj;
return Objects.equals(this.recipes, that.recipes);
}

@Override
public int hashCode() {
return Objects.hash(recipes);
}

@Override
public String toString() {
return "SyncRecipesPayload[" +
"recipes=" + recipes + ']';
}

}
Loading

0 comments on commit dd729b6

Please sign in to comment.