Skip to content

Commit

Permalink
Use gamerule for entity mutability instead
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEpicBlock committed Nov 16, 2024
1 parent b43e2aa commit 744dfe8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
14 changes: 10 additions & 4 deletions src/main/java/net/modfest/fireblanket/Fireblanket.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
Expand All @@ -28,6 +29,7 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.GameRules;
import net.modfest.fireblanket.command.CmdFindReplaceCommand;
import net.modfest.fireblanket.command.DumpCommand;
import net.modfest.fireblanket.command.RegionCommand;
Expand All @@ -49,9 +51,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
Expand All @@ -61,6 +60,13 @@ public class Fireblanket implements ModInitializer {
public static final Identifier FULL_STREAM_COMPRESSION = Identifier.of("fireblanket", "full_stream_compression");
public static final Identifier REGIONS_UPDATE = Identifier.of("fireblanket", "regions_update");

/**
* Whether new entities will be fixed.
* @see net.modfest.fireblanket.mixin.entity_immutability
*/
public static final GameRules.Key<GameRules.BooleanRule> NEW_ENTITIES_IMMUTABLE =
GameRuleRegistry.register("newEntitiesImmutable", GameRules.Category.MOBS, GameRuleFactory.createBooleanRule(true));

public static final Logger LOGGER = LoggerFactory.getLogger("Fireblanket");

public record QueuedPacket(ClientConnection conn, Packet<?> packet, PacketCallbacks listener) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/net/modfest/fireblanket/FireblanketMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return FireblanketConfig.get(ConfigSpecs.FLATTEN_CHUNK_PALETTES);
}

if (mixinClassName.contains("entity_immutability")) {
return FireblanketConfig.get(ConfigSpecs.ENTITY_IMMUTABILITY);
}

if (mixinClassName.contains("ai") || mixinClassName.contains("sounds")) {
return FireblanketConfig.get(ConfigSpecs.GAMEPLAY_CHANGES);
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/net/modfest/fireblanket/config/ConfigSpecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public final class ConfigSpecs {
Disables the usage of zstd to save world data and compress network connections.
""", "no", ConfigParsers.BOOLEAN);

public static final ConfigSpec<Boolean> ENTITY_IMMUTABILITY = new ConfigSpec<>("entity-immutability", "Entity Immutability by Default",
"""
Makes entities default to being immutable. For example, it will set frames to fixed by default.
""", "no", ConfigParsers.BOOLEAN);

public static final ConfigSpec<Boolean> GAMEPLAY_CHANGES = new ConfigSpec<>("gameplay-changes", "Gameplay Changes",
"""
Allow altering features in a way that impacts gameplay.
Expand All @@ -72,7 +67,6 @@ private static void buildMap() {
ALL_SPECS.add(FLATTEN_CHUNK_PALETTES);
ALL_SPECS.add(ALLOW_FOOTGUNS);
ALL_SPECS.add(AVOID_ZSTD);
ALL_SPECS.add(ENTITY_IMMUTABILITY);
ALL_SPECS.add(GAMEPLAY_CHANGES);

// We have registries at home:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.world.World;
import net.modfest.fireblanket.Fireblanket;
import net.modfest.fireblanket.mixinsupport.ImmmovableLivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -16,12 +17,14 @@ public class MixinArmorStand {
private int disabledSlots;

@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
private void onInit(EntityType entityType, World world, CallbackInfo ci) {
// Disable all slots by default
this.disabledSlots = 4144959;
// Disable movement (prevents abuse of fishing rods)
if (this instanceof ImmmovableLivingEntity im) {
im.setNoMovement(true);
private void onInit(EntityType<?> entityType, World world, CallbackInfo ci) {
if (world.getGameRules().getBoolean(Fireblanket.NEW_ENTITIES_IMMUTABLE)) {
// Disable all slots by default
this.disabledSlots = 4144959;
// Disable movement (prevents abuse of fishing rods)
if (this instanceof ImmmovableLivingEntity im) {
im.setNoMovement(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.world.World;
import net.modfest.fireblanket.Fireblanket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,7 +16,9 @@ public class MixinItemFrame {
private boolean fixed;

@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
private void onInit(EntityType entityType, World world, CallbackInfo ci) {
this.fixed = true;
private void onInit(EntityType<?> entityType, World world, CallbackInfo ci) {
if (world.getGameRules().getBoolean(Fireblanket.NEW_ENTITIES_IMMUTABLE)) {
this.fixed = true;
}
}
}
5 changes: 3 additions & 2 deletions src/main/resources/assets/fireblanket/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"argument.entity.selector.limit.unforced": "Targeting too many entities with no distance filter; add `force=true` to the selector to bypass",
"argument.entity.options.force.description": "Force-allow more than 50 entities targeted with no distance filter"
}
"argument.entity.options.force.description": "Force-allow more than 50 entities targeted with no distance filter",
"gamerule.newEntitiesImmutable": "Whether newly spawned entities should be immutable. (Item frames will be fixed for example"
}

0 comments on commit 744dfe8

Please sign in to comment.