Skip to content

Commit

Permalink
Added phantom mobcap rule
Browse files Browse the repository at this point in the history
  • Loading branch information
legoraft committed Nov 8, 2023
1 parent 325e128 commit 07aa987
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/survivaltweaks/commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
})
)
)
.then(CommandManager.literal("phantomMobcap").executes(c -> { c.getSource().sendMessage(Text.translatable("commands.tweak.query", "phantomMobcap", config.PHANTOM_MOBCAP)); return 1;})
.then(CommandManager.argument("boolean", bool())
.executes(c -> {
config.PHANTOM_MOBCAP = getBool(c, "boolean");
applyChanges();
c.getSource().sendMessage(Text.translatable("commands.tweak.set", "phantomMobcap", config.PHANTOM_MOBCAP));
return 1;
})
)
)
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/survivaltweaks/config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class config {
public static boolean CHEAP_RENAME = false;
public static boolean NO_ENDERMAN_GRIEF = false;
public static boolean NO_XP_PENALTY = false;
public static boolean PHANTOM_MOBCAP = false;


private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("survivaltweaks.properties");

Expand All @@ -24,6 +26,7 @@ public void write(Properties properties) {
properties.setProperty("cheap_rename", Boolean.toString(CHEAP_RENAME));
properties.setProperty("no_enderman_grief", Boolean.toString(NO_ENDERMAN_GRIEF));
properties.setProperty("no_xp_penalty", Boolean.toString(NO_XP_PENALTY));
properties.setProperty("phantom_mobcap", Boolean.toString(PHANTOM_MOBCAP));
}

public void read(Properties properties) {
Expand All @@ -32,6 +35,7 @@ public void read(Properties properties) {
CHEAP_RENAME = Boolean.parseBoolean(properties.getProperty("cheap_rename"));
NO_ENDERMAN_GRIEF = Boolean.parseBoolean(properties.getProperty("no_enderman_grief"));
NO_XP_PENALTY = Boolean.parseBoolean(properties.getProperty("no_xp_penalty"));
PHANTOM_MOBCAP = Boolean.parseBoolean(properties.getProperty("phantom_mobcap"));
}

public void save() {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/survivaltweaks/mixin/phantomSpawnerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.survivaltweaks.mixin;

import com.survivaltweaks.config;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.spawner.PhantomSpawner;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PhantomSpawner.class)
public class phantomSpawnerMixin {

@Inject(method = "spawn", at = @At("RETURN"), cancellable = true)
private void phantomSpawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals, CallbackInfoReturnable<Integer> cir) {
if (config.PHANTOM_MOBCAP && SpawnGroup.MONSTER.getCapacity() >= 70) {
cir.setReturnValue(0);
}
}

}

0 comments on commit 07aa987

Please sign in to comment.