Skip to content

Commit

Permalink
Update to new MixinCompiler version.
Browse files Browse the repository at this point in the history
Notable changes:
- MixinCompiler now lets us reference trait classes from the game class loader.
- MixinCompiler no longer force defines our modified classes onto the game class loader.
It defines them on its own class loader, along with our extension classes.
- All traits + markers and Passthrough Interfaces are now registered with `RegisterMultipartTraitsEvent`.
- Java traits can now properly override the parent constructor, and aren't forced to no-arg ctors.
- Substantial architectural improvements to MixinCompiler.
  • Loading branch information
covers1624 committed Jan 20, 2024
1 parent dcbc5f4 commit 36923ce
Show file tree
Hide file tree
Showing 26 changed files with 276 additions and 167 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ dependencies {
// compileOnly fg.deobf("mezz.jei:jei-${config.mc_version}:${config.jei_version}")

//Packed into built jar.
shadow("codechicken:TraitMixinCompiler:${config.mixin_version}") { transitive = false }
shadow("codechicken:TraitMixinCompiler-forge:${config.mixin_version}") { transitive = false }
shadow("codechicken:TraitMixinCompiler-scala:${config.mixin_version}") { transitive = false }
shadow("codechicken:ChickenASM:${config.chicken_asm_version}") { transitive = false }
shadow("codechicken:ChickenASM-modlauncher:${config.chicken_asm_version}") { transitive = false }
shadow("io.codechicken:TraitMixinCompiler:${config.mixin_version}") { transitive = false }
shadow("io.codechicken:ChickenASM:${config.chicken_asm_version}") { transitive = false }

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
}
Expand Down
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod_version=3.3.0
ccl_version=4.3.2.+
ccl_version_max=5.0.0

mixin_version=2.0.0.20
chicken_asm_version=3.1.0.15
mixin_version=3.0.0.21
chicken_asm_version=4.0.0.18
#jei_version=7.6.1.+
23 changes: 22 additions & 1 deletion src/main/java/codechicken/multipart/CBMultipart.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package codechicken.multipart;

import codechicken.lib.world.TileChunkLoadHook;
import codechicken.multipart.api.RegisterMultipartTraitsEvent;
import codechicken.multipart.api.part.*;
import codechicken.multipart.api.part.redstone.RedstonePart;
import codechicken.multipart.handler.PlacementConversionHandler;
import codechicken.multipart.init.CBMultipartModContent;
import codechicken.multipart.init.ClientInit;
import codechicken.multipart.init.DataGenerators;
import codechicken.multipart.init.MultiPartRegistries;
import codechicken.multipart.network.MultiPartNetwork;
import codechicken.multipart.trait.*;
import codechicken.multipart.util.MultipartGenerator;
import codechicken.multipart.util.MultipartLoadHandler;
import codechicken.multipart.util.TickScheduler;
import net.minecraft.world.Container;
import net.minecraft.world.WorldlyContainer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

import static codechicken.multipart.CBMultipart.MOD_ID;

Expand All @@ -31,11 +38,25 @@ public CBMultipart() {

DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> ClientInit::init);

MultipartGenerator.INSTANCE.loadAnnotations();
MultipartGenerator.INSTANCE.load();
MultipartLoadHandler.init();
MultiPartNetwork.init();
PlacementConversionHandler.init();
TickScheduler.init();
TileChunkLoadHook.init();

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegisterMultipartTraits);
}

private void onRegisterMultipartTraits(RegisterMultipartTraitsEvent event) {
event.registerClientTrait(AnimateTickPart.class, TAnimateTickTile.class);
event.registerTrait(CapabilityProviderPart.class, TCapabilityTile.class);
event.registerTrait(Container.class, TInventoryTile.class);
event.registerTrait(WorldlyContainer.class, TInventoryTile.class);
event.registerTrait(PartialOcclusionPart.class, TPartialOcclusionTile.class);
event.registerTrait(RedstonePart.class, TRedstoneTile.class);
event.registerTrait(SlottedPart.class, TSlottedTile.class);
event.registerTrait(TickablePart.class, TTickableTile.class);
event.registerServerTrait(NeighborTileChangePart.class, TTileChangeTile.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package codechicken.multipart.api;

import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.block.TileMultipart;
import codechicken.multipart.util.MultipartGenerator;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;

/**
* Fired on the mod bus for mods to register their traits and passthrough interfaces
* for {@link TileMultipart} classes.
* <p>
* This is fired at the end of mod loading, from {@link FMLLoadCompleteEvent}.
* <p>
* Created by covers1624 on 20/1/24.
*/
public final class RegisterMultipartTraitsEvent extends Event implements IModBusEvent {

private final MultipartGenerator generator;

public RegisterMultipartTraitsEvent(MultipartGenerator generator) {
this.generator = generator;
}

/**
* Register {@code trait} to be mixed into the {@link TileMultipart} when
* {@code marker} is found implemented on a {@link MultiPart} instance.
*
* @param marker The part marker class.
* @param trait The trait to implement.
*/
public void registerTrait(Class<?> marker, Class<? extends TileMultipart> trait) {
generator.registerTrait(marker, trait);
}

/**
* The same as {@link #registerTrait(Class, Class)} however, only effective client side.
*
* @param marker The part marker class.
* @param trait The trait to implement.
*/
public void registerClientTrait(Class<?> marker, Class<? extends TileMultipart> trait) {
generator.registerTrait(marker, trait, null);
}

/**
* The same as {@link #registerTrait(Class, Class)} however, only effective server side (including integrated server).
*
* @param marker The part marker class.
* @param trait The trait to implement.
*/
public void registerServerTrait(Class<?> marker, Class<? extends TileMultipart> trait) {
generator.registerTrait(marker, null, trait);
}

/**
* Register the specified class, when found on a {@link MultiPart} instance:<br/>
* - Implemented the interface on the {@link TileMultipart} instance with all methods proxied through to your part.<br/>
* - Only allow one instance of a part with this interface in the block space.
*
* @param iFace The interface to register.
*/
public void registerPassthroughInterface(Class<?> iFace) {
generator.registerPassThroughInterface(iFace);
}

/**
* The same as {@link #registerPassthroughInterface(Class)} however, only effective client side.
*
* @param iFace The interface to register.
*/
public void registerClientPassthroughInterface(Class<?> iFace) {
generator.registerPassThroughInterface(iFace, true, false);
}

/**
* The same as {@link #registerPassthroughInterface(Class)} however, only effective server side (including integrated server).
*
* @param iFace The interface to register.
*/
public void registerServerPassthroughInterface(Class<?> iFace) {
generator.registerPassThroughInterface(iFace, false, true);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.trait.TAnimateTickTile;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Block;

Expand All @@ -11,7 +9,6 @@
* <p>
* Created by covers1624 on 2/9/20.
*/
@MultiPartMarker (TAnimateTickTile.class)
public interface AnimateTickPart extends MultiPart {

void animateTick(RandomSource random);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.trait.TCapabilityTile;
import net.minecraft.core.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.Nullable;

/**
* Created by covers1624 on 7/1/21.
*/
@MultiPartMarker (TCapabilityTile.class)
public interface CapabilityProviderPart extends MultiPart, ICapabilityProvider {

boolean hasCapabilities(@Nullable Direction dir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.trait.TTileChangeTile;
import net.minecraft.core.Direction;

/**
* Mixin interface for parts that want to be notified of neighbor tile change events (comparators or inventory maintainers)
*/
@MultiPartMarker (TTileChangeTile.class)
public interface NeighborTileChangePart extends MultiPart {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.trait.TPartialOcclusionTile;
import net.minecraft.world.phys.shapes.VoxelShape;

/**
Expand All @@ -11,7 +9,6 @@
* <p>
* This part marker is managed by the mixin trait {@link codechicken.multipart.trait.TPartialOcclusionTile}.
*/
@MultiPartMarker (TPartialOcclusionTile.class)
public interface PartialOcclusionPart extends MultiPart {

/**
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/codechicken/multipart/api/part/SlottedPart.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.trait.TSlottedTile;

/**
* Interface for parts that fill a slot based configuration as defined in PartMap.
* If this is implemented, calling partMap(slot) on the host tile will return this part if the corresponding bit in the slotMask is set
* <p>
* Marker interface for TSlottedTile
*/
@MultiPartMarker (TSlottedTile.class)
public interface SlottedPart extends MultiPart {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package codechicken.multipart.api.part;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.trait.TTickableTile;

/**
* Created by covers1624 on 18/9/20.
*/
@MultiPartMarker (TTickableTile.class)
public interface TickablePart {

void tick();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package codechicken.multipart.api.part.redstone;

import codechicken.multipart.api.annotation.MultiPartMarker;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.trait.TRedstoneTile;
import codechicken.multipart.trait.extern.RedstoneTile;

/**
Expand All @@ -11,7 +9,6 @@
* Marker interface for TRedstoneTile. This means that if a part is an instance of {@link RedstonePart},
* the container tile may be cast to {@link RedstoneTile}
*/
@MultiPartMarker (TRedstoneTile.class)
public interface RedstonePart extends MultiPart {

/**
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/codechicken/multipart/block/TileMultipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ public TileMultipart(BlockPos pos, BlockState state) {
super(CBMultipartModContent.MULTIPART_TILE_TYPE.get(), pos, state);
}

// TODO Mixin compiler needs to support ctors with arguments, provided they are identical to the base class ctor.
protected TileMultipart() {
this(null, null);
throw new UnsupportedOperationException("Exists for traits.");
}

public List<MultiPart> getPartList() {
return partList;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package codechicken.multipart.trait;

import codechicken.mixin.forge.TraitSide;
import codechicken.multipart.api.annotation.MultiPartTrait;
import codechicken.multipart.api.part.AnimateTickPart;
import codechicken.multipart.api.part.MultiPart;
import codechicken.multipart.block.TileMultipart;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;

import java.util.List;

/**
* Created by covers1624 on 2/9/20.
*/
@MultiPartTrait (value = AnimateTickPart.class, side = TraitSide.CLIENT)
public class TAnimateTickTile extends TileMultipart {

public TAnimateTickTile(BlockPos pos, BlockState state) {
super(pos, state);
}

@Override
public void animateTick(RandomSource random) {
List<MultiPart> jPartList = getPartList();
Expand Down
Loading

0 comments on commit 36923ce

Please sign in to comment.