diff --git a/build.gradle b/build.gradle index 70fa1f9..3a93bdb 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,9 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // MixinExtras + include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}"))) + // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" } diff --git a/gradle.properties b/gradle.properties index 6b4088c..d6a6fba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties - # check these on https://modmuss50.me/fabric.html - minecraft_version=1.20.2 - yarn_mappings=1.20.2+build.4 - loader_version=0.15.6 +# check these on https://modmuss50.me/fabric.html +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.4 +loader_version=0.15.6 # Mod Properties - mod_version=1.6-release - maven_group=com.mmodding.notenoughgamerules - archives_base_name=NEG-FABRIC-1.20.2 +mod_version=1.6-release +maven_group=com.mmodding.notenoughgamerules +archives_base_name=NEG-FABRIC-1.20.2 # Dependencies - # check this on https://modmuss50.me/fabric.html - fabric_version=0.91.6+1.20.2 +# check this on https://modmuss50.me/fabric.html +mixinextras_version=0.3.5 +fabric_version=0.91.6+1.20.2 diff --git a/src/main/java/com/mmodding/notenoughgamerules/Gamerules.java b/src/main/java/com/mmodding/notenoughgamerules/Gamerules.java index 95deffd..f1aad57 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/Gamerules.java +++ b/src/main/java/com/mmodding/notenoughgamerules/Gamerules.java @@ -6,75 +6,75 @@ public class Gamerules { - public static GameRules.Key ALWAYS_SPAWN_DRAGON_EGG; - public static GameRules.Key ANVIL_DAMAGE; - public static GameRules.Key CAN_COPPER_OXIDE; - public static GameRules.Key CAN_ENTITY_INTERACT_WITH_BLOCK; - public static GameRules.Key CAN_ENTITY_INTERACT_WITH_ENTITIES; - public static GameRules.Key CAN_ENTITY_INTERACT_WITH_WORLD; - public static GameRules.Key CAN_HURT_PET_MOBS; - public static GameRules.Key CAN_PLAYER_SLEEP; - public static GameRules.Key CAN_PLAYER_TAKE_DAMAGE; - public static GameRules.Key DISABLE_CHAT; - public static GameRules.Key DISABLE_DIMENSION_CHANGE; - public static GameRules.Key DISABLE_KNOCKBACK; - public static GameRules.Key DISABLE_PISTONS; - public static GameRules.Key DO_BABIES_SPAWN; - public static GameRules.Key DO_CORAL_NEED_WATER; - public static GameRules.Key DO_ICE_FORM; - public static GameRules.Key DO_ICE_MELT; - public static GameRules.Key DO_SNOW_FORM; - public static GameRules.Key DO_SNOW_MELT; - public static GameRules.Key DO_TRANSFORMATIONS; - public static GameRules.Key DRAGON_BREATH_DAMAGE; - public static GameRules.Key EXPLOSION_DAMAGE; - public static GameRules.Key FALLING_BLOCKS_DAMAGE; - public static GameRules.Key KEEP_EFFECTS; - public static GameRules.Key KEEP_XP; - public static GameRules.Key LIGHTNING_DAMAGE; - public static GameRules.Key NATURAL_HUNGER; - public static GameRules.Key POISON_HEALTH; - public static GameRules.Key PVP; - public static GameRules.Key RAW_MEAT_HUNGER; - public static GameRules.Key SKY_HIGH; - public static GameRules.Key STALACTITE_DAMAGE; - public static GameRules.Key TNT_EXPLODES; - public static GameRules.Key VILLAGER_CONVERSION; + public static GameRules.Key ALWAYS_SPAWN_DRAGON_EGG; + public static GameRules.Key ANVIL_DAMAGE; + public static GameRules.Key CAN_COPPER_OXIDE; + public static GameRules.Key CAN_ENTITY_INTERACT_WITH_BLOCK; + public static GameRules.Key CAN_ENTITY_INTERACT_WITH_ENTITIES; + public static GameRules.Key CAN_ENTITY_INTERACT_WITH_WORLD; + public static GameRules.Key CAN_HURT_PET_MOBS; + public static GameRules.Key CAN_PLAYER_SLEEP; + public static GameRules.Key CAN_PLAYER_TAKE_DAMAGE; + public static GameRules.Key DISABLE_CHAT; + public static GameRules.Key DISABLE_DIMENSION_CHANGE; + public static GameRules.Key DISABLE_KNOCKBACK; + public static GameRules.Key DISABLE_PISTONS; + public static GameRules.Key DO_BABIES_SPAWN; + public static GameRules.Key DO_CORAL_NEED_WATER; + public static GameRules.Key DO_ICE_FORM; + public static GameRules.Key DO_ICE_MELT; + public static GameRules.Key DO_SNOW_FORM; + public static GameRules.Key DO_SNOW_MELT; + public static GameRules.Key DO_TRANSFORMATIONS; + public static GameRules.Key DRAGON_BREATH_DAMAGE; + public static GameRules.Key EXPLOSION_DAMAGE; + public static GameRules.Key FALLING_BLOCKS_DAMAGE; + public static GameRules.Key KEEP_EFFECTS; + public static GameRules.Key KEEP_XP; + public static GameRules.Key LIGHTNING_DAMAGE; + public static GameRules.Key NATURAL_HUNGER; + public static GameRules.Key POISON_HEALTH; + public static GameRules.Key PVP; + public static GameRules.Key RAW_MEAT_HUNGER; + public static GameRules.Key SKY_HIGH; + public static GameRules.Key STALACTITE_DAMAGE; + public static GameRules.Key TNT_EXPLODES; + public static GameRules.Key VILLAGER_CONVERSION; - public static void setupGamerules() { - ALWAYS_SPAWN_DRAGON_EGG = GameRuleRegistry.register("alwaysSpawnDragonEgg", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(false)); - ANVIL_DAMAGE = GameRuleRegistry.register("anvilDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - CAN_COPPER_OXIDE = GameRuleRegistry.register("canCopperOxide", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - CAN_ENTITY_INTERACT_WITH_BLOCK = GameRuleRegistry.register("canEntityInteractWithBlock", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); - CAN_ENTITY_INTERACT_WITH_ENTITIES = GameRuleRegistry.register("canEntityInteractWithEntities", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); - CAN_ENTITY_INTERACT_WITH_WORLD = GameRuleRegistry.register("canEntityInteractWithWorld", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); - CAN_HURT_PET_MOBS = GameRuleRegistry.register("canHurtPetMobs", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); - CAN_PLAYER_SLEEP = GameRuleRegistry.register("canPlayerSleep", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - CAN_PLAYER_TAKE_DAMAGE = GameRuleRegistry.register("canPlayerTakeDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - DISABLE_CHAT = GameRuleRegistry.register("disableChat", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); - DISABLE_DIMENSION_CHANGE = GameRuleRegistry.register("disableDimensionChange", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); - DISABLE_KNOCKBACK = GameRuleRegistry.register("disableKnockback", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); - DISABLE_PISTONS = GameRuleRegistry.register("disablePistons", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(false)); - DO_BABIES_SPAWN = GameRuleRegistry.register("doBabiesSpawn", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); - DO_CORAL_NEED_WATER = GameRuleRegistry.register("doCoralNeedWater", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - DO_ICE_FORM = GameRuleRegistry.register("doIceForm", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - DO_ICE_MELT = GameRuleRegistry.register("doIceMelt", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - DO_SNOW_FORM = GameRuleRegistry.register("doSnowForm", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - DO_SNOW_MELT = GameRuleRegistry.register("doSnowMelt", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); - DO_TRANSFORMATIONS = GameRuleRegistry.register("doTransformations", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); - DRAGON_BREATH_DAMAGE = GameRuleRegistry.register("dragonBreathDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); - EXPLOSION_DAMAGE = GameRuleRegistry.register("explosionDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); - FALLING_BLOCKS_DAMAGE = GameRuleRegistry.register("fallingBlocksDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - KEEP_EFFECTS = GameRuleRegistry.register("keepEffects", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); - KEEP_XP = GameRuleRegistry.register("keepXp", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); - LIGHTNING_DAMAGE = GameRuleRegistry.register("lightningDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); - NATURAL_HUNGER = GameRuleRegistry.register("naturalHunger", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); - POISON_HEALTH = GameRuleRegistry.register("poisonHealth", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(1)); - PVP = GameRuleRegistry.register("pvp", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - RAW_MEAT_HUNGER = GameRuleRegistry.register("rawMeatHunger", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(30)); - SKY_HIGH = GameRuleRegistry.register("skyHigh", GameRules.Category.MISC, GameRuleFactory.createIntRule(-64)); - STALACTITE_DAMAGE = GameRuleRegistry.register("stalactiteDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); - TNT_EXPLODES = GameRuleRegistry.register("tntExplodes", GameRules.Category.MISC, GameRuleFactory.createBooleanRule(true)); - VILLAGER_CONVERSION = GameRuleRegistry.register("villagerConversion", GameRules.Category.MOBS, GameRuleFactory.createIntRule(50)); - } + public static void setupGamerules() { + ALWAYS_SPAWN_DRAGON_EGG = GameRuleRegistry.register("alwaysSpawnDragonEgg", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(false)); + ANVIL_DAMAGE = GameRuleRegistry.register("anvilDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + CAN_COPPER_OXIDE = GameRuleRegistry.register("canCopperOxide", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + CAN_ENTITY_INTERACT_WITH_BLOCK = GameRuleRegistry.register("canEntityInteractWithBlock", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); + CAN_ENTITY_INTERACT_WITH_ENTITIES = GameRuleRegistry.register("canEntityInteractWithEntities", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); + CAN_ENTITY_INTERACT_WITH_WORLD = GameRuleRegistry.register("canEntityInteractWithWorld", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); + CAN_HURT_PET_MOBS = GameRuleRegistry.register("canHurtPetMobs", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); + CAN_PLAYER_SLEEP = GameRuleRegistry.register("canPlayerSleep", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + CAN_PLAYER_TAKE_DAMAGE = GameRuleRegistry.register("canPlayerTakeDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + DISABLE_CHAT = GameRuleRegistry.register("disableChat", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); + DISABLE_DIMENSION_CHANGE = GameRuleRegistry.register("disableDimensionChange", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); + DISABLE_KNOCKBACK = GameRuleRegistry.register("disableKnockback", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); + DISABLE_PISTONS = GameRuleRegistry.register("disablePistons", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(false)); + DO_BABIES_SPAWN = GameRuleRegistry.register("doBabiesSpawn", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); + DO_CORAL_NEED_WATER = GameRuleRegistry.register("doCoralNeedWater", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + DO_ICE_FORM = GameRuleRegistry.register("doIceForm", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + DO_ICE_MELT = GameRuleRegistry.register("doIceMelt", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + DO_SNOW_FORM = GameRuleRegistry.register("doSnowForm", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + DO_SNOW_MELT = GameRuleRegistry.register("doSnowMelt", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(true)); + DO_TRANSFORMATIONS = GameRuleRegistry.register("doTransformations", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true)); + DRAGON_BREATH_DAMAGE = GameRuleRegistry.register("dragonBreathDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); + EXPLOSION_DAMAGE = GameRuleRegistry.register("explosionDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); + FALLING_BLOCKS_DAMAGE = GameRuleRegistry.register("fallingBlocksDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + KEEP_EFFECTS = GameRuleRegistry.register("keepEffects", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); + KEEP_XP = GameRuleRegistry.register("keepXp", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); + LIGHTNING_DAMAGE = GameRuleRegistry.register("lightningDamage", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); + NATURAL_HUNGER = GameRuleRegistry.register("naturalHunger", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(-1)); + POISON_HEALTH = GameRuleRegistry.register("poisonHealth", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(1)); + PVP = GameRuleRegistry.register("pvp", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + RAW_MEAT_HUNGER = GameRuleRegistry.register("rawMeatHunger", GameRules.Category.PLAYER, GameRuleFactory.createIntRule(30)); + SKY_HIGH = GameRuleRegistry.register("skyHigh", GameRules.Category.MISC, GameRuleFactory.createIntRule(-64)); + STALACTITE_DAMAGE = GameRuleRegistry.register("stalactiteDamage", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(true)); + TNT_EXPLODES = GameRuleRegistry.register("tntExplodes", GameRules.Category.MISC, GameRuleFactory.createBooleanRule(true)); + VILLAGER_CONVERSION = GameRuleRegistry.register("villagerConversion", GameRules.Category.MOBS, GameRuleFactory.createIntRule(50)); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/NEGDamageTypes.java b/src/main/java/com/mmodding/notenoughgamerules/NEGDamageTypes.java index 3114e22..9eb57fc 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/NEGDamageTypes.java +++ b/src/main/java/com/mmodding/notenoughgamerules/NEGDamageTypes.java @@ -8,11 +8,11 @@ public class NEGDamageTypes { - public static final RegistryKey SKY_HIGH = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, NotEnoughGamerules.createId("sky_high")); - public static final RegistryKey DIFFERED_EXPLOSION = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, NotEnoughGamerules.createId("differed_explosion")); + public static final RegistryKey SKY_HIGH = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, NotEnoughGamerules.createId("sky_high")); + public static final RegistryKey DIFFERED_EXPLOSION = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, NotEnoughGamerules.createId("differed_explosion")); - public static void register(Registry damageTypeRegistry) { - Registry.register(damageTypeRegistry, NEGDamageTypes.SKY_HIGH, new DamageType("skyHigh", DamageScaling.ALWAYS, 0.1f)); - Registry.register(damageTypeRegistry, NEGDamageTypes.DIFFERED_EXPLOSION, new DamageType("explosion", DamageScaling.ALWAYS, 0.1f)); - } + public static void register(Registry damageTypeRegistry) { + Registry.register(damageTypeRegistry, NEGDamageTypes.SKY_HIGH, new DamageType("skyHigh", DamageScaling.ALWAYS, 0.1f)); + Registry.register(damageTypeRegistry, NEGDamageTypes.DIFFERED_EXPLOSION, new DamageType("explosion", DamageScaling.ALWAYS, 0.1f)); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/NotEnoughGamerules.java b/src/main/java/com/mmodding/notenoughgamerules/NotEnoughGamerules.java index 827e600..70f293e 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/NotEnoughGamerules.java +++ b/src/main/java/com/mmodding/notenoughgamerules/NotEnoughGamerules.java @@ -19,48 +19,48 @@ public class NotEnoughGamerules implements ModInitializer { - @Override - public void onInitialize() { - DynamicRegistrySetupCallback.EVENT.register(new DynamicRegistrySetupListener()); - Gamerules.setupGamerules(); - EntitySleepEvents.ALLOW_SLEEPING.register(new PlayerSleepsListener()); - ServerPlayerEvents.AFTER_RESPAWN.register(new AfterRespawnListener()); - } + @Override + public void onInitialize() { + DynamicRegistrySetupCallback.EVENT.register(new DynamicRegistrySetupListener()); + Gamerules.setupGamerules(); + EntitySleepEvents.ALLOW_SLEEPING.register(new PlayerSleepsListener()); + ServerPlayerEvents.AFTER_RESPAWN.register(new AfterRespawnListener()); + } - public static void damageGamerule(Entity entity, DamageSource source, CallbackInfoReturnable cir) { - if (entity == null) return; - GameRules gameRules = entity.getWorld().getGameRules(); - if (!gameRules.getBoolean(Gamerules.CAN_HURT_PET_MOBS) && source.getSource() instanceof PlayerEntity && - entity instanceof TameableEntity tameableEntity && tameableEntity.isTamed() && tameableEntity.getOwner() == source.getSource()) { - cir.cancel(); - } - if (!gameRules.getBoolean(Gamerules.PVP) && entity instanceof PlayerEntity && source.getSource() instanceof PlayerEntity) { - cir.cancel(); - } - if (gameRules.getInt(Gamerules.EXPLOSION_DAMAGE) > -1 && source.isIn(DamageTypeTags.IS_EXPLOSION)) { - entity.damage(entity.getDamageSources().create(NEGDamageTypes.DIFFERED_EXPLOSION), (float) gameRules.getInt(Gamerules.EXPLOSION_DAMAGE)); - cir.cancel(); - } - if (!gameRules.getBoolean(Gamerules.ANVIL_DAMAGE) && source.isOf(DamageTypes.FALLING_ANVIL)) { - cir.cancel(); - } - if (!gameRules.getBoolean(Gamerules.FALLING_BLOCKS_DAMAGE) && source.isOf(DamageTypes.FALLING_BLOCK)) { - cir.cancel(); - } - if (!gameRules.getBoolean(Gamerules.STALACTITE_DAMAGE) && source.isOf(DamageTypes.FALLING_STALACTITE)) { - cir.cancel(); - } - if (gameRules.getInt(Gamerules.DRAGON_BREATH_DAMAGE) > -1 && source.isOf(DamageTypes.DRAGON_BREATH)) { - entity.damage(entity.getDamageSources().dragonBreath(), (float) gameRules.getInt(Gamerules.DRAGON_BREATH_DAMAGE)); - cir.cancel(); - } - } + public static void damageGamerule(Entity entity, DamageSource source, CallbackInfoReturnable cir) { + if (entity == null) return; + GameRules gameRules = entity.getWorld().getGameRules(); + if (!gameRules.getBoolean(Gamerules.CAN_HURT_PET_MOBS) && source.getSource() instanceof PlayerEntity && + entity instanceof TameableEntity tameableEntity && tameableEntity.isTamed() && tameableEntity.getOwner() == source.getSource()) { + cir.cancel(); + } + if (!gameRules.getBoolean(Gamerules.PVP) && entity instanceof PlayerEntity && source.getSource() instanceof PlayerEntity) { + cir.cancel(); + } + if (gameRules.getInt(Gamerules.EXPLOSION_DAMAGE) > -1 && source.isIn(DamageTypeTags.IS_EXPLOSION)) { + entity.damage(entity.getDamageSources().create(NEGDamageTypes.DIFFERED_EXPLOSION), (float) gameRules.getInt(Gamerules.EXPLOSION_DAMAGE)); + cir.cancel(); + } + if (!gameRules.getBoolean(Gamerules.ANVIL_DAMAGE) && source.isOf(DamageTypes.FALLING_ANVIL)) { + cir.cancel(); + } + if (!gameRules.getBoolean(Gamerules.FALLING_BLOCKS_DAMAGE) && source.isOf(DamageTypes.FALLING_BLOCK)) { + cir.cancel(); + } + if (!gameRules.getBoolean(Gamerules.STALACTITE_DAMAGE) && source.isOf(DamageTypes.FALLING_STALACTITE)) { + cir.cancel(); + } + if (gameRules.getInt(Gamerules.DRAGON_BREATH_DAMAGE) > -1 && source.isOf(DamageTypes.DRAGON_BREATH)) { + entity.damage(entity.getDamageSources().dragonBreath(), (float) gameRules.getInt(Gamerules.DRAGON_BREATH_DAMAGE)); + cir.cancel(); + } + } - public static String id() { - return "not_enough_gamerules"; - } + public static String id() { + return "not_enough_gamerules"; + } - public static Identifier createId(String path) { - return new Identifier(NotEnoughGamerules.id(), path); - } + public static Identifier createId(String path) { + return new Identifier(NotEnoughGamerules.id(), path); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/events/AfterRespawnListener.java b/src/main/java/com/mmodding/notenoughgamerules/events/AfterRespawnListener.java index c9e4020..c46c0c6 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/events/AfterRespawnListener.java +++ b/src/main/java/com/mmodding/notenoughgamerules/events/AfterRespawnListener.java @@ -7,13 +7,13 @@ public class AfterRespawnListener implements ServerPlayerEvents.AfterRespawn { - @Override - public void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) { - if (newPlayer.getEntityWorld().getGameRules().getBoolean(Gamerules.KEEP_EFFECTS)) { - for (int i = 0; i < oldPlayer.getStatusEffects().size(); i++) { - StatusEffectInstance statusEffectInstance = oldPlayer.getStatusEffects().stream().toList().get(i); - newPlayer.addStatusEffect(statusEffectInstance, oldPlayer); - } - } - } + @Override + public void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) { + if (newPlayer.getEntityWorld().getGameRules().getBoolean(Gamerules.KEEP_EFFECTS)) { + for (int i = 0; i < oldPlayer.getStatusEffects().size(); i++) { + StatusEffectInstance statusEffectInstance = oldPlayer.getStatusEffects().stream().toList().get(i); + newPlayer.addStatusEffect(statusEffectInstance, oldPlayer); + } + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/events/DynamicRegistrySetupListener.java b/src/main/java/com/mmodding/notenoughgamerules/events/DynamicRegistrySetupListener.java index 2a51dee..5ad04ee 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/events/DynamicRegistrySetupListener.java +++ b/src/main/java/com/mmodding/notenoughgamerules/events/DynamicRegistrySetupListener.java @@ -7,8 +7,8 @@ public class DynamicRegistrySetupListener implements DynamicRegistrySetupCallback { - @Override - public void onRegistrySetup(DynamicRegistryView registryView) { - registryView.getOptional(RegistryKeys.DAMAGE_TYPE).ifPresent(NEGDamageTypes::register); - } + @Override + public void onRegistrySetup(DynamicRegistryView registryView) { + registryView.getOptional(RegistryKeys.DAMAGE_TYPE).ifPresent(NEGDamageTypes::register); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/events/PlayerSleepsListener.java b/src/main/java/com/mmodding/notenoughgamerules/events/PlayerSleepsListener.java index 7b0131d..bb600e7 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/events/PlayerSleepsListener.java +++ b/src/main/java/com/mmodding/notenoughgamerules/events/PlayerSleepsListener.java @@ -8,11 +8,11 @@ public class PlayerSleepsListener implements EntitySleepEvents.AllowSleeping { - @Override - public PlayerEntity.@Nullable SleepFailureReason allowSleep(PlayerEntity player, BlockPos sleepingPos) { - if (!player.getWorld().getGameRules().getBoolean(Gamerules.CAN_PLAYER_SLEEP)) { - return PlayerEntity.SleepFailureReason.NOT_POSSIBLE_NOW; - } - return null; - } + @Override + public PlayerEntity.@Nullable SleepFailureReason allowSleep(PlayerEntity player, BlockPos sleepingPos) { + if (!player.getWorld().getGameRules().getBoolean(Gamerules.CAN_PLAYER_SLEEP)) { + return PlayerEntity.SleepFailureReason.NOT_POSSIBLE_NOW; + } + return null; + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/ChatMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/ChatMixin.java index 568e120..7e04ec1 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/ChatMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/ChatMixin.java @@ -13,19 +13,18 @@ @Mixin(ServerPlayNetworkHandler.class) public abstract class ChatMixin { - @Shadow - public ServerPlayerEntity player; + @Shadow + public ServerPlayerEntity player; - @Shadow - private static boolean hasIllegalCharacter(String message) { - return false; - } + @Shadow + private static boolean hasIllegalCharacter(String message) { + return false; + } - @Inject(method = "onChatMessage", at = @At("HEAD"), cancellable = true) - private void onChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) { - if (!hasIllegalCharacter(packet.chatMessage())) { - if (!packet.chatMessage().startsWith("/") && (this.player.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_CHAT))) - ci.cancel(); - } - } + @Inject(method = "onChatMessage", at = @At("HEAD"), cancellable = true) + private void onChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) { + if (!hasIllegalCharacter(packet.chatMessage())) { + if (!packet.chatMessage().startsWith("/") && (this.player.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_CHAT))) ci.cancel(); + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/EnderDragonFightMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/EnderDragonFightMixin.java index 3d9e233..bb1dcf4 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/EnderDragonFightMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/EnderDragonFightMixin.java @@ -13,15 +13,15 @@ @Mixin(EnderDragonFight.class) public class EnderDragonFightMixin { - @Shadow - private boolean previouslyKilled; + @Shadow + private boolean previouslyKilled; - @Shadow - @Final + @Shadow + @Final private ServerWorld world; - @Redirect(method = "dragonKilled", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonFight;previouslyKilled:Z", opcode = Opcodes.GETFIELD)) - private boolean dragonKilled(EnderDragonFight instance) { - return this.previouslyKilled && !this.world.getGameRules().getBoolean(Gamerules.ALWAYS_SPAWN_DRAGON_EGG); - } + @Redirect(method = "dragonKilled", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonFight;previouslyKilled:Z", opcode = Opcodes.GETFIELD)) + private boolean dragonKilled(EnderDragonFight instance) { + return this.previouslyKilled && !this.world.getGameRules().getBoolean(Gamerules.ALWAYS_SPAWN_DRAGON_EGG); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/PoisonStatusEffectMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/PoisonStatusEffectMixin.java new file mode 100644 index 0000000..8a52d27 --- /dev/null +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/PoisonStatusEffectMixin.java @@ -0,0 +1,29 @@ +package com.mmodding.notenoughgamerules.mixin; + +import com.mmodding.notenoughgamerules.Gamerules; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffect; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.entity.effect.PoisonStatusEffect") +public class PoisonStatusEffectMixin { + + @Unique + private LivingEntity entity; + + @Inject(method = "applyUpdateEffect", at = @At("HEAD")) + private void applyUpdateEffectInjection(LivingEntity entity, int amplifier, CallbackInfo ci) { + this.entity = entity; + } + + @ModifyConstant(method = "applyUpdateEffect", constant = @Constant(floatValue = 1.0F, ordinal = 1)) + private float applyUpdateEffectConstantModifier(float constant) { + return (float) this.entity.getWorld().getGameRules().getInt(Gamerules.POISON_HEALTH); + } +} diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/ServerWorldMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/ServerWorldMixin.java index 7d44c81..c602eb5 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/ServerWorldMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/ServerWorldMixin.java @@ -1,5 +1,8 @@ package com.mmodding.notenoughgamerules.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.mmodding.notenoughgamerules.Gamerules; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; @@ -9,21 +12,20 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ServerWorld.class) public abstract class ServerWorldMixin { - @Shadow - public abstract MinecraftServer getServer(); + @Shadow + public abstract MinecraftServer getServer(); - @Redirect(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetIce(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z")) - private boolean tickChunkIceRedirection(Biome instance, WorldView world, BlockPos blockPos) { - return instance.canSetIce(world, blockPos) && this.getServer().getGameRules().getBoolean(Gamerules.DO_ICE_FORM); - } + @ModifyExpressionValue(method = "tickIceAndSnow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetIce(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z")) + private boolean tickChunkIceRedirection(boolean original) { + return original && this.getServer().getGameRules().getBoolean(Gamerules.DO_ICE_FORM); + } - @Redirect(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetSnow(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z")) - private boolean tickChunkSnowRedirection(Biome instance, WorldView world, BlockPos blockPos) { - return instance.canSetSnow(world, blockPos) && this.getServer().getGameRules().getBoolean(Gamerules.DO_SNOW_MELT); - } + @ModifyExpressionValue(method = "tickIceAndSnow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetSnow(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z")) + private boolean tickChunkSnowRedirection(boolean original) { + return original && this.getServer().getGameRules().getBoolean(Gamerules.DO_SNOW_MELT); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/StatusEffectMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/StatusEffectMixin.java deleted file mode 100644 index 7f82a61..0000000 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/StatusEffectMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mmodding.notenoughgamerules.mixin; - -import com.mmodding.notenoughgamerules.Gamerules; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(StatusEffect.class) -public class StatusEffectMixin { - - @Unique - private LivingEntity entity; - - @Inject(method = "applyUpdateEffect", at = @At("HEAD")) - private void applyUpdateEffectInjection(LivingEntity entity, int amplifier, CallbackInfo ci) { - this.entity = entity; - } - - @ModifyConstant(method = "applyUpdateEffect", constant = @Constant(floatValue = 1.0F, ordinal = 1)) - private float applyUpdateEffectConstantModifier(float constant) { - return (float) entity.getWorld().getGameRules().getInt(Gamerules.POISON_HEALTH); - } -} diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/AbstractBlockStateMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/AbstractBlockStateMixin.java index 8a4454f..f1777d3 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/AbstractBlockStateMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/AbstractBlockStateMixin.java @@ -17,14 +17,15 @@ @Mixin(AbstractBlock.AbstractBlockState.class) public class AbstractBlockStateMixin { - @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) + + @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) private void onEntityCollision(World world, BlockPos pos, Entity entity, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_WORLD)) ci.cancel(); - } + if (!world.getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_WORLD)) ci.cancel(); + } - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) + @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) private void onUse(World world, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_BLOCK)) - cir.setReturnValue(ActionResult.PASS); - } + if (!world.getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_BLOCK)) + cir.setReturnValue(ActionResult.PASS); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockBlockMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockBlockMixin.java index 3cbbd8f..5ea1169 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockBlockMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockBlockMixin.java @@ -13,8 +13,9 @@ @Mixin(CoralBlockBlock.class) public class CoralBlockBlockMixin { + @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); - } + if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockMixin.java index 4378264..626c389 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralBlockMixin.java @@ -13,8 +13,9 @@ @Mixin(CoralBlock.class) public class CoralBlockMixin { - @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) - private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); - } + + @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) + private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralFanMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralFanMixin.java index bb688b4..aae2565 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralFanMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralFanMixin.java @@ -13,8 +13,9 @@ @Mixin(CoralFanBlock.class) public class CoralFanMixin { - @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) - private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); - } + + @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) + private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralWallFanMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralWallFanMixin.java index 7fa1b7d..caa2b1b 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralWallFanMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/CoralWallFanMixin.java @@ -13,8 +13,9 @@ @Mixin(CoralWallFanBlock.class) public class CoralWallFanMixin { - @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) - private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); - } + + @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) + private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_CORAL_NEED_WATER)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/IceBlockMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/IceBlockMixin.java index 87b7105..fffa46d 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/IceBlockMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/IceBlockMixin.java @@ -13,8 +13,9 @@ @Mixin(IceBlock.class) public class IceBlockMixin { - @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) - private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_ICE_MELT)) ci.cancel(); - } + + @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) + private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_ICE_MELT)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/OxidizableBlockMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/OxidizableBlockMixin.java index 6cda7bb..ced5e88 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/OxidizableBlockMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/OxidizableBlockMixin.java @@ -13,8 +13,9 @@ @Mixin(OxidizableBlock.class) public class OxidizableBlockMixin { - @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) - private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.CAN_COPPER_OXIDE)) ci.cancel(); - } + + @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) + private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.CAN_COPPER_OXIDE)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/PistonMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/PistonMixin.java index e23019b..4052171 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/PistonMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/PistonMixin.java @@ -13,8 +13,9 @@ @Mixin(PistonBlock.class) public class PistonMixin { - @Inject(method = "shouldExtend", at = @At("HEAD"), cancellable = true) - private void shouldExtend(RedstoneView view, BlockPos pos, Direction pistonFace, CallbackInfoReturnable cir) { - if (view instanceof World world && world.getGameRules().getBoolean(Gamerules.DISABLE_PISTONS)) cir.setReturnValue(false); - } + + @Inject(method = "shouldExtend", at = @At("HEAD"), cancellable = true) + private void shouldExtend(RedstoneView view, BlockPos pos, Direction pistonFace, CallbackInfoReturnable cir) { + if (view instanceof World world && world.getGameRules().getBoolean(Gamerules.DISABLE_PISTONS)) cir.setReturnValue(false); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/SnowBlockMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/SnowBlockMixin.java index 6f1c0ae..32496ce 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/SnowBlockMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/blocks/SnowBlockMixin.java @@ -13,8 +13,9 @@ @Mixin(SnowBlock.class) public class SnowBlockMixin { - @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) - private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_SNOW_MELT)) ci.cancel(); - } + + @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) + private void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_SNOW_MELT)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMateGoalMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMateGoalMixin.java index a512452..7284bb5 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMateGoalMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMateGoalMixin.java @@ -9,5 +9,7 @@ @Mixin(AnimalMateGoal.class) public class AnimalMateGoalMixin { - @Shadow @Final protected AnimalEntity animal; + @Shadow + @Final + protected AnimalEntity animal; } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMixin.java index ee4bdc8..2c59a5a 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/AnimalMixin.java @@ -11,8 +11,8 @@ @Mixin(AnimalEntity.class) public class AnimalMixin { - @Inject(method = "breed(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/AnimalEntity;)V", at = @At("HEAD"), cancellable = true) - private void breed(ServerWorld world, AnimalEntity other, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_BABIES_SPAWN)) ci.cancel(); - } + @Inject(method = "breed(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/passive/AnimalEntity;)V", at = @At("HEAD"), cancellable = true) + private void breed(ServerWorld world, AnimalEntity other, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_BABIES_SPAWN)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/EntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/EntityMixin.java index fd0aa64..3a987b5 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/EntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/EntityMixin.java @@ -16,31 +16,33 @@ @Mixin(Entity.class) public abstract class EntityMixin { - @Shadow - public int age; + @Shadow + public int age; - @Shadow - public abstract int getId(); + @Shadow + public abstract int getId(); - @Shadow - public void onStruckByLightning(ServerWorld world, LightningEntity lightning) {} + @Shadow + public void onStruckByLightning(ServerWorld world, LightningEntity lightning) {} - @Shadow - public abstract boolean damage(DamageSource source, float amount); + @Shadow + public abstract boolean damage(DamageSource source, float amount); - @Shadow - public abstract double getY(); + @Shadow + public abstract double getY(); - @Shadow public abstract DamageSources getDamageSources(); + @Shadow + public abstract DamageSources getDamageSources(); - @Shadow public abstract World getWorld(); + @Shadow + public abstract World getWorld(); - @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) - private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { - int lightningDamage = lightning.getWorld().getGameRules().getInt(Gamerules.LIGHTNING_DAMAGE); - if (lightningDamage > -1) { - this.damage(this.getDamageSources().lightningBolt(), (float) lightningDamage); - ci.cancel(); + @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) + private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { + int lightningDamage = lightning.getWorld().getGameRules().getInt(Gamerules.LIGHTNING_DAMAGE); + if (lightningDamage > -1) { + this.damage(this.getDamageSources().lightningBolt(), (float) lightningDamage); + ci.cancel(); } } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/FoxBreadMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/FoxBreadMixin.java index d42b69e..5ec8b9d 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/FoxBreadMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/FoxBreadMixin.java @@ -9,8 +9,8 @@ @Mixin(targets = "net.minecraft.entity.passive.FoxEntity$MateGoal") public class FoxBreadMixin extends AnimalMateGoalMixin { - @Inject(method = "breed", at = @At("HEAD"), cancellable = true) - private void bread(CallbackInfo ci) { - if (!this.animal.getWorld().getGameRules().getBoolean(Gamerules.DO_BABIES_SPAWN)) ci.cancel(); - } + @Inject(method = "breed", at = @At("HEAD"), cancellable = true) + private void bread(CallbackInfo ci) { + if (!this.animal.getWorld().getGameRules().getBoolean(Gamerules.DO_BABIES_SPAWN)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/HoglinMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/HoglinMixin.java index abe107f..63e0c41 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/HoglinMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/HoglinMixin.java @@ -9,8 +9,9 @@ @Mixin(HoglinEntity.class) public abstract class HoglinMixin extends EntityMixin { - @Inject(method = "canConvert", at = @At("RETURN"), cancellable = true) - private void canConvert(CallbackInfoReturnable cir) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) cir.setReturnValue(false); - } + + @Inject(method = "canConvert", at = @At("RETURN"), cancellable = true) + private void canConvert(CallbackInfoReturnable cir) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) cir.setReturnValue(false); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/LivingEntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/LivingEntityMixin.java index 529004e..be0c16c 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/LivingEntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/LivingEntityMixin.java @@ -20,32 +20,32 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin extends EntityMixin { - @Shadow - protected ItemStack activeItemStack; + @Shadow + protected ItemStack activeItemStack; - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - Entity entity = this.getWorld().getEntityById(this.getId()); - assert entity != null; - NotEnoughGamerules.damageGamerule(entity, source, cir); - } + @Inject(method = "damage", at = @At("HEAD"), cancellable = true) + private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { + Entity entity = this.getWorld().getEntityById(this.getId()); + assert entity != null; + NotEnoughGamerules.damageGamerule(entity, source, cir); + } - @Inject(method = "takeKnockback", at = @At("HEAD"), cancellable = true) - private void takeKnockback(double strength, double x, double z, CallbackInfo ci) { - if (this.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_KNOCKBACK)) ci.cancel(); - } + @Inject(method = "takeKnockback", at = @At("HEAD"), cancellable = true) + private void takeKnockback(double strength, double x, double z, CallbackInfo ci) { + if (this.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_KNOCKBACK)) ci.cancel(); + } - @Inject(method = "consumeItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;finishUsing(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;", shift = At.Shift.AFTER)) - private void consumeItem(CallbackInfo ci) { - ItemStack itemStack = this.activeItemStack; - if (this.getWorld().getEntityById(this.getId()) instanceof PlayerEntity playerEntity) { - if ((Math.random() <= ((float) (this.getWorld().getGameRules().getInt(Gamerules.RAW_MEAT_HUNGER) / 100))) - && ((itemStack.getItem() == Items.BEEF) || (itemStack.getItem() == Items.CHICKEN) - || (itemStack.getItem() == Items.COD) || (itemStack.getItem() == Items.MUTTON) - || (itemStack.getItem() == Items.RABBIT) || (itemStack.getItem() == Items.PORKCHOP) - || (itemStack.getItem() == Items.SALMON))) { - playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.HUNGER, 600, 1)); - } - } - } + @Inject(method = "consumeItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;finishUsing(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;", shift = At.Shift.AFTER)) + private void consumeItem(CallbackInfo ci) { + ItemStack itemStack = this.activeItemStack; + if (this.getWorld().getEntityById(this.getId()) instanceof PlayerEntity playerEntity) { + if ((Math.random() <= ((float) (this.getWorld().getGameRules().getInt(Gamerules.RAW_MEAT_HUNGER) / 100))) + && ((itemStack.getItem() == Items.BEEF) || (itemStack.getItem() == Items.CHICKEN) + || (itemStack.getItem() == Items.COD) || (itemStack.getItem() == Items.MUTTON) + || (itemStack.getItem() == Items.RABBIT) || (itemStack.getItem() == Items.PORKCHOP) + || (itemStack.getItem() == Items.SALMON))) { + playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.HUNGER, 600, 1)); + } + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/MobEntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/MobEntityMixin.java index b674f97..f4355d8 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/MobEntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/MobEntityMixin.java @@ -6,9 +6,10 @@ @Mixin(MobEntity.class) public abstract class MobEntityMixin extends EntityMixin { - @Shadow - protected void mobTick() {} - @Shadow - public void tick() {} + @Shadow + protected void mobTick() {} + + @Shadow + public void tick() {} } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PigMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PigMixin.java index b0753de..f673e64 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PigMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PigMixin.java @@ -11,11 +11,12 @@ @Mixin(PigEntity.class) public abstract class PigMixin extends EntityMixin { - @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) - private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { - super.onStruckByLightning(world, lightning); - ci.cancel(); - } - } + + @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) + private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { + super.onStruckByLightning(world, lightning); + ci.cancel(); + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PiglinMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PiglinMixin.java index eab7586..0d7e270 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PiglinMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/PiglinMixin.java @@ -9,11 +9,12 @@ @Mixin(AbstractPiglinEntity.class) public abstract class PiglinMixin extends MobEntityMixin { - @Inject(method = "mobTick", at = @At("HEAD"), cancellable = true) - private void mobTick(CallbackInfo ci) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { - super.mobTick(); - ci.cancel(); - } - } + + @Inject(method = "mobTick", at = @At("HEAD"), cancellable = true) + private void mobTick(CallbackInfo ci) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { + super.mobTick(); + ci.cancel(); + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntEntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntEntityMixin.java index 4266e36..a7d6581 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntEntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntEntityMixin.java @@ -9,8 +9,9 @@ @Mixin(TntEntity.class) public abstract class TntEntityMixin extends EntityMixin { - @Inject(method = "explode", at = @At("HEAD"), cancellable = true) - private void explode(CallbackInfo ci) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.TNT_EXPLODES)) ci.cancel(); - } + + @Inject(method = "explode", at = @At("HEAD"), cancellable = true) + private void explode(CallbackInfo ci) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.TNT_EXPLODES)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntMinecartEntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntMinecartEntityMixin.java index 546e833..f2f1f75 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntMinecartEntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/TntMinecartEntityMixin.java @@ -10,8 +10,9 @@ @Mixin(TntMinecartEntity.class) public abstract class TntMinecartEntityMixin extends EntityMixin { - @Inject(method = "explode(Lnet/minecraft/entity/damage/DamageSource;D)V", at = @At("HEAD"), cancellable = true) - private void explode(DamageSource damageSource, double power, CallbackInfo ci) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.TNT_EXPLODES)) ci.cancel(); - } + + @Inject(method = "explode(Lnet/minecraft/entity/damage/DamageSource;D)V", at = @At("HEAD"), cancellable = true) + private void explode(DamageSource damageSource, double power, CallbackInfo ci) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.TNT_EXPLODES)) ci.cancel(); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/VillagerMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/VillagerMixin.java index 33f018d..ab806ed 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/VillagerMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/VillagerMixin.java @@ -11,11 +11,12 @@ @Mixin(VillagerEntity.class) public abstract class VillagerMixin extends EntityMixin { - @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) - private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { - if (!world.getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { - super.onStruckByLightning(world, lightning); - ci.cancel(); - } - } + + @Inject(method = "onStruckByLightning", at = @At("HEAD"), cancellable = true) + private void onStruckByLightning(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { + if (!world.getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { + super.onStruckByLightning(world, lightning); + ci.cancel(); + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieMixin.java index a206fd3..0ea3123 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieMixin.java @@ -13,18 +13,18 @@ @Mixin(ZombieEntity.class) public abstract class ZombieMixin extends MobEntityMixin { - @Inject(method = "tick", at = @At("HEAD"), cancellable = true) - private void tick(CallbackInfo ci) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { - super.tick(); - ci.cancel(); - } - } + @Inject(method = "tick", at = @At("HEAD"), cancellable = true) + private void tick(CallbackInfo ci) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { + super.tick(); + ci.cancel(); + } + } - @Redirect(method = "onKilledOther", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextBoolean()Z")) - private boolean changeBoolean(Random instance) { - float randomFloat = instance.nextFloat(); - float villagerConversion = (float) this.getWorld().getGameRules().getInt(Gamerules.VILLAGER_CONVERSION) / 100; - return this.getWorld().getDifficulty() == Difficulty.NORMAL ? randomFloat >= villagerConversion : randomFloat < villagerConversion; - } + @Redirect(method = "onKilledOther", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextBoolean()Z")) + private boolean changeBoolean(Random instance) { + float randomFloat = instance.nextFloat(); + float villagerConversion = (float) this.getWorld().getGameRules().getInt(Gamerules.VILLAGER_CONVERSION) / 100; + return this.getWorld().getDifficulty() == Difficulty.NORMAL ? randomFloat >= villagerConversion : randomFloat < villagerConversion; + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieVillagerMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieVillagerMixin.java index eb90aa7..4b25420 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieVillagerMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/entities/ZombieVillagerMixin.java @@ -10,11 +10,11 @@ @Mixin(ZombieVillagerEntity.class) public abstract class ZombieVillagerMixin extends MobEntityMixin { - @Inject(method = "tick", at = @At("HEAD"), cancellable = true) - private void tick(CallbackInfo ci) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { - super.tick(); - ci.cancel(); - } - } + @Inject(method = "tick", at = @At("HEAD"), cancellable = true) + private void tick(CallbackInfo ci) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.DO_TRANSFORMATIONS)) { + super.tick(); + ci.cancel(); + } + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ClientPlayerMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ClientPlayerMixin.java index 6424669..135bdaa 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ClientPlayerMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ClientPlayerMixin.java @@ -12,10 +12,11 @@ @Mixin(ClientPlayerEntity.class) public abstract class ClientPlayerMixin extends LivingEntityMixin { - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - Entity entity = this.getWorld().getEntityById(this.getId()); - assert entity != null; - NotEnoughGamerules.damageGamerule(entity, source, cir); - } + + @Inject(method = "damage", at = @At("HEAD"), cancellable = true) + private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { + Entity entity = this.getWorld().getEntityById(this.getId()); + assert entity != null; + NotEnoughGamerules.damageGamerule(entity, source, cir); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/OtherClientPlayerEntityMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/OtherClientPlayerEntityMixin.java index 8681cc5..55c7b35 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/OtherClientPlayerEntityMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/OtherClientPlayerEntityMixin.java @@ -13,10 +13,10 @@ @Mixin(OtherClientPlayerEntity.class) public abstract class OtherClientPlayerEntityMixin extends LivingEntityMixin { - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - Entity entity = this.getWorld().getEntityById(this.getId()); - assert entity != null; - NotEnoughGamerules.damageGamerule(entity, source, cir); - } + @Inject(method = "damage", at = @At("HEAD"), cancellable = true) + private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { + Entity entity = this.getWorld().getEntityById(this.getId()); + assert entity != null; + NotEnoughGamerules.damageGamerule(entity, source, cir); + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/PlayerMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/PlayerMixin.java index 1a33d67..dd26c14 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/PlayerMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/PlayerMixin.java @@ -22,54 +22,59 @@ @Mixin(PlayerEntity.class) public abstract class PlayerMixin extends LivingEntityMixin { - @Shadow - public float experienceProgress; - @Shadow - public int experienceLevel; - @Shadow - public int totalExperience; - @Shadow - protected HungerManager hungerManager; - @Shadow - public abstract void sendMessage(Text message, boolean actionBar); + @Shadow + public float experienceProgress; - @Shadow - public abstract boolean damage(DamageSource source, float amount); + @Shadow + public int experienceLevel; - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.CAN_PLAYER_TAKE_DAMAGE)) cir.cancel(); - Entity entity = this.getWorld().getEntityById(this.getId()); - assert entity != null; - NotEnoughGamerules.damageGamerule(entity, source, cir); - } + @Shadow + public int totalExperience; - @Inject(method = "tick", at = @At("TAIL"), cancellable = true) - private void tick(CallbackInfo ci) { - if (this.getWorld().isClient) ci.cancel(); + @Shadow + protected HungerManager hungerManager; - int naturalHunger = this.getWorld().getGameRules().getInt(Gamerules.NATURAL_HUNGER); - if ((naturalHunger > -1) && (this.hungerManager.getFoodLevel() < naturalHunger)) { - this.hungerManager.setFoodLevel(20); - } - if (this.getY() < this.getWorld().getGameRules().getInt(Gamerules.SKY_HIGH)) { - this.sendMessage(Text.translatable("message.not_enough_gamerules.sky_high_warning"), true); + @Shadow + public abstract void sendMessage(Text message, boolean actionBar); + + @Shadow + public abstract boolean damage(DamageSource source, float amount); + + @Inject(method = "damage", at = @At("HEAD"), cancellable = true) + private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.CAN_PLAYER_TAKE_DAMAGE)) cir.cancel(); + Entity entity = this.getWorld().getEntityById(this.getId()); + assert entity != null; + NotEnoughGamerules.damageGamerule(entity, source, cir); + } - if (this.getWorld().getTime() % 200 == 0 && this.age > 199) { - this.damage(this.getDamageSources().create(NEGDamageTypes.SKY_HIGH), (float) 10); - } + @Inject(method = "tick", at = @At("TAIL"), cancellable = true) + private void tick(CallbackInfo ci) { + if (this.getWorld().isClient) ci.cancel(); + + int naturalHunger = this.getWorld().getGameRules().getInt(Gamerules.NATURAL_HUNGER); + if ((naturalHunger > -1) && (this.hungerManager.getFoodLevel() < naturalHunger)) { + this.hungerManager.setFoodLevel(20); } - } - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - private void interact(CallbackInfoReturnable cir) { - if (!this.getWorld().getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_ENTITIES)) - cir.setReturnValue(ActionResult.PASS); - } + if (this.getY() < this.getWorld().getGameRules().getInt(Gamerules.SKY_HIGH)) { + this.sendMessage(Text.translatable("message.not_enough_gamerules.sky_high_warning"), true); + + if (this.getWorld().getTime() % 200 == 0 && this.age > 199) { + this.damage(this.getDamageSources().create(NEGDamageTypes.SKY_HIGH), (float) 10); + } + } + } + + @Inject(method = "interact", at = @At("HEAD"), cancellable = true) + private void interact(CallbackInfoReturnable cir) { + if (!this.getWorld().getGameRules().getBoolean(Gamerules.CAN_ENTITY_INTERACT_WITH_ENTITIES)) + cir.setReturnValue(ActionResult.PASS); + } - @Redirect(method = "getXpToDrop", at = @At(value = "FIELD", target = "Lnet/minecraft/world/GameRules;KEEP_INVENTORY:Lnet/minecraft/world/GameRules$Key;", opcode = Opcodes.GETSTATIC)) - private GameRules.Key getXpToDrop() { - return Gamerules.KEEP_XP; - } + @Redirect(method = "getXpToDrop", at = @At(value = "FIELD", target = "Lnet/minecraft/world/GameRules;KEEP_INVENTORY:Lnet/minecraft/world/GameRules$Key;", opcode = Opcodes.GETSTATIC)) + private GameRules.Key getXpToDrop() { + return Gamerules.KEEP_XP; + } } diff --git a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ServerPlayerMixin.java b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ServerPlayerMixin.java index 5db887a..d618d89 100644 --- a/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ServerPlayerMixin.java +++ b/src/main/java/com/mmodding/notenoughgamerules/mixin/player/ServerPlayerMixin.java @@ -15,32 +15,31 @@ @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerMixin extends PlayerMixin { - @Inject(method = "moveToWorld", at = @At("HEAD"), cancellable = true) - private void moveToWorld(ServerWorld destination, CallbackInfoReturnable cir) { - if (destination.getGameRules().getBoolean(Gamerules.DISABLE_DIMENSION_CHANGE)) cir.cancel(); - } - - @Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At("HEAD"), cancellable = true) - private void teleport(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { - if ((targetWorld != this.getWorld()) && (this.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_DIMENSION_CHANGE))) - ci.cancel(); - } - - @Inject(method = "copyFrom", at = @At("TAIL")) - private void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) { - if (this.getWorld().getGameRules().getBoolean(Gamerules.KEEP_XP)) { - this.experienceLevel = oldPlayer.experienceLevel; - this.totalExperience = oldPlayer.totalExperience; - this.experienceProgress = oldPlayer.experienceProgress; - } - } - - @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;experienceLevel:I", opcode = Opcodes.PUTFIELD, ordinal = 1)) - private void copyFromExperienceLevel(ServerPlayerEntity instance, int value) {} - - @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;totalExperience:I", opcode = Opcodes.PUTFIELD, ordinal = 1)) - private void copyFromTotalExperience(ServerPlayerEntity instance, int value) {} - - @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;experienceProgress:F", opcode = Opcodes.PUTFIELD, ordinal = 1)) - private void copyFromExperienceProgress(ServerPlayerEntity instance, float value) {} + @Inject(method = "moveToWorld", at = @At("HEAD"), cancellable = true) + private void moveToWorld(ServerWorld destination, CallbackInfoReturnable cir) { + if (destination.getGameRules().getBoolean(Gamerules.DISABLE_DIMENSION_CHANGE)) cir.cancel(); + } + + @Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At("HEAD"), cancellable = true) + private void teleport(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { + if ((targetWorld != this.getWorld()) && (this.getWorld().getGameRules().getBoolean(Gamerules.DISABLE_DIMENSION_CHANGE))) ci.cancel(); + } + + @Inject(method = "copyFrom", at = @At("TAIL")) + private void copyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci) { + if (this.getWorld().getGameRules().getBoolean(Gamerules.KEEP_XP)) { + this.experienceLevel = oldPlayer.experienceLevel; + this.totalExperience = oldPlayer.totalExperience; + this.experienceProgress = oldPlayer.experienceProgress; + } + } + + @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;experienceLevel:I", opcode = Opcodes.PUTFIELD, ordinal = 1)) + private void copyFromExperienceLevel(ServerPlayerEntity instance, int value) {} + + @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;totalExperience:I", opcode = Opcodes.PUTFIELD, ordinal = 1)) + private void copyFromTotalExperience(ServerPlayerEntity instance, int value) {} + + @Redirect(method = "copyFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayerEntity;experienceProgress:F", opcode = Opcodes.PUTFIELD, ordinal = 1)) + private void copyFromExperienceProgress(ServerPlayerEntity instance, float value) {} } diff --git a/src/main/resources/not_enough_gamerules.mixins.json b/src/main/resources/not_enough_gamerules.mixins.json index b376634..877fb35 100644 --- a/src/main/resources/not_enough_gamerules.mixins.json +++ b/src/main/resources/not_enough_gamerules.mixins.json @@ -7,7 +7,7 @@ "ChatMixin", "EnderDragonFightMixin", "ServerWorldMixin", - "StatusEffectMixin", + "PoisonStatusEffectMixin", "blocks.AbstractBlockStateMixin", "blocks.CoralBlockBlockMixin", "blocks.CoralBlockMixin",