diff options
| author | Shnupbups <shnupbups@gmail.com> | 2022-07-14 15:26:05 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-14 13:26:05 +0800 |
| commit | 99ad86acb465c95d10c51672564502666b8b16dc (patch) | |
| tree | 4513b6f4dc1c2020ca42e15bcc63476aa1d7d361 /default-plugin/src/main/java | |
| parent | 550fd78f9ed2dd3fdb6f34feed41f87e478fdd22 (diff) | |
| download | RoughlyEnoughItems-99ad86acb465c95d10c51672564502666b8b16dc.tar.gz RoughlyEnoughItems-99ad86acb465c95d10c51672564502666b8b16dc.tar.bz2 RoughlyEnoughItems-99ad86acb465c95d10c51672564502666b8b16dc.zip | |
Improvements to Composting category (#975)
* improvements to composting category
1. Fixed the chance tooltip not showing up
2. `DefaultCompostingDisplay.of` is no longer used and has been deprecated
3. Page count is kept track of internally and used to avoid having to specify the page number manually in a constructor, as a result the constructors that do specify it have been marked as internal as they should only be used by the serializer, but remain public for backwards compatibility with anything that may use them
* am i have stupid
* forRemoval
Diffstat (limited to 'default-plugin/src/main/java')
3 files changed, 33 insertions, 18 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index cdb3fd883..d4c1877b3 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -261,11 +261,10 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin if (ComposterBlock.COMPOSTABLES.isEmpty()) { ComposterBlock.bootStrap(); } - int page = 0; - Iterator<List<Object2FloatMap.Entry<ItemLike>>> iterator = Iterators.partition(ComposterBlock.COMPOSTABLES.object2FloatEntrySet().stream().sorted(Map.Entry.comparingByValue()).iterator(), 35); + Iterator<List<EntryIngredient>> iterator = Iterators.partition(ComposterBlock.COMPOSTABLES.object2FloatEntrySet().stream().sorted(Map.Entry.comparingByValue()).map(entry -> EntryIngredients.of(entry.getKey())).iterator(), 35); while (iterator.hasNext()) { - List<Object2FloatMap.Entry<ItemLike>> entries = iterator.next(); - registry.add(DefaultCompostingDisplay.of(entries, Collections.singletonList(EntryIngredients.of(new ItemStack(Items.BONE_MEAL))), page++)); + List<EntryIngredient> entries = iterator.next(); + registry.add(new DefaultCompostingDisplay(entries, Collections.singletonList(EntryIngredients.of(new ItemStack(Items.BONE_MEAL))))); } DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { registry.add(new DefaultStrippingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue()))); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java index ab65b6ccc..4962c4394 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java @@ -34,7 +34,6 @@ import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.plugin.common.BuiltinPlugin; import me.shedaniel.rei.plugin.common.displays.DefaultCompostingDisplay; @@ -44,13 +43,13 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.ComposterBlock; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; @Environment(EnvType.CLIENT) public class DefaultCompostingCategory implements DisplayCategory<DefaultCompostingDisplay> { @@ -95,15 +94,15 @@ public class DefaultCompostingCategory implements DisplayCategory<DefaultCompost int i = 0; for (int y = 0; y < 5; y++) for (int x = 0; x < 7; x++) { - EntryIngredient entryStack = stacks.size() > i ? stacks.get(i) : EntryIngredient.empty(); - if (!entryStack.isEmpty()) { - ComposterBlock.COMPOSTABLES.object2FloatEntrySet().stream().filter(entry -> entry.getKey() != null && Objects.equals(entry.getKey().asItem(), entryStack.get(0).getValue())).findAny().map(Map.Entry::getValue).ifPresent(chance -> { - for (EntryStack<?> stack : entryStack) { - stack.tooltip(Component.translatable("text.rei.composting.chance", Mth.fastFloor(chance * 100)).withStyle(ChatFormatting.YELLOW)); - } - }); + EntryIngredient entryIngredient = stacks.size() > i ? stacks.get(i) : EntryIngredient.empty(); + if (!entryIngredient.isEmpty()) { + ItemStack firstStack = (ItemStack) entryIngredient.get(0).getValue(); + float chance = ComposterBlock.COMPOSTABLES.getFloat(firstStack.getItem()); + if (chance > 0.0f) { + entryIngredient = entryIngredient.map(stack -> stack.copy().tooltip(Component.translatable("text.rei.composting.chance", Mth.clamp(Mth.fastFloor(chance * 100), 0, 100)).withStyle(ChatFormatting.YELLOW))); + } } - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 72 + 9 + x * 18, bounds.y + 12 + y * 18)).entries(entryStack).markInput()); + widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 72 + 9 + x * 18, bounds.y + 12 + y * 18)).entries(entryIngredient).markInput()); i++; } widgets.add(Widgets.createArrow(new Point(startingPoint.x - 1 - 5, startingPoint.y + 7 - 5))); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java index 4862c27c8..bbf31cb38 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java @@ -24,6 +24,8 @@ package me.shedaniel.rei.plugin.common.displays; import it.unimi.dsi.fastutil.objects.Object2FloatMap; +import org.jetbrains.annotations.ApiStatus; + import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.api.common.entry.EntryIngredient; @@ -36,8 +38,11 @@ import java.util.Arrays; import java.util.List; public class DefaultCompostingDisplay extends BasicDisplay { - private int page; - + private static int pages; + + private final int page; + + @Deprecated(forRemoval = true) public static DefaultCompostingDisplay of(List<Object2FloatMap.Entry<ItemLike>> inputs, List<EntryIngredient> output, int page) { EntryIngredient[] inputIngredients = new EntryIngredient[inputs.size()]; int i = 0; @@ -47,19 +52,31 @@ public class DefaultCompostingDisplay extends BasicDisplay { } return new DefaultCompostingDisplay(Arrays.asList(inputIngredients), output, page); } - + + @ApiStatus.Internal public DefaultCompostingDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs, CompoundTag tag) { this(inputs, outputs, tag.getInt("page")); } - + + public DefaultCompostingDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs) { + super(inputs, outputs); + this.page = pages++; + } + + @ApiStatus.Internal public DefaultCompostingDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs, int page) { super(inputs, outputs); this.page = page; + if (pages <= page) pages = page + 1; } public int getPage() { return page; } + + public static int getPages() { + return pages; + } @Override public CategoryIdentifier<?> getCategoryIdentifier() { |
