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 17b49186293578c06144a476473324a9a1f6fcbb..f073d0657855e70f70c33ec7c7bf82388570e3d2 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java +++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java @@ -66,6 +66,7 @@ import net.minecraft.world.item.DyeItem; import net.minecraft.world.item.Item; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.SheepRegrowWoolEvent; +import space.bxteam.divinemc.util.carpetfixes.ProperDyeMixin; // DivineMC // CraftBukkit end public class Sheep extends Animal implements Shearable { @@ -459,20 +460,28 @@ 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(); - CraftingInput craftinginput = Sheep.makeCraftInput(enumcolor, enumcolor1); - Optional optional = this.level().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftinginput, this.level()).map((recipeholder) -> { // CraftBukkit - decompile error - return ((CraftingRecipe) recipeholder.value()).assemble(craftinginput, 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 { + CraftingInput craftinginput = Sheep.makeCraftInput(firstColor, secondColor); + Optional optional = this.level().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftinginput, this.level()).map((recipeholder) -> { // CraftBukkit - decompile error + return ((CraftingRecipe) recipeholder.value()).assemble(craftinginput, 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; + }); + } } private static CraftingInput makeCraftInput(DyeColor firstColor, DyeColor secondColor) { diff --git a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java index 641a957cfda8de6f4114350393f441f2f3b9c8dd..75adcde96d7924fa1892462e66ffe16476735658 100644 --- a/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java +++ b/src/main/java/space/bxteam/divinemc/configuration/DivineConfig.java @@ -161,10 +161,12 @@ public class DivineConfig { public static boolean biomeManagerOptimization = true; public static boolean optimizedDragonRespawn = true; public static boolean optimizeNoiseGeneration = true; + public static boolean sheepOptimization = true; private static void optimizations() { biomeManagerOptimization = getBoolean("settings.optimizations.biome-manager-optimization", biomeManagerOptimization); optimizedDragonRespawn = getBoolean("settings.optimizations.optimized-dragon-respawn", optimizedDragonRespawn); optimizeNoiseGeneration = getBoolean("settings.optimizations.optimize-noise-generation", optimizeNoiseGeneration); + sheepOptimization = getBoolean("settings.optimizations.sheep-optimization", sheepOptimization); } public static boolean asyncPathfinding = true; 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; + } +}