9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-22 16:29:26 +00:00
Files
Gale/patches/server/0111-Optimize-sheep-offspring-color.patch
2023-08-29 22:39:50 +02:00

124 lines
6.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
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 de850d184d57452529c5b6e2bfe2adf48360be3b..0f8edacfeafb77f722af246a8d9413f82a045cb3 100644
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
@@ -34,6 +34,7 @@ public class GaleWorldConfiguration extends ConfigurationPart {
public class SmallOptimizations extends ConfigurationPart {
public boolean saveFireworks = true; // Gale - EMC - make saving fireworks configurable
+ public boolean useOptimizedSheepOffspringColor = true; // Gale - carpet-fixes - optimize sheep offspring color
// Gale start - Airplane - reduce projectile chunk loading
public MaxProjectileChunkLoads maxProjectileChunkLoads;