Skip to content

Commit

Permalink
5.1.1 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
Traben-0 committed Jan 2, 2024
1 parent 68ff90c commit bda9fa5
Show file tree
Hide file tree
Showing 45 changed files with 566 additions and 533 deletions.
9 changes: 9 additions & 0 deletions common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[**ETF Changelog:**]


[5.1.1]
- fixed 3d skin layers mod & etf skin feature, compat for the 1.6 update *(also removed log warning spam for future changes to 3d skin layers)*.
- restructured the config
- generified the emissive and enchanted pixel rendering methods
- the mini entities in mob spawners UUID's should now always use the following format in nbt *("[I;?,?,12345,12345]")*
making them identifiable for randomisation, the blocks property should also return the actual mob spawner block.


[5.1]

- mob spawner entities can now variate their textures again.
Expand Down
14 changes: 9 additions & 5 deletions common/src/main/java/traben/entity_texture_features/ETFApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public final class ETFApi {
* @return the etf config object
*/
public static ETFConfig getETFConfigObject() {
return ETFClientCommon.ETFConfigData;
return ETFConfig.getInstance();
}

/**
Expand All @@ -97,8 +97,12 @@ public static ETFConfig getETFConfigObject() {
* @param newETFConfig the new ETF config to be saved and used by ETF
*/
public static void setETFConfigObject(ETFConfig newETFConfig) {
ETFClientCommon.ETFConfigData = newETFConfig;
saveETFConfigChangesAndResetETF();
if(newETFConfig != null) {
ETFConfig.setInstance(newETFConfig);
saveETFConfigChangesAndResetETF();
}else{
ETFUtils2.logError("new config was null: ignoring.");
}
}

/**
Expand All @@ -107,7 +111,7 @@ public static void setETFConfigObject(ETFConfig newETFConfig) {
* @return the copy of ETF's current config object
*/
public static ETFConfig getCopyOfETFConfigObject() {
return ETFConfig.copyFrom(ETFClientCommon.ETFConfigData);
return ETFConfig.copyFrom(ETFConfig.getInstance());
}

/**
Expand All @@ -123,7 +127,7 @@ public static ETFConfig getDefaultETFConfigObject() {
* saves any config changes to the live ETF config to file and resets ETF to function with the new settings
*/
public static void saveETFConfigChangesAndResetETF() {
ETFUtils2.saveConfig();
ETFConfig.saveConfig();
ETFManager.resetInstance();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package traben.entity_texture_features;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.client.render.LightmapTextureManager;
import org.slf4j.Logger;
import traben.entity_texture_features.config.ETFConfig;
import traben.entity_texture_features.utils.ETFUtils2;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;


Expand All @@ -23,19 +19,19 @@ public class ETFClientCommon {

public static final int EMISSIVE_FEATURE_LIGHT_VALUE = LightmapTextureManager.MAX_LIGHT_COORDINATE + 2;
public static boolean IRIS_DETECTED = false;
//config object
public static ETFConfig ETFConfigData = new ETFConfig();


//sets whether to display config load warning in gui
public static boolean configHadLoadError = false;
public static boolean SKIN_LAYERS_DETECTED = false;

public static void start() {
//check only once
SKIN_LAYERS_DETECTED = (ETFVersionDifferenceHandler.isThisModLoaded("skinlayers") || ETFVersionDifferenceHandler.isThisModLoaded("skinlayers3d"));
SKIN_LAYERS_DETECTED = ETFVersionDifferenceHandler.isThisModLoaded("skinlayers3d");
IRIS_DETECTED = ETFVersionDifferenceHandler.isThisModLoaded("iris") || ETFVersionDifferenceHandler.isThisModLoaded("oculus");

LOGGER.info("Loading Entity Texture Features, " + randomQuip());
etf$loadConfig();
ETFConfig.loadConfig();
ETFUtils2.checkModCompatibility();
}

Expand Down Expand Up @@ -78,36 +74,6 @@ private static String[] getQuips() {
// config code based on bedrockify & actually unbreaking fabric config code
// https://github.com/juancarloscp52/BedrockIfy/blob/1.17.x/src/main/java/me/juancarloscp52/bedrockify/Bedrockify.java
// https://github.com/wutdahack/ActuallyUnbreakingFabric/blob/1.18.1/src/main/java/wutdahack/actuallyunbreaking/ActuallyUnbreaking.java
public static void etf$loadConfig() {
try {
File config = new File(CONFIG_DIR, "entity_texture_features.json");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
if (config.exists()) {
try {
FileReader fileReader = new FileReader(config);
ETFConfigData = gson.fromJson(fileReader, ETFConfig.class);
fileReader.close();
ETFUtils2.saveConfig();
} catch (IOException e) {
ETFUtils2.logMessage("Config could not be loaded, using defaults", false);
ETFConfigData = new ETFConfig();
ETFUtils2.saveConfig();
configHadLoadError = true;
}
} else {
ETFConfigData = new ETFConfig();
ETFUtils2.saveConfig();
}
if (ETFConfigData == null) {
ETFUtils2.logMessage("Config was null, using defaults", false);
ETFConfigData = new ETFConfig();
configHadLoadError = true;
}
} catch (Exception e) {
ETFUtils2.logError("Config was corrupt or broken, using defaults", false);
ETFConfigData = new ETFConfig();
configHadLoadError = true;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,56 @@
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.PlayerModelPart;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import traben.entity_texture_features.utils.ETFUtils2;

// compatibility class for the wonderful 3D skin layers mod by @tr9zw to utilise ETF skin features
public abstract class ETF3DSkinLayersUtil {


// todo ensure rendering method is kept up to date with how 3D skin layers mod does it
// copy of 3D skin layers hand rendering code as ETF needs to be able to render it at will with a custom VertexConsumer
public static void renderHand(PlayerEntityRenderer instance, MatrixStack poseStack, VertexConsumer vertexConsumer, int i, AbstractClientPlayerEntity abstractClientPlayer, ModelPart arm, ModelPart sleeve) {
try {
// try contains hand render code
boolean rightSleeve = instance.getModel().leftSleeve != sleeve;
if (rightSleeve) {
if (!SkinLayersModBase.config.enableRightSleeve) {
return;
public static void renderHand(PlayerEntityRenderer instance, MatrixStack poseStack, VertexConsumer vertexConsumer, int i, AbstractClientPlayerEntity abstractClientPlayer, ModelPart arm, ModelPart sleeve)
throws NoClassDefFoundError,Exception {
boolean rightSleeve;
label59: {
rightSleeve = (instance.getModel()).leftSleeve != sleeve;
if (rightSleeve) {
if (SkinLayersModBase.config.enableRightSleeve) {
break label59;
}
} else if (SkinLayersModBase.config.enableLeftSleeve) {
break label59;
}
} else if (!SkinLayersModBase.config.enableLeftSleeve) {

return;
}

sleeve.visible = false;
if (abstractClientPlayer.isPartVisible(rightSleeve ? PlayerModelPart.RIGHT_SLEEVE : PlayerModelPart.LEFT_SLEEVE)) {
PlayerSettings settings = (PlayerSettings) abstractClientPlayer;
float pixelScaling = 1.1F;
PlayerSettings settings = (PlayerSettings)abstractClientPlayer;
float armHeightScaling = 1.1F;
boolean thinArms = ((PlayerEntityModelAccessor) instance.getModel()).hasThinArms();
if (SkinUtil.setup3dLayers(abstractClientPlayer, settings, thinArms, instance.getModel())) {
Mesh part = sleeve == instance.getModel().leftSleeve ? settings.getLeftArmMesh() : settings.getRightArmMesh();
boolean thinArms = ((PlayerEntityModelAccessor)instance.getModel()).hasThinArms();
if (SkinUtil.setup3dLayers(abstractClientPlayer, settings, thinArms, (PlayerEntityModel)instance.getModel())) {
Mesh part = sleeve == ((PlayerEntityModel)instance.getModel()).leftSleeve ? settings.getLeftArmMesh() : settings.getRightArmMesh();
part.copyFrom(arm);
poseStack.push();
poseStack.scale(pixelScaling, armHeightScaling, pixelScaling);
boolean left = sleeve == instance.getModel().leftSleeve;
poseStack.scale(SkinLayersModBase.config.firstPersonPixelScaling, armHeightScaling, SkinLayersModBase.config.firstPersonPixelScaling);
boolean left = sleeve == ((PlayerEntityModel)instance.getModel()).leftSleeve;
float x = left ? 5.0F : -5.0F;
float y = 1.4F;
double scaleOffset = ((double)SkinLayersModBase.config.firstPersonPixelScaling - 1.1) * 5.0;
if (left) {
x = (float)((double)x - scaleOffset);
} else {
x = (float)((double)x + scaleOffset);
}

if (!thinArms) {
if (left) {
x = (float) ((double) x + 0.4);
x = (float)((double)x + 0.45);
} else {
x = (float) ((double) x - 0.4);
x = (float)((double)x - 0.45);
}
}

Expand All @@ -61,14 +71,5 @@ public static void renderHand(PlayerEntityRenderer instance, MatrixStack poseSta
poseStack.pop();
}
}
} catch (Exception e) {
ETFUtils2.logWarn("Exception with ETF's 3D skin layers mod hand compatibility: " + e);
} catch (NoClassDefFoundError error) {
// Should never be thrown
// unless a significant change if skin layers mod
ETFUtils2.logError("Error with ETF's 3D skin layers mod hand compatibility: " + error);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,86 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import traben.entity_texture_features.ETFClientCommon;
import traben.entity_texture_features.ETFVersionDifferenceHandler;
import traben.entity_texture_features.features.ETFManager;
import traben.entity_texture_features.utils.ETFUtils2;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import static traben.entity_texture_features.ETFClientCommon.CONFIG_DIR;
import static traben.entity_texture_features.ETFClientCommon.MOD_ID;

@SuppressWarnings("CanBeFinal")
public class ETFConfig {

public static ETFConfig getInstance() {
if(instance == null){
loadConfig();
}
return instance;
}

public static void setInstance(ETFConfig newConfigInstance) {
instance = newConfigInstance;
}

public static void loadConfig() {
try {
File config = new File(ETFClientCommon.CONFIG_DIR, "entity_texture_features.json");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
if (config.exists()) {
try {
FileReader fileReader = new FileReader(config);
instance = gson.fromJson(fileReader, ETFConfig.class);
fileReader.close();
saveConfig();
} catch (IOException e) {
ETFUtils2.logMessage("Config could not be loaded, using defaults", false);
instance = new ETFConfig();
saveConfig();
ETFClientCommon.configHadLoadError = true;
}
} else {
instance = new ETFConfig();
saveConfig();
}
if (instance == null) {
ETFUtils2.logMessage("Config was null, using defaults", false);
instance = new ETFConfig();
ETFClientCommon.configHadLoadError = true;
}
} catch (Exception e) {
ETFUtils2.logError("Config was corrupt or broken, using defaults", false);
instance = new ETFConfig();
ETFClientCommon.configHadLoadError = true;
}
}

public static void saveConfig() {
File config = new File(CONFIG_DIR, "entity_texture_features.json");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
if (!config.getParentFile().exists()) {
//noinspection ResultOfMethodCallIgnored
config.getParentFile().mkdir();
}
try {
FileWriter fileWriter = new FileWriter(config);
fileWriter.write(gson.toJson(ETFConfig.getInstance()));
fileWriter.close();
} catch (IOException e) {
ETFUtils2.logError("Config file could not be saved", false);
}
}

//config object
private static ETFConfig instance = null;

public IllegalPathMode illegalPathSupportMode = IllegalPathMode.None;

public boolean enableCustomTextures = true;
Expand Down Expand Up @@ -114,7 +183,6 @@ private String getKey() {

public UpdateFrequency next() {
//not enhanced for 1.16 version compat
//noinspection DuplicatedCode
switch (this) {
case Never:
return Slow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.Objects;

import static traben.entity_texture_features.ETFClientCommon.ETFConfigData;
import static traben.entity_texture_features.ETFClientCommon.MOD_ID;

//inspired by puzzles custom gui code
Expand All @@ -39,7 +38,7 @@ public class ETFConfigScreenMain extends ETFConfigScreen {

public ETFConfigScreenMain(Screen parent) {
super(ETFVersionDifferenceHandler.getTextFromTranslation("config." + MOD_ID + ".title"), parent);
temporaryETFConfig = ETFConfig.copyFrom(ETFConfigData);
temporaryETFConfig = ETFConfig.copyFrom(ETFConfig.getInstance());


if (ETFClientCommon.configHadLoadError) {
Expand Down Expand Up @@ -84,8 +83,8 @@ protected void init() {
this.addDrawableChild(ButtonWidget.builder(
ETFVersionDifferenceHandler.getTextFromTranslation("gui.done"),
(button) -> {
ETFConfigData = temporaryETFConfig;
ETFUtils2.saveConfig();
ETFConfig.setInstance(temporaryETFConfig);
ETFConfig.saveConfig();
ETFUtils2.checkModCompatibility();
ETFManager.resetInstance();
ETFClientCommon.configHadLoadError = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.text.Text;
import traben.entity_texture_features.ETFClientCommon;
import traben.entity_texture_features.ETFVersionDifferenceHandler;
import traben.entity_texture_features.config.ETFConfig;
import traben.entity_texture_features.config.screens.ETFConfigScreen;
import traben.entity_texture_features.config.screens.ETFConfigScreenMain;
import traben.entity_texture_features.features.player.ETFPlayerTexture;
Expand Down Expand Up @@ -120,7 +121,7 @@ protected void init() {
}

//capture conditions separately to generate specific instructions for users to fix tool
boolean condition1 = ETFClientCommon.ETFConfigData.skinFeaturesEnabled;
boolean condition1 = ETFConfig.getInstance().skinFeaturesEnabled;
boolean condition2 = !ETFVersionDifferenceHandler.isFabric() || ETFVersionDifferenceHandler.isThisModLoaded("fabric");
boolean condition3 = MinecraftClient.getInstance().player != null;
boolean condition4 = ETFPlayerTexture.clientPlayerOriginalSkinImageForTool != null;
Expand Down
Loading

0 comments on commit bda9fa5

Please sign in to comment.