11package traben .entity_texture_features ;
22
3+ import it .unimi .dsi .fastutil .objects .Object2BooleanOpenHashMap ;
4+ import net .minecraft .block .entity .BlockEntity ;
5+ import net .minecraft .entity .Entity ;
6+ import net .minecraft .util .Identifier ;
7+ import org .jetbrains .annotations .Nullable ;
38import traben .entity_texture_features .config .ETFConfig ;
49import traben .entity_texture_features .texture_handlers .ETFManager ;
10+ import traben .entity_texture_features .utils .ETFTexturePropertiesUtils ;
511import traben .entity_texture_features .utils .ETFUtils2 ;
612
13+ import java .util .List ;
14+ import java .util .Properties ;
15+ import java .util .UUID ;
16+
717//an api that will remain unchanged for external mod access (primarily puzzle at this time)
818@ SuppressWarnings ("unused" )
919public class ETFApi {
1020
11- final public static int ETFApiVersion = 2 ;
21+ final public static int ETFApiVersion = 3 ;
1222 //provides access to the ETF config object to read AND modify its values
1323 //please be sure to run the save config method below after any changes
24+ public static ETFConfig getETFConfigObject () {
25+ return ETFClientCommon .ETFConfigData ;
26+ }
27+ //static getter that simply provided an object pointer, doesn't work with config resseting
28+ @ Deprecated
1429 public static ETFConfig getETFConfigObject = ETFClientCommon .ETFConfigData ;
1530
1631 //saves any config changes to file and resets ETF to function with the new settings
@@ -24,6 +39,79 @@ public static void resetETF() {
2439 ETFManager .resetInstance ();
2540 }
2641
27- //for now only puzzle support has been considered
28- //please notify the dev if you would like something added here
42+
43+
44+
45+ // returns the object below that provides functionality to input an entity and output a suffix integer as defined in
46+ // a valid OptiFine random entity properties file given in this method.
47+ // this method will return null for any failure and should print some relevant information on the failure reason.
48+ // the return from this method only requires object.getSuffixForEntity() to be called to retrieve a suffix integer,
49+ // the suffix may or may not be valid, it is up to you to test if the file with that suffix actually exists.
50+ // see the comments below within the object itself for further info.
51+ //
52+ //suffixKeyName would be "skins" for regular OptiFine random textures and "models" for OptiFine random entity models
53+ public ETFRandomTexturePropertyInstance readRandomPropertiesFileAndReturnTestingObject (Identifier propertiesFileIdentifier , String suffixKeyName ) {
54+ return ETFRandomTexturePropertyInstance .getInstance (propertiesFileIdentifier , suffixKeyName );
55+ }
56+
57+
58+ public static class ETFRandomTexturePropertyInstance {
59+ @ Nullable
60+ private static ETFRandomTexturePropertyInstance getInstance (Identifier propertiesFileIdentifier , String suffixKeyName ) {
61+ Properties props = ETFUtils2 .readAndReturnPropertiesElseNull (propertiesFileIdentifier );
62+ if (props == null ) return null ;
63+ List <ETFTexturePropertiesUtils .ETFTexturePropertyCase > etfs = ETFTexturePropertiesUtils .getAllValidPropertyObjects (props , suffixKeyName , propertiesFileIdentifier );
64+ if (etfs .isEmpty ()) return null ;
65+ return new ETFRandomTexturePropertyInstance (etfs );
66+ }
67+
68+ private ETFRandomTexturePropertyInstance (List <ETFTexturePropertiesUtils .ETFTexturePropertyCase > etfs ) {
69+ propertyCases = etfs ;
70+ }
71+
72+ private final List <ETFTexturePropertiesUtils .ETFTexturePropertyCase > propertyCases ;
73+
74+ // this is the primary method of the object,
75+ // it will accept an entity and some additional args and will output a variant suffix integer that matches
76+ // the OptiFine cases outlined in the properties file, it ONLY outputs an integer, testing whether that
77+ // variant number exists or not is up to you.
78+ //
79+ // the boolean second arg provides the algorithm context to allow faster iterations when an entity needs to be
80+ // repeatedly tested, as is the case with the health property, since it can change over time you must retest the
81+ // entity occasionally, the boolean should be true the first time an entity is sent to this method,
82+ // and false every time thereafter, if you don't care about this just hard code it to [true].
83+ //
84+ // the third arg is an optimized type of Map<UUID,boolean>. this map is for your own optimization usage as
85+ // the method will put a boolean into the map to mark whether an entity ever needs to be updated again.
86+ // if the entity has no update-able properties (like health) it will never need to be tested again, so you can
87+ // check this map to skip testing it if it's not needed.
88+ // if the map returns [true] then that entity can possibly update, and you should retest it periodically, if the
89+ // map returns [false] then the entity will never change its suffix, and you can skip testing it.
90+ // the map can simply be hard coded [null] if you do not care.
91+ //
92+ // note an output of 0 ALWAYS means you need to use the vanilla variant, usually due to finding no match
93+ // an output of 1, can be handled in 2 ways, usually it is used to refer to the vanilla suffix, but you might
94+ // also choose to check for a #1 suffix, I would recommend using 1 to mean the vanilla/default variant.
95+ int getSuffixForEntity (Entity entityToBeTested , boolean isThisTheFirstTestForEntity , Object2BooleanOpenHashMap <UUID > cacheToMarkEntitiesWhoseVariantCanChangeAgain ) {
96+ boolean isAnUpdate = !isThisTheFirstTestForEntity ;
97+ for (ETFTexturePropertiesUtils .ETFTexturePropertyCase testCase : propertyCases ) {
98+ if (testCase .doesEntityMeetConditionsOfThisCase (entityToBeTested , isThisTheFirstTestForEntity , cacheToMarkEntitiesWhoseVariantCanChangeAgain )){
99+ return testCase .getAnEntityVariantSuffixFromThisCase (entityToBeTested .getUuid ());
100+ }
101+ }
102+ return 0 ;
103+ }
104+
105+ // same as above but valid for Block Entities, you must supply a UUID,
106+ // you can always generate a UUID from a string with UUID.nameUUIDFromBytes("STRING".getBytes())
107+ int getSuffixForBlockEntity (BlockEntity entityToBeTested , UUID uuidForBlockEntity , boolean isThisTheFirstTestForEntity , Object2BooleanOpenHashMap <UUID > cacheToMarkEntitiesWhoseVariantCanChangeAgain ) {
108+ boolean isAnUpdate = !isThisTheFirstTestForEntity ;
109+ for (ETFTexturePropertiesUtils .ETFTexturePropertyCase testCase : propertyCases ) {
110+ if (testCase .doesEntityMeetConditionsOfThisCase (entityToBeTested , uuidForBlockEntity , isThisTheFirstTestForEntity , cacheToMarkEntitiesWhoseVariantCanChangeAgain )){
111+ return testCase .getAnEntityVariantSuffixFromThisCase (uuidForBlockEntity );
112+ }
113+ }
114+ return 0 ;
115+ }
116+ }
29117}
0 commit comments