From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Thu, 8 May 2025 16:49:29 +0300 Subject: [PATCH] Carpet-Fixes: Sheep Optimization This patch is based on the following mixins and classes: * "carpetfixes/helpers/Utils.java" * "carpetfixes/mixins/optimizations/SheepEntity_childColorMixin.java" By: fxmorin <28154542+fxmorin@users.noreply.github.com> As part of: carpet-fixes (https://github.com/fxmorin/carpet-fixes) Licensed under: MIT (https://opensource.org/licenses/MIT) Patch description: The game determines the child sheep's color by getting a wool block from the parents, putting them in a crafting recipe, getting the output wool and getting the color from that. I don't know in what world we would consider a data-driven method with that much overhead as a smart idea. Instead, we used a prebaked list of all the possible colors and combinations, however this means that you can't use a datapack to change it. diff --git a/net/minecraft/world/item/DyeColor.java b/net/minecraft/world/item/DyeColor.java index 6bac07817d2916c64f703586599a2cab226872e6..0b6eb7da40b1dc956da06abfb6145a69525fb89b 100644 --- a/net/minecraft/world/item/DyeColor.java +++ b/net/minecraft/world/item/DyeColor.java @@ -112,6 +112,15 @@ public enum DyeColor implements StringRepresentable { } public static DyeColor getMixedColor(ServerLevel level, DyeColor first, DyeColor second) { + // DivineMC start - Carpet-Fixes: Sheep Optimization + if (org.bxteam.divinemc.DivineConfig.sheepOptimization) { + DyeColor col = properDye(first, second); + + if (col == null) col = level.random.nextBoolean() ? first : second; + + return col; + } + // DivineMC end - Carpet-Fixes: Sheep Optimization CraftingInput craftingInput = makeCraftColorInput(first, second); return level.recipeAccess() .getRecipeFor(RecipeType.CRAFTING, craftingInput, level) @@ -132,4 +141,85 @@ public enum DyeColor implements StringRepresentable { return values()[random.nextInt(values().length)]; } // Purpur end - Shulker spawn from bullet options + + // DivineMC start - Carpet-Fixes: Sheep Optimization + private 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; + } + // DivineMC end - Carpet-Fixes: Sheep Optimization }