Add naturally spawning cold pigs on Sigma
This commit is contained in:
parent
1a1f6c8d09
commit
693037a982
4 changed files with 187 additions and 2 deletions
49
.forgejo/workflows/sigma-cold-pigs.yml
Normal file
49
.forgejo/workflows/sigma-cold-pigs.yml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
name: Sigma Cold Pigs Overlay
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/sigma-cold-pigs-*']
|
||||
|
||||
jobs:
|
||||
sigma-cold-pigs:
|
||||
runs-on: dune-ci
|
||||
steps:
|
||||
- name: Check out exact revision
|
||||
shell: bash
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init .
|
||||
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
|
||||
git checkout --detach FETCH_HEAD
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '9.2.1'
|
||||
- name: Test Terrain and package the reviewed donor class
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p DuneTerrain test jar
|
||||
mkdir sigma-cold-pigs
|
||||
PYTHONPATH=tools python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
from plugin_sigma_cold_pigs import ENTRY
|
||||
from plugin_wild_update import read_archive, write_archive
|
||||
jars = list(Path("DuneTerrain/build/libs").glob("*.jar"))
|
||||
assert len(jars) == 1
|
||||
entries = read_archive(jars[0].read_bytes())
|
||||
Path("sigma-cold-pigs/donor.zip").write_bytes(write_archive({ENTRY: entries[ENTRY]}))
|
||||
PY
|
||||
cp tools/{SigmaColdPigMerge.java,plugin_sigma_cold_pigs.py,plugin_wild_update.py} sigma-cold-pigs/
|
||||
printf '%s\n' "$GITHUB_SHA" > sigma-cold-pigs/SOURCE_COMMIT
|
||||
(cd sigma-cold-pigs && sha256sum -- *.zip *.py *.java SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Sigma-Cold-Pigs
|
||||
path: sigma-cold-pigs
|
||||
if-no-files-found: error
|
||||
|
|
@ -10,13 +10,20 @@ import org.bukkit.plugin.Plugin;
|
|||
public final class PlanetMobs implements Listener {
|
||||
private static final Set<String> NETHER=Set.of("BLAZE","GHAST","HOGLIN","MAGMA_CUBE","PIGLIN","PIGLIN_BRUTE","STRIDER","WITHER_SKELETON","ZOGLIN","ZOMBIFIED_PIGLIN","SKELETON","ENDERMAN");
|
||||
private static final Set<String> PASSIVE=Set.of("ALLAY","ARMADILLO","AXOLOTL","BAT","CAMEL","CAT","CHICKEN","COD","COW","DONKEY","FROG","GLOW_SQUID","HORSE","MUSHROOM_COW","MOOSHROOM","MULE","OCELOT","PARROT","PIG","PUFFERFISH","RABBIT","SALMON","SHEEP","SNIFFER","SNOWMAN","SNOW_GOLEM","SQUID","STRIDER","TADPOLE","TROPICAL_FISH","TURTLE","VILLAGER","WANDERING_TRADER");
|
||||
public static boolean allowed(String planet,String mob,boolean island){return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
|
||||
public static boolean allowed(String planet,String mob,boolean island){if(allowedColdPig(planet,mob))return true;return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
|
||||
public static boolean allowedSpawn(String planet,String mob,boolean island,String reason){return allowed(planet,mob,island)||planet.equals("giedi_prime")&&(reason.equals("SPAWNER")&&Set.of("SKELETON","ZOMBIE","SPIDER","CAVE_SPIDER").contains(mob)||mob.equals("WARDEN"));}
|
||||
public static void start(Plugin plugin){Bukkit.getPluginManager().registerEvents(new PlanetMobs(),plugin);Bukkit.getPluginManager().registerEvents(new NativePlants(),plugin);PlanetSoil.start(plugin);}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void spawning(CreatureSpawnEvent event){var e=event.getEntity();String planet=e.getWorld().getName();if(!TemperateLandscape.enabled(planet))return;
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void spawning(CreatureSpawnEvent event){if(sigmaColdPig(event))return;var e=event.getEntity();String planet=e.getWorld().getName();if(!TemperateLandscape.enabled(planet))return;
|
||||
if(e instanceof PiglinAbstract piglin&&planet.equals("giedi_prime"))piglin.setImmuneToZombification(true);if(e instanceof Hoglin hoglin&&planet.equals("giedi_prime"))hoglin.setImmuneToZombification(true);
|
||||
if(event.getSpawnReason()==CreatureSpawnEvent.SpawnReason.CUSTOM||e.hasMetadata("NPC")||e instanceof Tameable pet&&pet.isTamed())return;
|
||||
var at=e.getLocation();if(planet.equals("sigma_draconis_iv")&&e.getType().name().equals("SULFUR_CUBE")&&at.getBlock().getBiome().getKey().getKey().equals("sulfur_caves"))return;if(!allowedSpawn(planet,e.getType().name(),TemperateLandscape.islandDistance(e.getWorld().getSeed(),at.getBlockX(),at.getBlockZ())<112,event.getSpawnReason().name()))event.setCancelled(true);
|
||||
}
|
||||
private static boolean allowedColdPig(String world,String type){return "sigma_draconis_iv".equals(world)&&"PIG".equals(type);}
|
||||
private static boolean sigmaColdPig(CreatureSpawnEvent event){
|
||||
if(!(event.getEntity() instanceof Pig pig)||!allowedColdPig(pig.getWorld().getName(),"PIG")
|
||||
||event.getSpawnReason()==CreatureSpawnEvent.SpawnReason.CUSTOM||pig.hasMetadata("NPC"))return false;
|
||||
pig.setVariant(Pig.Variant.COLD);
|
||||
return true;
|
||||
}
|
||||
@EventHandler public void loaded(ServerLoadEvent event){var world=Bukkit.getWorld("giedi_prime");if(world!=null){world.setTime(18000);world.setStorm(false);world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE,false);world.setGameRule(GameRule.DO_WEATHER_CYCLE,false);}var arrakis=Bukkit.getWorld("arrakis");if(arrakis!=null)arrakis.setGameRule(GameRule.WATER_SOURCE_CONVERSION,false);}
|
||||
}
|
||||
|
|
|
|||
69
tools/SigmaColdPigMerge.java
Normal file
69
tools/SigmaColdPigMerge.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FrameNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
class SigmaColdPigMerge {
|
||||
private static final String OWNER = "com/example/duneterrain/PlanetMobs";
|
||||
private static final String PIG = "(Ljava/lang/String;Ljava/lang/String;)Z";
|
||||
private static final String SPAWN = "(Lorg/bukkit/event/entity/CreatureSpawnEvent;)";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 3) throw new IllegalArgumentException("Expected retained, donor and output classes");
|
||||
var reader = new ClassReader(Files.readAllBytes(Path.of(args[0])));
|
||||
var retained = parse(reader);
|
||||
var donor = parse(new ClassReader(Files.readAllBytes(Path.of(args[1]))));
|
||||
if (!OWNER.equals(retained.name) || !OWNER.equals(donor.name) ||
|
||||
retained.methods.stream().anyMatch(m -> m.name.equals("sigmaColdPig") || m.name.equals("allowedColdPig"))) {
|
||||
throw new IllegalArgumentException("Unexpected retained PlanetMobs class");
|
||||
}
|
||||
retained.methods.add(method(donor, "sigmaColdPig", SPAWN + "Z"));
|
||||
retained.methods.add(method(donor, "allowedColdPig", PIG));
|
||||
var allowed = method(retained, "allowed", "(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
||||
var check = new InsnList();
|
||||
check.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
check.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
check.add(new MethodInsnNode(Opcodes.INVOKESTATIC, OWNER, "allowedColdPig", PIG, false));
|
||||
prefix(allowed, check, true);
|
||||
var spawning = method(retained, "spawning", SPAWN + "V");
|
||||
var convert = new InsnList();
|
||||
convert.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
convert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, OWNER, "sigmaColdPig", SPAWN + "Z", false));
|
||||
prefix(spawning, convert, false);
|
||||
var writer = new ClassWriter(reader, 0);
|
||||
retained.accept(writer);
|
||||
Files.write(Path.of(args[2]), writer.toByteArray());
|
||||
}
|
||||
|
||||
private static void prefix(MethodNode method, InsnList instructions, boolean returnsValue) {
|
||||
var resume = new LabelNode();
|
||||
instructions.add(new JumpInsnNode(Opcodes.IFEQ, resume));
|
||||
if (returnsValue) instructions.add(new InsnNode(Opcodes.ICONST_1));
|
||||
instructions.add(new InsnNode(returnsValue ? Opcodes.IRETURN : Opcodes.RETURN));
|
||||
instructions.add(resume);
|
||||
instructions.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
method.instructions.insert(instructions);
|
||||
method.maxStack = Math.max(method.maxStack, 2);
|
||||
}
|
||||
|
||||
private static ClassNode parse(ClassReader reader) {
|
||||
var node = new ClassNode();
|
||||
reader.accept(node, 0);
|
||||
return node;
|
||||
}
|
||||
|
||||
private static MethodNode method(ClassNode node, String name, String descriptor) {
|
||||
return node.methods.stream().filter(m -> m.name.equals(name) && m.desc.equals(descriptor))
|
||||
.findFirst().orElseThrow(() -> new IllegalArgumentException("Missing expected method " + name));
|
||||
}
|
||||
}
|
||||
60
tools/plugin_sigma_cold_pigs.py
Normal file
60
tools/plugin_sigma_cold_pigs.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
"""Build the Sigma-only cold pig class graft and two biome mob-list changes."""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from plugin_wild_update import digest, read_archive, write_archive
|
||||
|
||||
TERRAIN_SHA = "2c9d56d64253a8ee49d3411dc32e4da3885e2cd1bc35b00b64ca920f180c1eb5"
|
||||
BIOME_SHA = "0116d155df34e6c9c0482c0f7e21404ea69ea1357819005acfdb110ab748b139"
|
||||
ENTRY = "com/example/duneterrain/PlanetMobs.class"
|
||||
|
||||
|
||||
def checked(path, sha):
|
||||
source = path.read_bytes()
|
||||
if digest(source) != sha:
|
||||
raise ValueError(f"Unreviewed baseline or donor: {path.name}")
|
||||
return read_archive(source)
|
||||
|
||||
|
||||
def assemble(terrain, biomes, donor, donor_sha, terrain_output, biomes_output, classpath):
|
||||
existing = checked(terrain, TERRAIN_SHA)
|
||||
pack = checked(biomes, BIOME_SHA)
|
||||
compiled = checked(donor, donor_sha)
|
||||
for name in ("snowy_plains", "snowy_taiga"):
|
||||
entry = f"data/minecraft/worldgen/biome/{name}.json"
|
||||
data = json.loads(pack[entry])
|
||||
spawners = data["spawners"]["creature"]
|
||||
if any(spawner["type"] == "minecraft:pig" for spawner in spawners):
|
||||
raise ValueError("Pig spawn already registered")
|
||||
spawners.append({"type": "minecraft:pig", "weight": 4, "minCount": 2, "maxCount": 3})
|
||||
pack[entry] = (json.dumps(data, ensure_ascii=False, indent=2) + "\n").encode()
|
||||
java_home = os.environ.get("JAVA_HOME")
|
||||
executable = "java.exe" if os.name == "nt" else "java"
|
||||
java = str(Path(java_home) / "bin" / executable) if java_home else executable
|
||||
with TemporaryDirectory() as temporary:
|
||||
temp = Path(temporary)
|
||||
old, new, merged = (temp / f"{name}.class" for name in ("retained", "donor", "merged"))
|
||||
old.write_bytes(existing[ENTRY])
|
||||
new.write_bytes(compiled[ENTRY])
|
||||
helper = Path(__file__).with_name("SigmaColdPigMerge.java")
|
||||
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
|
||||
existing[ENTRY] = merged.read_bytes()
|
||||
for path, contents in ((terrain_output, existing), (biomes_output, pack)):
|
||||
with path.open("xb") as result:
|
||||
result.write(write_archive(contents))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("terrain", type=Path)
|
||||
parser.add_argument("biomes", type=Path)
|
||||
parser.add_argument("donor", type=Path)
|
||||
parser.add_argument("donor_sha")
|
||||
parser.add_argument("terrain_output", type=Path)
|
||||
parser.add_argument("biomes_output", type=Path)
|
||||
parser.add_argument("classpath", help="ASM core and tree JARs")
|
||||
assemble(**vars(parser.parse_args()))
|
||||
Loading…
Reference in a new issue

Staff