your current location:首页 > news>Manningham Mills Github warehouse introduction Chinese translation [MM] Manningham Mills (Fabric ASM) Minecraft Game

Manningham Mills Github warehouse introduction Chinese translation [MM] Manningham Mills (Fabric ASM) Minecraft Game

2024-12-10 17:50:58|Myriagame |source:minecraft skins

The following is the introduction of the author of the author GitHub warehouse: (including technical content)

Manningham Mills

In a harmonious world consisting of Mixin and terrible reflex HACK, Fabric is in it.Mixin is the most suitable for the simple injection of the additional code and the redirection of the method call. It provides a clear guidelines for possible things and check whether what is doing normal during runtime.When other changes need to be made, Mixin will be proven to be not appropriate whether it is changing the judgment of if or in the cycle.With simple annotations alone, convenience no longer exists.You either copy most of the methods, and then cancel in the clumsy @inject, or use the worse @Overwrite to solve everything.

Think of another thing for a while, you are trying to inject it into a method with a privacy as a parameter. This situation is the most disastrous.If it is an interface reflection, it will save you in the form of classic unsafe InvocationHandler and let the interface "pretend" inherit.If you get more troubles in the stall class, you still have a @coerce or pray.

If you need to inherit the private class.Mixin has completely abandoned you to die.Of course, theoretically you can @Accessor , but when Java does not use your fake as a suitable super -class constructor, this is completely useless for inheritance.Repackaging Hack may try his best to let you enter a private class in a package, but at that moment, you have left a safe harbor and entered a dangerous open water.Even so, a suitable private class cannot be accessed.What you can do is not a pile of re -packaging, but a battleship of an Access Transformer.

Control danger

Define warship

MOD's access converter is defined by Loom during development.For the production code, the access converter will automatically map to the intermediary name from YARN and put it in the Silky.at in the production of JAR.MM will automatically load and apply any conversion at runtime. If it does not exist, ILLegalaccessException is thrown.Loom applies any conversion for development, so unless it will be added to another MOD with another MOD with an AT (Access Transformer access converter), it does not require MM.

The AT of the provided example is defined in build.gradle.

Reasonable structure

In the Fabric, the access converter only needs to let the class open (allow directly reference and inherit) and the method disclosure (allow inheritance, especially the constructor).Therefore, MM uses a more concise access converter format to consider that no field or non -public conversion is considered.

#Any line starting with a have iGnored

#

#As are any empty lines

#And empty line

#CLASSSES Defined Alone are interpreted to mean the class is to be made public and definalasy

#The class defined alone is explained as the public and has been defined

Net/Minecraft/item/itemstack

#CLASSSES Defined with A Method Description Are Interpreted to Mean The Method is to be Made Public and DefinalISED

#Use the descriptor definition of the method to explain that the method is public and has been defined

Net/Minecraft/itemstack (LNET/MINECRAFT/ITEM/ITEMPROVIDER;) V#Loom Will Crash When any Wrongly or Ambiguously TranSFor support

#Provide any errors or unclear transformations, LOOM will collapse

#Mm Will Merly Filly to Transform Invalid Methods, Whilst Invalid Classes Will Crash

#MM can only be unable to convert invalidation, and the invalid class will collapse

#net/minecraft/itemstack

#Will go bang if uncommented ^^^^

#If the annotation above is canceled, it will collapse

Here is a definition of AT provided by the example

Sailing safely

Now you have left the security zone, and the degree of protection provides Mixin is not exactly the same.Although there are relatively few errors caused by access to accessers, the golden rule that is always worth remembering is:

Avoid changing anything unnecessary

Each conversion will become another fragile update in your MOD

Be careful to convert the protected method into a public method

If they retain Protect (they can do this), any other MOD inherited the method will collapse.Although this can be repaired theory, it needs to sniff all the loaded mods to repair the class structure.If you want to achieve this, then you will be exhausted. If you succeed, I will accept it.

Make sure the conversion in development is exported correctly to the production environment

If a single item exports multiple mod jars, you should pay attention to any MOD that needs to be converted.A project can only define an AT. By default, it will be added to the JAR and SourceSjar tasks and all the tasks with Remapjartask and Remappingjar.This can be configured as:

Disable the re -mapping and exporting AT's main jar mission ...

 jar {jar {

At.include = false

}

Disable the SourceSjar task exported to AT ...

 SourceSjar {

At.include = false

}

Remapjartask and Remappingjar tasks can disable the AT reproduction and export through the Includeat property at the same time:

 task examplejar (type: remappingjar, dependson: exmpleClasses) {

From SourceSets.example.output

Includeat = false

}

Note that for AT, which is purely used for @mixin targets, they do not need to appear at runtime, because Mixin does not directly load the type of type.However, if other AT needs (need at runtime), their existence is not harmful.

The access converter is very neat, but it is still limited.You can convert the enum's constructor to a public structure function, but this does not add new entries or make great progress here.To this end, it is necessary to bypass to the expanded bay.


Use the extended bay

Waiting for a tide

During the MOD loading process, it must be registered in the early days you want to add.Therefore, it is very reasonable to expect the initialization of a given mod.In order to solve this problem (and load traps described below), MM has a "Early Riseers" system, "Early Riseers" class to implement Runnable, and calls early when needed.Early Riser is defined as an entry point, which is defined in the fabric.mod.json of the mod.The Early Riser entrance point is named MM: Early_risers, using Runnable type, so the Run method is called when initialization.The Early Riser of the provided example is defined here.

Navigation entrance

The early nature required for extension brings potential traps of class loading.Considering that the main startup class will be explained, it is definitely not very good to accidentally quote a Mixin class to be applied.Therefore, it is necessary to be careful about the class that may be loaded by Early Riser.

In order to expand the enumeration category, the Classtinkerers provides four methods:

enumbuilder (string)

enumbuilder (string, class ...)

Enumbuilder (String, String ...)

enumbuilder (String, Object ...)

Although on the surface, there may be subtle differences between the use of Class, String or Object array, but this difference is critical to avoiding classes that do not want unwillingly.

Fast way

The first method is relatively simple, but the least flexible.In the absence of the required constructor with the constructor without parameters, this method can be used to prevent passing the empty array to the other three methods.In fact, the passing group to any of the other three methods is equivalent to using this method in function.However, if the constructor does receive parameters, then this method is not applicable (nor does it work), so another method should be used.

Simple way

The second method is actually easier to use.The variable solid parameters indicate the parameter type to be used in the required enumeration class, so it is subconsciously introduced to the Class.There is nothing wrong with the type in Java or libraries, but it will bring a big problem when it involves the Minecraft type.Because it is mentioned, then it must be loaded so that Java can clearly know its existence (and defined attributes).Therefore, Classtinkerers will check whether the class is introduced in the Net.Minecraft package, if so, it will collapse.Considering that a class like GlstateManager is not in the package, it can still be mixin, which is of course a bit rough, but retaining compassion is not better than anything.

Safe way

The third method requires a greater workload.As with the second one, the variable actual parameters indicate the parameter type of the required constructor.But unlike the second, it does not use the Class object, but uses internal names (similar to Mixin).This is obviously not safe, because compared with the game that runs normally, there are different names in the development environment, but this is its price.Benefits (as you may have guessed) are that internal names can be loaded by bypassing the class, because Java does not need to know the existence of the type even when looking for a constructor.

The important thing is to remember (a bit confused) the first parameter is not the internal name of the enumeration class, but the ordinary class name.This part is for the consistency between methods, partly because the internal name will be used, because in fact, only the class name can be found to find the enumeration class to be expanded.

Lazy way

The fourth method is actually a combination of the first two methods.Like them, variable parameters represent parameter types of the required constructor.However, these types can be specified as Class, internal name String or directly as ASM Type object.This method is all beautiful, because it can directly specify the non -Minecraft class without mandatory designated Minecraft classes.There are always good choices.

Stop pier

No matter which method is used, the generated return object will be the Enumadder of the selected constructor.It theoretically allows any multiple values ​​that need to be added, and you can choose to perform this operation method again:

Addenum (String, Object ...)

Addenum (String, SUPPLIER)

The first name and potential parameters of the value are the objects created in advance.This is useful for the constructor that may not need any additional parameters or only uses the constructor of the Java/Library type.The second also uses the name of the value, but using a factory class, the factory class returns a set of parameters as needed.This protects the type that was originally loaded after Lambda, thereby avoiding passing more useless string.

These two methods are provided here.After adding the required values, you must call the enumadder#build to change the actual application.Although the operation of using Enumadder as a Builder looks more like Java-Y, it will also be registered as a single block, not adding one by one, which greatly improves the class conversion speed.Once you call Build, adding more values ​​will end in failure.

Dislocation raft

If you specify and try to use an invalid (usually a definition error) constructor, you will find this error constructor during the conversion process, causing the game to collapse due to NosuchMethoderror.After all, the exception is to make trouble.The name of repeated or invalid values ​​will throw out classverifyrror. In the end, JVM will determine what should be used and what is not.

The given parameter object actually trusts a certain degree of trust with the type matching of the constructor. If they do not match, then the classcasStexception will be thrown.For the parameters used in the constructive function, the parameters of the error number will be thrown out of iLlegalargumentexception.

Amphibious landing

Sometimes, the dock itself is not enough to complete the expansion task at hand, which will bring great problems to any additional addition.At this time, you can make comprehensive amphibious landing on the bay.

The method in the enumeration class must be a subclass, such as abstract enumeration classes. When the added value method is added, the directly added value will cause AbstractMethoderror.The constructive function itself cannot provide solutions, so MM will make the added entry into sub -enumeration categories.These subclasses are defined by an additional structural class (parameter of the constructor), which defines the sub -category to cover the enumeration.Like ordinary plus methods, according to the transfer method of ordinary constructor parameters, there are two options:

Addenumsubclass (String, String, Object ...)

Addenumsubclass (String, String, SUPPLIER)

The role of the first and third parameters is like ordinary addition.The second parameter is the internal name of the structure class of the subclass.Such a structure category itself can expand other classes (therefore supporting typical class inheritance in technically supporting, although it is an enumeration class), it should eventually use abstract methods that need to bring @Shadow annotations, and unregistered abstract MIXIN extension expansionTo the target enumeration category.Although this is an unusual method, it allows the Mixin annotation processor to handle fuzzy processing without any injection at runtime.Instead, when running, the mixin class is deleted from the hierarchical structure of the structure class to replace the Object (because it must be the deepest parent class) and the method of directly calling from the subclass.

Structural classes can be used to add multiple times, and each addition will create an instance.It is stored in subclasses for processing method calls.After that, if necessary, the structural class can store its own state through the field.For the reasons for loading and general soundness, it is strongly recommended to use the structural class outside the enumeration extension.

This is an example structure with registered and useful use to demonstrate the actual usage of enchantmenttarget.

Plunder

Since it is completed in the enumeration class, it is completed during the loading period, so the obtaining entry may need to be carried out elsewhere in the code.In fact, it should indeed happen elsewhere, because the behavior of loading the lifts you added is very stupid.MM adds a method of getting a new strip: CLASSTINKERERS#GETENUM (Class, String).It will fail soon, so any problems added to the enumeration during the conversion process will become clear.If you use it in multiple places, it is also worth caching the result, because its time complexity is O (n), and n represents the given enumeration class.

The provided examples are used here.

Extended map

Sometimes, the existing category and resources are not mapping enough to expand it.These patchs can be dynamically attached at runtime to allow the additional JAR as needed.All adds are added in the form of URL so that the URLClassLoader of the MOD can be found through Classtinkerrs#addurl (url).If the call is too early (that is, before Early Riseers runs), it will execute failure and return to false, otherwise it will add a given URL to the class path and return True.

Suppose you feel about this world without Mixin and want to go deeper.The dangerous ocean (primitive ASM) is a channel to greater liberation of the ocean.Throwing any concepts of security and cautiousness to the clouds, it means to completely break everything and give full play to the potential of Fabric.

Throw away the map

Classification


The first step of ASM's understanding is to allow you to generate any category you want.Of course, trying to redefine the existing classes cannot work, but you can think of an almost infinite alternative category library to generate anything you want.More importantly, the class can be generated at any time. As long as the definition is registered, they can be loaded and used.Defining a class is simple. Just give the name, and then pass the byte code of the name and class into ClassStinkerrs#Define (String, byte []).The bytecode of the class can be generated using the standard ASM classWriter. You don't need to manually calculate the required content.If this method has been used to define a given name class, it will skip the additional definition and return False.If there are classes with the same name on the class path, then the behavior is an unfarished behavior (don't do this).

Class modification

Now you can define the class at will, and it must be closer to the complete understanding of ASM.However, creating a new class is not as powerful as changing the existing classes as needed.Of course, if the class has been loaded, it will be too late, but it is the ultimate goal without Mixins (before that).

The conversion of the class is completed by registering a given class to ClassNode Consumer with a classNode consumer registered with Classtinkerers#addtransformation (String, Consumer).This means that there can be a conversion of any number of categories.Just like adding it to the enumeration class, it needs to be completed from Early Riser, so that all the converted classes will be learned in time before the game starts.

Class replacement

In the case of a very few, the conversion of classes is so extensive, any instant compatibility that may be changed before is unrealistic.In this case, there is a more decisive choice that is to modify the existing classes and directly replace it.The replacement should not be taken lightly, because a class can only register one replacement.

The replacement of the class is completed by registering a given class with ClassNode Consumer with a clicplacement (String, Consumer).Like ordinary class conversion, this needs to be completed in Early Riser.If you have registered for a given name, you will throw an iLleGalStateException.

With these, you can now change any content you like as freely as possible in the Fabric ecosystem.Now, in the open waters of the primitive ocean full of ASM, everything you do is unrestrained, and any problem (or there is indeed no problem) may be determined by you.I wish you a happy journey!

PS: If you are lost on the sea, you are confused with a class that is generated and/or modified. Remember that Mixin can help you. Use the virtual machine parameter -dmixin.debug.export = true.MM fully supports all classes it changes and generated.

Incorporate into my heart

Manningham Mills (or Lister Mills, when you want to cover up its facts in Manningham) are the world's largest silk and velvet textile factories in the world.This building now listed as a second -class building covers an area of ​​27 acres and can accommodate more than 11,000 employees who produce high -quality textiles.It is estimated that this 249 -foot -high chimney weighs about 8,000 English tons, which is a lighthouse that attracts buyers to buy luxury apartments. Since the factory closed and converted into an apartment building in 1999, it has almost nothing.It's not that Manningham is a place you should yearn for now.Or come true.