mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add test mod and fix game rules on forge
This commit is contained in:
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
],
|
||||
"mixins": [
|
||||
"BiomeGenerationSettingsBuilderAccessor", "MixinRegistryEntry", "MixinBlockEntity", "MixinBlockEntityExtension",
|
||||
"MobSpawnSettingsBuilderAccessor"
|
||||
"MobSpawnSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:emerald_block"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user