浏览代码

Add test mod and fix game rules on forge

shedaniel 4 年之前
父节点
当前提交
4f333f7ec7

+ 1 - 1
forge/src/main/java/me/shedaniel/architectury/mixin/forge/TagHooksImpl.java → forge/src/main/java/me/shedaniel/architectury/hooks/forge/TagHooksImpl.java

@@ -17,7 +17,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-package me.shedaniel.architectury.mixin.forge;
+package me.shedaniel.architectury.hooks.forge;
 
 import net.minecraft.resources.ResourceLocation;
 import net.minecraft.tags.Tag;

+ 46 - 0
forge/src/main/java/me/shedaniel/architectury/mixin/forge/GameRulesAccessor.java

@@ -0,0 +1,46 @@
+package me.shedaniel.architectury.mixin.forge;
+
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.level.GameRules;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Invoker;
+
+import java.util.function.BiConsumer;
+
+@Mixin(GameRules.class)
+public interface GameRulesAccessor {
+    /**
+     * Spliting simple classes because mixin can't handle refmap using the same name
+     */
+    @Mixin(GameRules.BooleanValue.class)
+    interface BooleanValue {
+        @Invoker("create")
+        static GameRules.Type<GameRules.BooleanValue> invokeCreateArchitectury(boolean value, BiConsumer<MinecraftServer, GameRules.BooleanValue> biConsumer) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.BooleanValue.class)
+    interface BooleanValueSimple {
+        @Invoker("create")
+        static GameRules.Type<GameRules.BooleanValue> invokeCreateArchitectury(boolean value) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.IntegerValue.class)
+    interface IntegerValue {
+        @Invoker("create")
+        static GameRules.Type<GameRules.IntegerValue> invokeCreateArchitectury(int value, BiConsumer<MinecraftServer, GameRules.IntegerValue> biConsumer) {
+            throw new AssertionError();
+        }
+    }
+    
+    @Mixin(GameRules.IntegerValue.class)
+    interface IntegerValueSimple {
+        @Invoker("create")
+        static GameRules.Type<GameRules.IntegerValue> invokeCreateArchitectury(int value) {
+            throw new AssertionError();
+        }
+    }
+}

+ 9 - 8
forge/src/main/java/me/shedaniel/architectury/registry/forge/GameRuleFactoryImpl.java

@@ -19,6 +19,7 @@
 
 package me.shedaniel.architectury.registry.forge;
 
+import me.shedaniel.architectury.mixin.forge.GameRulesAccessor;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.world.level.GameRules;
 
@@ -26,20 +27,20 @@ import java.util.function.BiConsumer;
 
 public class GameRuleFactoryImpl {
     private GameRuleFactoryImpl() {}
-
+    
     public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue) {
-        return GameRules.BooleanValue.create(defaultValue);
+        return GameRulesAccessor.BooleanValueSimple.invokeCreateArchitectury(defaultValue);
     }
-
+    
     public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changedCallback) {
-        return GameRules.BooleanValue.create(defaultValue, changedCallback);
+        return GameRulesAccessor.BooleanValue.invokeCreateArchitectury(defaultValue, changedCallback);
     }
-
+    
     public static GameRules.Type<GameRules.IntegerValue> createIntRule(int defaultValue) {
-        return GameRules.IntegerValue.create(defaultValue);
+        return GameRulesAccessor.IntegerValueSimple.invokeCreateArchitectury(defaultValue);
     }
-
+    
     public static GameRules.Type<GameRules.IntegerValue> createIntRule(int defaultValue, BiConsumer<MinecraftServer, GameRules.IntegerValue> changedCallback) {
-        return GameRules.IntegerValue.create(defaultValue, changedCallback);
+        return GameRulesAccessor.IntegerValue.invokeCreateArchitectury(defaultValue, changedCallback);
     }
 }

+ 0 - 4
forge/src/main/resources/META-INF/accesstransformer.cfg

@@ -33,7 +33,3 @@ public-f net.minecraft.world.biome.BiomeAmbience field_242524_f # foliageColor
 public-f net.minecraft.world.biome.BiomeAmbience field_242525_g # grassColor
 public-f net.minecraft.world.biome.BiomeAmbience field_242526_h # grassColorModifier
 public net.minecraft.world.storage.FolderName <init>(Ljava/lang/String;)V
-public net.minecraft.world.GameRules$BooleanValue func_223567_b(ZLjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$BooleanValue func_223568_b(Z)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$IntegerValue func_223564_a(ILjava/util/function/BiConsumer;)Lnet/minecraft/world/GameRules$RuleType; # create
-public net.minecraft.world.GameRules$IntegerValue func_223559_b(I)Lnet/minecraft/world/GameRules$RuleType; # create

+ 1 - 1
forge/src/main/resources/architectury.mixins.json

@@ -8,7 +8,7 @@
   ],
   "mixins": [
     "BiomeGenerationSettingsBuilderAccessor", "MixinRegistryEntry", "MixinBlockEntity", "MixinBlockEntityExtension",
-    "MobSpawnSettingsBuilderAccessor"
+    "MobSpawnSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple"
   ],
   "injectors": {
     "defaultRequire": 1

+ 2 - 0
testmod-common/src/main/java/me/shedaniel/architectury/test/TestMod.java

@@ -27,6 +27,7 @@ import me.shedaniel.architectury.test.debug.client.ClientOverlayMessageSink;
 import me.shedaniel.architectury.test.gamerule.TestGameRules;
 import me.shedaniel.architectury.test.registry.TestRegistries;
 import me.shedaniel.architectury.test.registry.client.TestKeybinds;
+import me.shedaniel.architectury.test.tags.TestTags;
 import me.shedaniel.architectury.utils.Env;
 import me.shedaniel.architectury.utils.EnvExecutor;
 
@@ -38,6 +39,7 @@ public class TestMod {
         DebugEvents.initialize();
         TestRegistries.initialize();
         TestGameRules.init();
+        TestTags.initialize();
         if (Platform.getEnvironment() == Env.CLIENT)
             TestKeybinds.initialize();
     }

+ 28 - 0
testmod-common/src/main/java/me/shedaniel/architectury/test/tags/TestTags.java

@@ -0,0 +1,28 @@
+package me.shedaniel.architectury.test.tags;
+
+import me.shedaniel.architectury.event.events.BlockEvent;
+import me.shedaniel.architectury.hooks.TagHooks;
+import me.shedaniel.architectury.test.TestMod;
+import net.minecraft.core.particles.ParticleTypes;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.tags.Tag;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.level.block.Block;
+
+public class TestTags {
+    public static void initialize() {
+        // This will not be present, but it should return an empty tag
+        Tag.Named<Block> heartParticles = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles"));
+        // This will act like a normal tag, we have emerald block here
+        Tag.Named<Block> heartParticles2 = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles2"));
+        
+        BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
+            if (player != null && !world.isClientSide() && (state.is(heartParticles) || state.is(heartParticles2))) {
+                ((ServerLevel) world).sendParticles(player, ParticleTypes.HEART, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.0, 0.0, 0.0, 0.0);
+            }
+            
+            return InteractionResult.PASS;
+        });
+    }
+}

+ 6 - 0
testmod-common/src/main/resources/data/architectury-test/tags/blocks/heart_particles2.json

@@ -0,0 +1,6 @@
+{
+    "replace": false,
+    "values": [
+        "minecraft:emerald_block"
+    ]
+}