Fix Automatic Event Subscriber not detecting mod id defaults, and fix test mods.
This commit is contained in:
parent
8c8ef2d9e1
commit
3c5728f070
7 changed files with 61 additions and 56 deletions
|
@ -32,6 +32,7 @@ import org.objectweb.asm.Type;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ public class AutomaticEventSubscriber
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
private static final Type AUTO_SUBSCRIBER = Type.getType(Mod.EventBusSubscriber.class);
|
private static final Type AUTO_SUBSCRIBER = Type.getType(Mod.EventBusSubscriber.class);
|
||||||
|
private static final Type MOD_TYPE = Type.getType(Mod.class);
|
||||||
public static void inject(final ModContainer mod, final ModFileScanData scanData, final ClassLoader loader)
|
public static void inject(final ModContainer mod, final ModFileScanData scanData, final ClassLoader loader)
|
||||||
{
|
{
|
||||||
if (scanData == null) return;
|
if (scanData == null) return;
|
||||||
|
@ -53,6 +55,9 @@ public class AutomaticEventSubscriber
|
||||||
List<ModFileScanData.AnnotationData> ebsTargets = scanData.getAnnotations().stream().
|
List<ModFileScanData.AnnotationData> ebsTargets = scanData.getAnnotations().stream().
|
||||||
filter(annotationData -> AUTO_SUBSCRIBER.equals(annotationData.getAnnotationType())).
|
filter(annotationData -> AUTO_SUBSCRIBER.equals(annotationData.getAnnotationType())).
|
||||||
collect(Collectors.toList());
|
collect(Collectors.toList());
|
||||||
|
Map<String, String> modids = scanData.getAnnotations().stream().
|
||||||
|
filter(annotationData -> MOD_TYPE.equals(annotationData.getAnnotationType())).
|
||||||
|
collect(Collectors.toMap(a -> a.getClassType().getClassName(), a -> (String)a.getAnnotationData().get("value")));
|
||||||
|
|
||||||
ebsTargets.forEach(ad -> {
|
ebsTargets.forEach(ad -> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -60,7 +65,7 @@ public class AutomaticEventSubscriber
|
||||||
getOrDefault("value", Arrays.asList(new ModAnnotation.EnumHolder(null, "CLIENT"), new ModAnnotation.EnumHolder(null, "DEDICATED_SERVER")));
|
getOrDefault("value", Arrays.asList(new ModAnnotation.EnumHolder(null, "CLIENT"), new ModAnnotation.EnumHolder(null, "DEDICATED_SERVER")));
|
||||||
final EnumSet<Dist> sides = sidesValue.stream().map(eh -> Dist.valueOf(eh.getValue())).
|
final EnumSet<Dist> sides = sidesValue.stream().map(eh -> Dist.valueOf(eh.getValue())).
|
||||||
collect(Collectors.toCollection(() -> EnumSet.noneOf(Dist.class)));
|
collect(Collectors.toCollection(() -> EnumSet.noneOf(Dist.class)));
|
||||||
final String modId = (String)ad.getAnnotationData().getOrDefault("modid", mod.getModId());
|
final String modId = (String)ad.getAnnotationData().getOrDefault("modid", modids.getOrDefault(ad.getClassType().getClassName(), mod.getModId()));
|
||||||
final ModAnnotation.EnumHolder busTargetHolder = (ModAnnotation.EnumHolder)ad.getAnnotationData().getOrDefault("bus", new ModAnnotation.EnumHolder(null, "FORGE"));
|
final ModAnnotation.EnumHolder busTargetHolder = (ModAnnotation.EnumHolder)ad.getAnnotationData().getOrDefault("bus", new ModAnnotation.EnumHolder(null, "FORGE"));
|
||||||
final Mod.EventBusSubscriber.Bus busTarget = Mod.EventBusSubscriber.Bus.valueOf(busTargetHolder.getValue());
|
final Mod.EventBusSubscriber.Bus busTarget = Mod.EventBusSubscriber.Bus.valueOf(busTargetHolder.getValue());
|
||||||
if (Objects.equals(mod.getModId(), modId) && sides.contains(FMLEnvironment.dist)) {
|
if (Objects.equals(mod.getModId(), modId) && sides.contains(FMLEnvironment.dist)) {
|
||||||
|
|
|
@ -109,15 +109,17 @@ public class DataGeneratorTest
|
||||||
{
|
{
|
||||||
static final String MODID = "data_gen_test";
|
static final String MODID = "data_gen_test";
|
||||||
|
|
||||||
private static final Gson GSON = new GsonBuilder()
|
private static Gson GSON = null;
|
||||||
.registerTypeAdapter(Variant.class, new Variant.Deserializer())
|
|
||||||
.registerTypeAdapter(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer())
|
|
||||||
.registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer())
|
|
||||||
.create();
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void gatherData(GatherDataEvent event)
|
public static void gatherData(GatherDataEvent event)
|
||||||
{
|
{
|
||||||
|
GSON = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Variant.class, new Variant.Deserializer())
|
||||||
|
.registerTypeAdapter(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer())
|
||||||
|
.registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer())
|
||||||
|
.create();
|
||||||
|
|
||||||
DataGenerator gen = event.getGenerator();
|
DataGenerator gen = event.getGenerator();
|
||||||
|
|
||||||
if (event.includeClient())
|
if (event.includeClient())
|
||||||
|
|
|
@ -37,10 +37,12 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
import net.minecraftforge.event.RegistryEvent;
|
||||||
import net.minecraftforge.event.world.PistonEvent;
|
import net.minecraftforge.event.world.PistonEvent;
|
||||||
import net.minecraftforge.event.world.PistonEvent.PistonMoveType;
|
import net.minecraftforge.event.world.PistonEvent.PistonMoveType;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,9 +79,9 @@ public class PistonEventTest
|
||||||
{
|
{
|
||||||
World world = (World) event.getWorld();
|
World world = (World) event.getWorld();
|
||||||
PistonBlockStructureHelper pistonHelper = event.getStructureHelper();
|
PistonBlockStructureHelper pistonHelper = event.getStructureHelper();
|
||||||
if (world.isRemote)
|
PlayerEntity player = DistExecutor.callWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
|
||||||
|
if (world.isRemote && player != null)
|
||||||
{
|
{
|
||||||
PlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
if (pistonHelper.canMove())
|
if (pistonHelper.canMove())
|
||||||
{
|
{
|
||||||
player.sendMessage(new StringTextComponent(String.format("Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getBlocksToMove().size(), pistonHelper.getBlocksToDestroy().size())));
|
player.sendMessage(new StringTextComponent(String.format("Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getBlocksToMove().size(), pistonHelper.getBlocksToDestroy().size())));
|
||||||
|
@ -118,9 +120,10 @@ public class PistonEventTest
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boolean isSticky = event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.STICKY_PISTON;
|
boolean isSticky = event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.STICKY_PISTON;
|
||||||
if (event.getWorld().isRemote())
|
|
||||||
|
PlayerEntity player = DistExecutor.callWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
|
||||||
|
if (event.getWorld().isRemote() && player != null)
|
||||||
{
|
{
|
||||||
PlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
if (isSticky)
|
if (isSticky)
|
||||||
{
|
{
|
||||||
BlockPos targetPos = event.getFaceOffsetPos().offset(event.getDirection());
|
BlockPos targetPos = event.getFaceOffsetPos().offset(event.getDirection());
|
||||||
|
|
|
@ -41,43 +41,47 @@ import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||||
import net.minecraftforge.client.model.QuadTransformer;
|
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
import net.minecraftforge.client.model.data.IModelData;
|
||||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.model.TransformationHelper;
|
import net.minecraftforge.common.model.TransformationHelper;
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.fml.RegistryObject;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import net.minecraftforge.registries.ObjectHolder;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
@Mod(TRSRTransformerTest.MODID)
|
@Mod(TRSRTransformerTest.MODID)
|
||||||
public class TRSRTransformerTest {
|
public class TRSRTransformerTest {
|
||||||
public static final String MODID = "trsr_transformer_test";
|
public static final String MODID = "trsr_transformer_test";
|
||||||
|
private static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID);
|
||||||
|
private static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);
|
||||||
|
|
||||||
|
private static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register("test", () -> new Block(Block.Properties.create(Material.ROCK)));
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().group(ItemGroup.MISC)));
|
||||||
|
|
||||||
public TRSRTransformerTest() {
|
public TRSRTransformerTest() {
|
||||||
// Register ourselves for server and other game events we are interested in
|
final IEventBus mod = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> mod.addListener(this::onModelBake));
|
||||||
|
BLOCKS.register(mod);
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelBake);
|
ITEMS.register(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onModelBake(ModelBakeEvent e) {
|
public void onModelBake(ModelBakeEvent e) {
|
||||||
for (ResourceLocation id : e.getModelRegistry().keySet()) {
|
for (ResourceLocation id : e.getModelRegistry().keySet()) {
|
||||||
if ("trsr_transformer_test".equals(id.getNamespace()) && "test".equals(id.getPath())) {
|
if (MODID.equals(id.getNamespace()) && "test".equals(id.getPath())) {
|
||||||
e.getModelRegistry().put(id, new MyBakedModel(e.getModelRegistry().get(id)));
|
e.getModelRegistry().put(id, new MyBakedModel(e.getModelRegistry().get(id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MyBakedModel implements IDynamicBakedModel
|
public class MyBakedModel implements IDynamicBakedModel {
|
||||||
{
|
|
||||||
private final IBakedModel base;
|
private final IBakedModel base;
|
||||||
|
|
||||||
public MyBakedModel(IBakedModel base) {
|
public MyBakedModel(IBakedModel base) {
|
||||||
|
@ -95,7 +99,7 @@ public class TRSRTransformerTest {
|
||||||
|
|
||||||
for (BakedQuad quad : base.getQuads(state, side, rand, data)) {
|
for (BakedQuad quad : base.getQuads(state, side, rand, data)) {
|
||||||
|
|
||||||
if(true)
|
if (true)
|
||||||
{
|
{
|
||||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||||
|
|
||||||
|
@ -104,12 +108,10 @@ public class TRSRTransformerTest {
|
||||||
quad.pipe(transformer);
|
quad.pipe(transformer);
|
||||||
|
|
||||||
quads.add(builder.build());
|
quads.add(builder.build());
|
||||||
}
|
} /* else {
|
||||||
else
|
|
||||||
{
|
|
||||||
QuadTransformer qt = new QuadTransformer(trans);
|
QuadTransformer qt = new QuadTransformer(trans);
|
||||||
quads.add(qt.processOne(quad));
|
quads.add(qt.processOne(quad));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return quads.build();
|
return quads.build();
|
||||||
|
@ -145,20 +147,4 @@ public class TRSRTransformerTest {
|
||||||
return base.getOverrides();
|
return base.getOverrides();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
|
||||||
public static class RegistryEvents {
|
|
||||||
@ObjectHolder("trsr_transformer_test:test")
|
|
||||||
public static Block testblock;
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
|
|
||||||
blockRegistryEvent.getRegistry().register(new Block(Block.Properties.create(Material.ROCK)).setRegistryName("trsr_transformer_test", "test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
|
|
||||||
itemRegistryEvent.getRegistry().register(new BlockItem(testblock, new Item.Properties().group(ItemGroup.MISC)).setRegistryName("trsr_transformer_test", "test"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,14 @@ import net.minecraftforge.client.event.RenderNameplateEvent;
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
|
||||||
@Mod("nameplate_render_test")
|
|
||||||
@Mod.EventBusSubscriber
|
@Mod(NameplateRenderingEventTest.MODID)
|
||||||
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class NameplateRenderingEventTest
|
public class NameplateRenderingEventTest
|
||||||
{
|
{
|
||||||
|
public static final String MODID = "nameplate_render_test";
|
||||||
static final boolean ENABLED = false;
|
static final boolean ENABLED = false;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
|
@ -60,7 +60,8 @@ public class GravityAttributeTest
|
||||||
private static final AttributeModifier REDUCED_GRAVITY = (new AttributeModifier(REDUCED_GRAVITY_ID, "Reduced gravity", (double)-0.80, Operation.MULTIPLY_TOTAL)).setSaved(false);
|
private static final AttributeModifier REDUCED_GRAVITY = (new AttributeModifier(REDUCED_GRAVITY_ID, "Reduced gravity", (double)-0.80, Operation.MULTIPLY_TOTAL)).setSaved(false);
|
||||||
|
|
||||||
|
|
||||||
public GravityAttributeTest() {
|
public GravityAttributeTest()
|
||||||
|
{
|
||||||
if (ENABLE)
|
if (ENABLE)
|
||||||
{
|
{
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
@ -71,7 +72,7 @@ public class GravityAttributeTest
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void worldTick(TickEvent.WorldTickEvent event)
|
public void worldTick(TickEvent.WorldTickEvent event)
|
||||||
{
|
{
|
||||||
if (ENABLE && !event.world.isRemote)
|
if (!event.world.isRemote)
|
||||||
{
|
{
|
||||||
if (ticks++ > 60)
|
if (ticks++ > 60)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,3 +63,9 @@ loaderVersion="[28,)"
|
||||||
modId="global_loot_test"
|
modId="global_loot_test"
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="custom_plant_type_test"
|
modId="custom_plant_type_test"
|
||||||
|
[[dependencies.global_loot_test]]
|
||||||
|
modId="forge"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[1,)"
|
||||||
|
ordering="AFTER"
|
||||||
|
side="BOTH"
|
||||||
|
|
Loading…
Reference in a new issue