Skip to content

Commit

Permalink
Merge pull request #8 from Kasualix/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcat101 authored Oct 25, 2023
2 parents cd250b3 + e98d2d1 commit ecd48d3
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 24 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TileEntity> {

Expand Down Expand Up @@ -105,7 +105,7 @@ public void appendTail(List<ITextComponent> 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()));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mcp/mobius/waila/overlay/OverlayRenderer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/mcp/mobius/waila/overlay/RayTracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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())
Expand All @@ -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;
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/snownee/jade/AmberPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/snownee/jade/Jade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,13 +33,27 @@ public class Jade {
public static final INamedTag<Block> 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()));
});
}
}
13 changes: 9 additions & 4 deletions src/main/java/snownee/jade/JadeCommonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
}

}
6 changes: 6 additions & 0 deletions src/main/java/snownee/jade/api/ExtendedTileEntityType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package snownee.jade.api;

public interface ExtendedTileEntityType {
boolean amber$shouldShowCustomName();
void amber$setShouldShowCustomName(boolean shouldShowCustomName);
}
6 changes: 6 additions & 0 deletions src/main/java/snownee/jade/api/WailaBlacklisted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package snownee.jade.api;

public interface WailaBlacklisted {
boolean amber$isInWailaBlacklist();
void amber$setIsInWailaBlacklist(boolean isInWailaBlacklist);
}
23 changes: 23 additions & 0 deletions src/main/java/snownee/jade/mixin/EntityTypeMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 21 additions & 0 deletions src/main/java/snownee/jade/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 22 additions & 0 deletions src/main/java/snownee/jade/mixin/TileEntityTypeMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 17 additions & 0 deletions src/main/resources/amber.mixins.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit ecd48d3

Please sign in to comment.