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.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -46,6 +47,7 @@ public class AutomaticEventSubscriber
|
|||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
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)
|
||||
{
|
||||
if (scanData == null) return;
|
||||
|
@ -53,6 +55,9 @@ public class AutomaticEventSubscriber
|
|||
List<ModFileScanData.AnnotationData> ebsTargets = scanData.getAnnotations().stream().
|
||||
filter(annotationData -> AUTO_SUBSCRIBER.equals(annotationData.getAnnotationType())).
|
||||
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 -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -60,7 +65,7 @@ public class AutomaticEventSubscriber
|
|||
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())).
|
||||
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 Mod.EventBusSubscriber.Bus busTarget = Mod.EventBusSubscriber.Bus.valueOf(busTargetHolder.getValue());
|
||||
if (Objects.equals(mod.getModId(), modId) && sides.contains(FMLEnvironment.dist)) {
|
||||
|
|
|
@ -109,15 +109,17 @@ public class DataGeneratorTest
|
|||
{
|
||||
static final String MODID = "data_gen_test";
|
||||
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(Variant.class, new Variant.Deserializer())
|
||||
.registerTypeAdapter(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer())
|
||||
.registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer())
|
||||
.create();
|
||||
private static Gson GSON = null;
|
||||
|
||||
@SubscribeEvent
|
||||
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();
|
||||
|
||||
if (event.includeClient())
|
||||
|
@ -186,7 +188,7 @@ public class DataGeneratorTest
|
|||
.build(consumer, ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Tags extends BlockTagsProvider
|
||||
{
|
||||
|
||||
|
@ -194,7 +196,7 @@ public class DataGeneratorTest
|
|||
{
|
||||
super(gen);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerTags()
|
||||
{
|
||||
|
@ -205,14 +207,14 @@ public class DataGeneratorTest
|
|||
.addOptionalTag(new ResourceLocation("forge", "storage_blocks/ruby"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Lang extends LanguageProvider
|
||||
{
|
||||
public Lang(DataGenerator gen)
|
||||
{
|
||||
super(gen, MODID, "en_us");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTranslations()
|
||||
{
|
||||
|
@ -376,7 +378,7 @@ public class DataGeneratorTest
|
|||
.transform(Perspective.FIXED)
|
||||
.scale(0.5f)
|
||||
.end()
|
||||
.transform(Perspective.THIRDPERSON_RIGHT)
|
||||
.transform(Perspective.THIRDPERSON_RIGHT)
|
||||
.rotation(75, 45, 0)
|
||||
.translation(0, 2.5f, 0)
|
||||
.scale(0.375f)
|
||||
|
|
|
@ -37,10 +37,12 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.world.PistonEvent;
|
||||
import net.minecraftforge.event.world.PistonEvent.PistonMoveType;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
/**
|
||||
|
@ -77,9 +79,9 @@ public class PistonEventTest
|
|||
{
|
||||
World world = (World) event.getWorld();
|
||||
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())
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
BlockPos targetPos = event.getFaceOffsetPos().offset(event.getDirection());
|
||||
|
|
|
@ -41,43 +41,47 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
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.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod(TRSRTransformerTest.MODID)
|
||||
public class TRSRTransformerTest {
|
||||
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() {
|
||||
// Register ourselves for server and other game events we are interested in
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelBake);
|
||||
final IEventBus mod = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> mod.addListener(this::onModelBake));
|
||||
BLOCKS.register(mod);
|
||||
ITEMS.register(mod);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBake(ModelBakeEvent e) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MyBakedModel implements IDynamicBakedModel
|
||||
{
|
||||
public class MyBakedModel implements IDynamicBakedModel {
|
||||
private final IBakedModel base;
|
||||
|
||||
public MyBakedModel(IBakedModel base) {
|
||||
|
@ -95,7 +99,7 @@ public class TRSRTransformerTest {
|
|||
|
||||
for (BakedQuad quad : base.getQuads(state, side, rand, data)) {
|
||||
|
||||
if(true)
|
||||
if (true)
|
||||
{
|
||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
||||
|
||||
|
@ -104,12 +108,10 @@ public class TRSRTransformerTest {
|
|||
quad.pipe(transformer);
|
||||
|
||||
quads.add(builder.build());
|
||||
}
|
||||
else
|
||||
{
|
||||
} /* else {
|
||||
QuadTransformer qt = new QuadTransformer(trans);
|
||||
quads.add(qt.processOne(quad));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return quads.build();
|
||||
|
@ -145,20 +147,4 @@ public class TRSRTransformerTest {
|
|||
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.SubscribeEvent;
|
||||
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 static final String MODID = "nameplate_render_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@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);
|
||||
|
||||
|
||||
public GravityAttributeTest() {
|
||||
public GravityAttributeTest()
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -71,7 +72,7 @@ public class GravityAttributeTest
|
|||
@SubscribeEvent
|
||||
public void worldTick(TickEvent.WorldTickEvent event)
|
||||
{
|
||||
if (ENABLE && !event.world.isRemote)
|
||||
if (!event.world.isRemote)
|
||||
{
|
||||
if (ticks++ > 60)
|
||||
{
|
||||
|
|
|
@ -63,3 +63,9 @@ loaderVersion="[28,)"
|
|||
modId="global_loot_test"
|
||||
[[mods]]
|
||||
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