diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..b73842b4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,30 @@ +on: [ push, pull_request, workflow_dispatch ] + +jobs: + Build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: 17 + - name: Cache + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + .gradle + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'build.gradle') }} + - name: Build with Gradle + run: | + chmod +x gradlew + ./gradlew build + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: Artifacts-forge + path: ${{ github.workspace }}/build/libs diff --git a/build.gradle b/build.gradle index 03e83a83..70c3d8a2 100644 --- a/build.gradle +++ b/build.gradle @@ -81,6 +81,12 @@ repositories { } } + +mixin { + add sourceSets.main, "amber.refmap.json" + config "amber.mixins.json" +} + dependencies { minecraft 'net.minecraftforge:forge:1.16.5-36.2.34' annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' @@ -118,7 +124,8 @@ jar { attributes([ "Implementation-Title": project.name, "Implementation-Version": "${version}", - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + "MixinConfigs": "amber.mixins.json" ]) } } diff --git a/src/main/java/mcp/mobius/waila/addons/core/HUDHandlerBlocks.java b/src/main/java/mcp/mobius/waila/addons/core/HUDHandlerBlocks.java index 3c313836..6a32135f 100644 --- a/src/main/java/mcp/mobius/waila/addons/core/HUDHandlerBlocks.java +++ b/src/main/java/mcp/mobius/waila/addons/core/HUDHandlerBlocks.java @@ -29,10 +29,10 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import snownee.jade.Jade; -import snownee.jade.JadeCommonConfig; import snownee.jade.JadePlugin; import snownee.jade.Renderables; import snownee.jade.addon.vanilla.TrappedChestProvider; +import snownee.jade.api.ExtendedTileEntityType; public class HUDHandlerBlocks implements IComponentProvider, IServerDataProvider { @@ -105,7 +105,7 @@ public void appendTail(List tooltip, IDataAccessor accessor, IPl @Override public void appendServerData(CompoundNBT data, ServerPlayerEntity player, World world, TileEntity t) { - if (t instanceof INameable && JadeCommonConfig.shouldShowCustomName(t)) { + if (t instanceof INameable && ((ExtendedTileEntityType)t.getType()).amber$shouldShowCustomName()) { INameable nameable = (INameable) t; if (nameable.hasCustomName()) { data.putString("givenName", ITextComponent.Serializer.toJson(nameable.getCustomName())); diff --git a/src/main/java/mcp/mobius/waila/overlay/OverlayRenderer.java b/src/main/java/mcp/mobius/waila/overlay/OverlayRenderer.java index 4de2462a..9a9d1d8e 100644 --- a/src/main/java/mcp/mobius/waila/overlay/OverlayRenderer.java +++ b/src/main/java/mcp/mobius/waila/overlay/OverlayRenderer.java @@ -1,6 +1,6 @@ package mcp.mobius.waila.overlay; -import java.awt.Rectangle; +import java.awt.*; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @@ -23,6 +23,7 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraftforge.common.MinecraftForge; +import snownee.jade.api.WailaBlacklisted; public class OverlayRenderer { @@ -71,7 +72,7 @@ public static void renderOverlay() { if (mc.options.renderDebug && Waila.CONFIG.get().getGeneral().shouldHideFromDebug()) return; - if (RayTracing.INSTANCE.getTarget().getType() == RayTraceResult.Type.BLOCK && !Waila.CONFIG.get().getGeneral().getBlockBlacklist().contains(RayTracing.INSTANCE.getTargetStack().getItem().getRegistryName().toString())) + if (RayTracing.INSTANCE.getTarget().getType() == RayTraceResult.Type.BLOCK && !((WailaBlacklisted)RayTracing.INSTANCE.getTargetStack().getItem()).amber$isInWailaBlacklist()) renderOverlay(WailaTickHandler.instance().tooltip, new MatrixStack()); if (RayTracing.INSTANCE.getTarget().getType() == RayTraceResult.Type.ENTITY && PluginConfig.INSTANCE.get(PluginCore.CONFIG_SHOW_ENTITY)) diff --git a/src/main/java/mcp/mobius/waila/overlay/RayTracing.java b/src/main/java/mcp/mobius/waila/overlay/RayTracing.java index 41e06008..a5c6921f 100644 --- a/src/main/java/mcp/mobius/waila/overlay/RayTracing.java +++ b/src/main/java/mcp/mobius/waila/overlay/RayTracing.java @@ -41,7 +41,7 @@ import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.fml.ModList; +import snownee.jade.api.WailaBlacklisted; public class RayTracing { @@ -130,6 +130,7 @@ public ItemStack getIdentifierStack() { } private boolean canBeTarget(Entity target, Entity viewEntity) { + if (((WailaBlacklisted)target.getType()).amber$isInWailaBlacklist()) return false; if (target.isSpectator()) return false; if (target == viewEntity.getVehicle()) @@ -144,9 +145,6 @@ private boolean canBeTarget(Entity target, Entity viewEntity) { if (!target.hasCustomName() && target.getName() instanceof TranslationTextComponent && !I18n.exists(((TranslationTextComponent)target.getName()).getKey())) { return false; } - if (Waila.CONFIG.get().getGeneral().getEntityBlacklist().contains(target.getEncodeId())) { - return false; - } return true; } diff --git a/src/main/java/snownee/jade/AmberPlugin.java b/src/main/java/snownee/jade/AmberPlugin.java index 734edaf1..c562df7f 100644 --- a/src/main/java/snownee/jade/AmberPlugin.java +++ b/src/main/java/snownee/jade/AmberPlugin.java @@ -40,12 +40,13 @@ public void register(IRegistrar registrar) { registrar.registerBlockDataProvider(ChannelProvider.INSTANCE, Block.class); registrar.addConfig(AE2_CHANNELS, true); } - - registrar.registerComponentProvider(SpeedProvider.INSTANCE, TooltipPosition.BODY, KineticBlock.class); - registrar.addConfig(CREATE_SPEED, ModList.get().isLoaded("create")); - registrar.registerComponentProvider(StressProvider.INSTANCE, TooltipPosition.BODY, KineticBlock.class); - registrar.registerBlockDataProvider(StressProvider.INSTANCE, KineticBlock.class); - registrar.addConfig(CREATE_STRESS, ModList.get().isLoaded("create")); + if (ModList.get().isLoaded("create")) { + registrar.registerComponentProvider(SpeedProvider.INSTANCE, TooltipPosition.BODY, KineticBlock.class); + registrar.addConfig(CREATE_SPEED, true); + registrar.registerComponentProvider(StressProvider.INSTANCE, TooltipPosition.BODY, KineticBlock.class); + registrar.registerBlockDataProvider(StressProvider.INSTANCE, KineticBlock.class); + registrar.addConfig(CREATE_STRESS, true); + } if (ModList.get().isLoaded("farmersdelight")) { registrar.registerComponentProvider(MushroomColonyAgeProvider.INSTANCE, TooltipPosition.BODY, MushroomColonyBlock.class); diff --git a/src/main/java/snownee/jade/Jade.java b/src/main/java/snownee/jade/Jade.java index 04a75897..fe500d96 100644 --- a/src/main/java/snownee/jade/Jade.java +++ b/src/main/java/snownee/jade/Jade.java @@ -4,17 +4,26 @@ import org.apache.commons.lang3.tuple.Pair; +import mcp.mobius.waila.Waila; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; +import net.minecraft.item.Item; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ITag.INamedTag; +import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.network.FMLNetworkConstants; +import net.minecraftforge.registries.ForgeRegistries; +import snownee.jade.api.ExtendedTileEntityType; +import snownee.jade.api.WailaBlacklisted; @Mod(Jade.MODID) public class Jade { @@ -24,13 +33,27 @@ public class Jade { public static final INamedTag PICK = BlockTags.createOptional(new ResourceLocation(MODID, "pick")); public Jade() { - ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, JadeCommonConfig.spec); - FMLJavaModLoadingContext.get().getModEventBus().register(JadeCommonConfig.class); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::init); + ModLoadingContext ctx = ModLoadingContext.get(); + IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); + ctx.registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); + ctx.registerConfig(ModConfig.Type.COMMON, JadeCommonConfig.spec); + modBus.register(JadeCommonConfig.class); + modBus.addListener(this::init); + modBus.addListener(this::clientSetup); } private void init(FMLCommonSetupEvent event) { - JadeCommonConfig.refresh(); + event.enqueueWork(() -> { + JadeCommonConfig.refresh(); + for (TileEntityType tileEntityType : ForgeRegistries.TILE_ENTITIES) ((ExtendedTileEntityType)tileEntityType).amber$setShouldShowCustomName(JadeCommonConfig.shouldShowCustomName(tileEntityType)); + }); + } + + @SuppressWarnings("DataFlowIssue") + private void clientSetup(FMLClientSetupEvent event) { + event.enqueueWork(() -> { + for (EntityType entityType : ForgeRegistries.ENTITIES) ((WailaBlacklisted)entityType).amber$setIsInWailaBlacklist(entityType.canSerialize() && Waila.CONFIG.get().getGeneral().getEntityBlacklist().contains(entityType.getRegistryName().toString())); + for (Item item : ForgeRegistries.ITEMS) ((WailaBlacklisted)item).amber$setIsInWailaBlacklist(Waila.CONFIG.get().getGeneral().getBlockBlacklist().contains(item.getRegistryName().toString())); + }); } } diff --git a/src/main/java/snownee/jade/JadeCommonConfig.java b/src/main/java/snownee/jade/JadeCommonConfig.java index b1195208..9abdc5fd 100644 --- a/src/main/java/snownee/jade/JadeCommonConfig.java +++ b/src/main/java/snownee/jade/JadeCommonConfig.java @@ -8,14 +8,16 @@ import com.google.common.base.Predicates; import com.google.common.collect.Sets; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; import net.minecraftforge.common.ForgeConfigSpec.IntValue; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.registries.ForgeRegistries; import snownee.jade.addon.vanilla.InventoryProvider; +import snownee.jade.api.ExtendedTileEntityType; public final class JadeCommonConfig { @@ -68,19 +70,22 @@ public static void refresh() { public static void onConfigReload(ModConfig.Reloading event) { ((CommentedFileConfig) event.getConfig().getConfigData()).load(); refresh(); + for (TileEntityType tileEntityType : ForgeRegistries.TILE_ENTITIES) { + ((ExtendedTileEntityType)tileEntityType).amber$setShouldShowCustomName(shouldShowCustomName(tileEntityType)); + } } public static boolean shouldIgnoreTE(String id) { return inventoryBlacklist.contains(id); } - public static boolean shouldShowCustomName(TileEntity t) { - String modid = t.getType().getRegistryName().getNamespace(); + @SuppressWarnings("DataFlowIssue") + public static boolean shouldShowCustomName(TileEntityType t) { + String modid = t.getRegistryName().getNamespace(); if (onlyShowVanilla) { return modid.equals("minecraft"); } else { return !modBlacklist.contains(modid); } } - } diff --git a/src/main/java/snownee/jade/api/ExtendedTileEntityType.java b/src/main/java/snownee/jade/api/ExtendedTileEntityType.java new file mode 100644 index 00000000..78c8d1d1 --- /dev/null +++ b/src/main/java/snownee/jade/api/ExtendedTileEntityType.java @@ -0,0 +1,6 @@ +package snownee.jade.api; + +public interface ExtendedTileEntityType { + boolean amber$shouldShowCustomName(); + void amber$setShouldShowCustomName(boolean shouldShowCustomName); +} diff --git a/src/main/java/snownee/jade/api/WailaBlacklisted.java b/src/main/java/snownee/jade/api/WailaBlacklisted.java new file mode 100644 index 00000000..707a347a --- /dev/null +++ b/src/main/java/snownee/jade/api/WailaBlacklisted.java @@ -0,0 +1,6 @@ +package snownee.jade.api; + +public interface WailaBlacklisted { + boolean amber$isInWailaBlacklist(); + void amber$setIsInWailaBlacklist(boolean isInWailaBlacklist); +} diff --git a/src/main/java/snownee/jade/mixin/EntityTypeMixin.java b/src/main/java/snownee/jade/mixin/EntityTypeMixin.java new file mode 100644 index 00000000..0028d6d6 --- /dev/null +++ b/src/main/java/snownee/jade/mixin/EntityTypeMixin.java @@ -0,0 +1,23 @@ +package snownee.jade.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.entity.EntityType; +import snownee.jade.api.WailaBlacklisted; + +@Mixin(EntityType.class) +public abstract class EntityTypeMixin implements WailaBlacklisted { + + @Unique private boolean amber$isInWailaBlacklist; + + @Override + public boolean amber$isInWailaBlacklist() { + return this.amber$isInWailaBlacklist; + } + + @Override + public void amber$setIsInWailaBlacklist(boolean isInWailaBlacklist) { + this.amber$isInWailaBlacklist = isInWailaBlacklist; + } +} diff --git a/src/main/java/snownee/jade/mixin/ItemMixin.java b/src/main/java/snownee/jade/mixin/ItemMixin.java new file mode 100644 index 00000000..251e0e50 --- /dev/null +++ b/src/main/java/snownee/jade/mixin/ItemMixin.java @@ -0,0 +1,21 @@ +package snownee.jade.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.item.Item; +import snownee.jade.api.WailaBlacklisted; + +@Mixin(Item.class) +public class ItemMixin implements WailaBlacklisted { + @Unique private boolean amber$isInWailaBlacklist; + @Override + public boolean amber$isInWailaBlacklist() { + return this.amber$isInWailaBlacklist; + } + + @Override + public void amber$setIsInWailaBlacklist(boolean isInWailaBlacklist) { + this.amber$isInWailaBlacklist = isInWailaBlacklist; + } +} diff --git a/src/main/java/snownee/jade/mixin/TileEntityTypeMixin.java b/src/main/java/snownee/jade/mixin/TileEntityTypeMixin.java new file mode 100644 index 00000000..b3effc8e --- /dev/null +++ b/src/main/java/snownee/jade/mixin/TileEntityTypeMixin.java @@ -0,0 +1,22 @@ +package snownee.jade.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.tileentity.TileEntityType; +import snownee.jade.api.ExtendedTileEntityType; + +@Mixin(TileEntityType.class) +public class TileEntityTypeMixin implements ExtendedTileEntityType { + @Unique private boolean amber$shouldShowCustomName; + + @Override + public boolean amber$shouldShowCustomName() { + return this.amber$shouldShowCustomName; + } + + @Override + public void amber$setShouldShowCustomName(boolean shouldShowCustomName) { + this.amber$shouldShowCustomName = shouldShowCustomName; + } +} diff --git a/src/main/resources/amber.mixins.json b/src/main/resources/amber.mixins.json new file mode 100644 index 00000000..ff5d41d3 --- /dev/null +++ b/src/main/resources/amber.mixins.json @@ -0,0 +1,17 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "snownee.jade.mixin", + "compatibilityLevel": "JAVA_8", + "refmap": "amber.refmap.json", + "injectors": { + "defaultRequire": 1 + }, + "client": [ + "EntityTypeMixin", + "ItemMixin" + ], + "mixins": [ + "TileEntityTypeMixin" + ] +}