From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Fri, 23 Dec 2022 22:47:38 +0100 Subject: [PATCH] Optimize sheep offspring color License: MIT (https://opensource.org/licenses/MIT) Gale - https://galemc.org 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) * carpet-fixes 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. * carpet-fixes copyright * MIT License Copyright (c) 2020 Fx Morin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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 c0e89262c596fbdd0bb3c3f76baccb17a1bb5fcd..d8f99e1221609d481ee79ee31f645731f34e1021 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java +++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java @@ -392,7 +392,59 @@ public class Sheep extends Animal implements Shearable { return super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityNbt); } + // Gale start - carpet-fixes - optimize sheep offspring color + 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; + } + // Gale end - carpet-fixes - optimize sheep offspring color + private DyeColor getOffspringColor(Animal firstParent, Animal secondParent) { + // Gale start - carpet-fixes - optimize sheep offspring color + if (firstParent.level() != null && firstParent.level().galeConfig().smallOptimizations.useOptimizedSheepOffspringColor) { + DyeColor firstColor = ((Sheep)firstParent).getColor(); + DyeColor secondColor = ((Sheep)secondParent).getColor(); + DyeColor col = properDye(firstColor,secondColor); + if (col == null) col = this.level().random.nextBoolean() ? firstColor : secondColor; + return col; + } + // Gale end - carpet-fixes - optimize sheep offspring color DyeColor enumcolor = ((Sheep) firstParent).getColor(); DyeColor enumcolor1 = ((Sheep) secondParent).getColor(); CraftingContainer inventorycrafting = Sheep.makeContainer(enumcolor, enumcolor1); diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java index c57275584b56d9d32d4b5f303423ffeb1de19854..7be0e4c7a54e858db93a6ac45517533d4b040a8c 100644 --- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java +++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java @@ -47,6 +47,21 @@ public class GaleWorldConfiguration extends ConfigurationPart { public boolean saveFireworks = true; // Gale end - EMC - make saving fireworks configurable + // Gale start - carpet-fixes - optimize sheep offspring color + /** + * Whether to use a (much) faster way to choose a color when a new baby sheep is born. + * The color chosen is exactly the same as vanilla. + * However, in vanilla, it is possible to change the new color by + * changing the crafting recipe for combining dyes using a data pack. + * If this is set to true, any such crafting recipe changes will be ignored. + * + */ + public boolean useOptimizedSheepOffspringColor = true; + // Gale end - carpet-fixes - optimize sheep offspring color + // Gale start - Airplane - reduce projectile chunk loading public MaxProjectileChunkLoads maxProjectileChunkLoads; public class MaxProjectileChunkLoads extends ConfigurationPart {