From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sat, 13 Jan 2024 20:59:28 +0300 Subject: [PATCH] Carpet-Fixes: Sheep Optimization Original project: https://github.com/fxmorin/carpet-fixes diff --git a/src/main/java/net/minecraft/world/entity/animal/Sheep.java b/src/main/java/net/minecraft/world/entity/animal/Sheep.java index 6b1244d3957e7f62c96ffd34692b8916337839fd..994d81bb16040439ecbdf427dfde70d255a9076c 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java +++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java @@ -68,6 +68,7 @@ import net.minecraft.world.item.Item; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.SheepRegrowWoolEvent; import org.bukkit.inventory.InventoryView; +import space.bxteam.divinemc.util.carpetfixes.ProperDyeMixin; // CraftBukkit end public class Sheep extends Animal implements Shearable { @@ -460,21 +461,30 @@ public class Sheep extends Animal implements Shearable { return super.finalizeSpawn(world, difficulty, spawnReason, entityData); } + // DivineMC start - Carpet-Fixes: Sheep Optimization private DyeColor getOffspringColor(Animal firstParent, Animal secondParent) { - DyeColor enumcolor = ((Sheep) firstParent).getColor(); - DyeColor enumcolor1 = ((Sheep) secondParent).getColor(); - CraftingContainer inventorycrafting = Sheep.makeContainer(enumcolor, enumcolor1); - Optional optional = this.level().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventorycrafting, this.level()).map((recipeholder) -> { // CraftBukkit - decompile error - return ((CraftingRecipe) recipeholder.value()).assemble(inventorycrafting, this.level().registryAccess()); - }).map(ItemStack::getItem); - - Objects.requireNonNull(DyeItem.class); - optional = optional.filter(DyeItem.class::isInstance); - Objects.requireNonNull(DyeItem.class); - return (DyeColor) optional.map(DyeItem.class::cast).map(DyeItem::getDyeColor).orElseGet(() -> { - return this.level().random.nextBoolean() ? enumcolor : enumcolor1; - }); + DyeColor firstColor = ((Sheep) firstParent).getColor(); + DyeColor secondColor = ((Sheep) secondParent).getColor(); + + if (space.bxteam.divinemc.configuration.DivineConfig.sheepOptimization) { + DyeColor col = ProperDyeMixin.properDye(firstColor, secondColor); + if (col == null) col = this.level().random.nextBoolean() ? firstColor : secondColor; + return col; + } else { + CraftingContainer inventorycrafting = Sheep.makeContainer(firstColor, secondColor); + Optional optional = this.level().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventorycrafting, this.level()).map((recipeholder) -> { // CraftBukkit - decompile error + return ((CraftingRecipe) recipeholder.value()).assemble(inventorycrafting, this.level().registryAccess()); + }).map(ItemStack::getItem); + + Objects.requireNonNull(DyeItem.class); + optional = optional.filter(DyeItem.class::isInstance); + Objects.requireNonNull(DyeItem.class); + return (DyeColor) optional.map(DyeItem.class::cast).map(DyeItem::getDyeColor).orElseGet(() -> { + return this.level().random.nextBoolean() ? firstColor : secondColor; + }); + } } + // DivineMC end private static CraftingContainer makeContainer(DyeColor firstColor, DyeColor secondColor) { TransientCraftingContainer transientcraftingcontainer = new TransientCraftingContainer(new AbstractContainerMenu((MenuType) null, -1) { diff --git a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java index 73b6c3590dad95cddd9cc1a1cff36492175da232..bf550fa360f69b714ac346333c78d7f8de2a71b9 100644 --- a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java +++ b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java @@ -154,7 +154,9 @@ public class DivineConfig { } public static boolean biomeManagerOptimization = true; + public static boolean sheepOptimization = true; private static void optimizations() { biomeManagerOptimization = getBoolean("settings.optimizations.biome-manager-optimization", biomeManagerOptimization); + sheepOptimization = getBoolean("settings.optimizations.sheep-optimization", sheepOptimization); } } diff --git a/src/main/java/space/bxteam/divinemc/util/carpetfixes/ProperDyeMixin.java b/src/main/java/space/bxteam/divinemc/util/carpetfixes/ProperDyeMixin.java new file mode 100644 index 0000000000000000000000000000000000000000..6cbcf1580312a9275e41813a26b36e42a2481a2c --- /dev/null +++ b/src/main/java/space/bxteam/divinemc/util/carpetfixes/ProperDyeMixin.java @@ -0,0 +1,46 @@ +package space.bxteam.divinemc.util.carpetfixes; + +import net.minecraft.world.item.DyeColor; + +public class ProperDyeMixin { + public static DyeColor properDye(DyeColor firstColor, DyeColor secondColor) { + if (firstColor.equals(secondColor)) return firstColor; + switch (firstColor) { + case WHITE -> { + switch (secondColor) { + case BLUE -> {return DyeColor.LIGHT_BLUE;} + case GRAY -> {return DyeColor.LIGHT_GRAY;} + case BLACK -> {return DyeColor.GRAY;} + case GREEN -> {return DyeColor.LIME;} + case RED -> {return DyeColor.PINK;} + } + } + case BLUE -> { + switch (secondColor) { + case WHITE -> {return DyeColor.LIGHT_BLUE;} + case GREEN -> {return DyeColor.CYAN;} + case RED -> {return DyeColor.PURPLE;} + } + } + case RED -> { + switch (secondColor) { + case YELLOW -> {return DyeColor.ORANGE;} + case WHITE -> {return DyeColor.PINK;} + case BLUE -> {return DyeColor.PURPLE;} + } + } + case GREEN -> { + switch (secondColor) { + case BLUE -> {return DyeColor.CYAN;} + case WHITE -> {return DyeColor.LIME;} + } + } + case YELLOW -> {if (secondColor.equals(DyeColor.RED)) return DyeColor.ORANGE;} + case PURPLE -> {if (secondColor.equals(DyeColor.PINK)) return DyeColor.MAGENTA;} + case PINK -> {if (secondColor.equals(DyeColor.PURPLE)) return DyeColor.MAGENTA;} + case GRAY -> {if (secondColor.equals(DyeColor.WHITE)) return DyeColor.LIGHT_GRAY;} + case BLACK -> {if (secondColor.equals(DyeColor.WHITE)) return DyeColor.GRAY;} + } + return null; + } +}