Use standard bundled assets and simplify cauldron interactions
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
# AstraCauldron
|
||||
|
||||
Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**.
|
||||
Требуется **AstraPlus 0.9.2+**.
|
||||
Требуется **AstraPlus 0.9.3+**.
|
||||
Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks.
|
||||
Модели супа зарегистрированы через AstraPlus и берутся из JAR. Пользовательские замены
|
||||
можно положить в `astraplus/resources/assets/astradev_soups`; мод не переписывает их.
|
||||
|
||||
## Режимы котла
|
||||
|
||||
|
||||
+5
-2
@@ -3,10 +3,10 @@ plugins {
|
||||
id("net.neoforged.moddev") version "2.0.146"
|
||||
}
|
||||
group = "online.astradev"
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
repositories { mavenCentral() }
|
||||
val astraPlusApi = providers.gradleProperty("astraPlusApi")
|
||||
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.2.jar")
|
||||
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.3.jar")
|
||||
dependencies {
|
||||
compileOnly(files(astraPlusApi))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||
@@ -25,9 +25,12 @@ tasks.withType<JavaCompile>().configureEach {
|
||||
options.release.set(25)
|
||||
}
|
||||
tasks.processResources {
|
||||
includeEmptyDirs = false
|
||||
inputs.property("modVersion", project.version)
|
||||
filesMatching("META-INF/neoforge.mods.toml") { expand("version" to project.version) }
|
||||
}
|
||||
|
||||
tasks.withType<Jar>().configureEach { includeEmptyDirs = false }
|
||||
tasks.test { useJUnitPlatform() }
|
||||
sourceSets.test {
|
||||
compileClasspath += sourceSets.main.get().compileClasspath
|
||||
|
||||
@@ -22,9 +22,12 @@ import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.neoforge.event.level.*;
|
||||
import net.neoforged.neoforge.event.level.block.BreakBlockEvent;
|
||||
import net.neoforged.neoforge.event.server.*;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
|
||||
import org.slf4j.*;
|
||||
|
||||
@Mod(value = "astracauldron", dist = Dist.DEDICATED_SERVER)
|
||||
@@ -35,7 +38,6 @@ public final class AstraCauldron {
|
||||
private static LiquidPots liquids;
|
||||
|
||||
public AstraCauldron() {
|
||||
NeoForge.EVENT_BUS.addListener(EventPriority.HIGHEST, this::resources);
|
||||
NeoForge.EVENT_BUS.addListener(this::start);
|
||||
NeoForge.EVENT_BUS.addListener(this::stop);
|
||||
NeoForge.EVENT_BUS.addListener(this::tick);
|
||||
@@ -48,17 +50,9 @@ public final class AstraCauldron {
|
||||
NeoForge.EVENT_BUS.addListener(this::commands);
|
||||
}
|
||||
|
||||
private void resources(ServerAboutToStartEvent event) {
|
||||
try {
|
||||
SoupResources.install(FMLPaths.GAMEDIR.get());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot export AstraCauldron resources", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void start(ServerStartedEvent event) {
|
||||
try {
|
||||
online.astradev.plus.api.AstraPlusApi.current()
|
||||
AstraPlusApi.current()
|
||||
.orElseThrow(() -> new IllegalStateException("AstraPlus API unavailable"));
|
||||
pots =
|
||||
new SoupPots(
|
||||
@@ -119,7 +113,7 @@ public final class AstraCauldron {
|
||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||
}
|
||||
|
||||
private void breakBlock(net.neoforged.neoforge.event.level.block.BreakBlockEvent event) {
|
||||
private void breakBlock(BreakBlockEvent event) {
|
||||
if (event.isCanceled() || pots == null) return;
|
||||
if (!(event.getLevel() instanceof ServerLevel level)) return;
|
||||
boolean removed = pots.breakPot(level, event.getPos());
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package online.astradev.cauldron;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CombinationRules {
|
||||
private CombinationRules() {}
|
||||
|
||||
public static boolean matches(Set<String> tags, String selector) {
|
||||
return selector.equals("*") || tags.contains(selector.toLowerCase(java.util.Locale.ROOT));
|
||||
return selector.equals("*") || tags.contains(selector.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static String rejection(
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.server.level.*;
|
||||
import net.minecraft.sounds.*;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import net.minecraft.world.item.alchemy.Potions;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
@@ -64,29 +65,30 @@ public final class LiquidPots implements AutoCloseable {
|
||||
this.server = server;
|
||||
api = AstraPlusApi.current().flatMap(AstraPlusApi::cauldrons).orElseThrow();
|
||||
file = server.getWorldPath(LevelResource.ROOT).resolve("astracauldron/liquids.json");
|
||||
if (Files.exists(file)) {
|
||||
if (Files.exists(file)) load();
|
||||
}
|
||||
|
||||
private void load() throws IOException {
|
||||
var json = JsonParser.parseString(Files.readString(file)).getAsJsonObject();
|
||||
if (json.get("version").getAsInt() != 1)
|
||||
if (json.get("version").getAsInt() != 1) {
|
||||
throw new IllegalArgumentException("Unknown liquid data version");
|
||||
}
|
||||
for (var entry : json.getAsJsonArray("cauldrons")) {
|
||||
var c = entry.getAsJsonObject();
|
||||
var pos =
|
||||
new Position(
|
||||
Identifier.parse(c.get("dimension").getAsString()).toString(),
|
||||
new BlockPos(
|
||||
c.get("x").getAsInt(),
|
||||
c.get("y").getAsInt(),
|
||||
c.get("z").getAsInt()));
|
||||
CauldronApi.Potion potion =
|
||||
c.has("potion")
|
||||
? api.potion(
|
||||
SoupFiles.decode(
|
||||
c.get("potion"), server.registryAccess()))
|
||||
.orElseThrow()
|
||||
: null;
|
||||
var liquid =
|
||||
new Liquid(c.get("levels").getAsInt(), c.get("rgb").getAsInt(), potion);
|
||||
if (liquids.putIfAbsent(pos, liquid) != null)
|
||||
var record = entry.getAsJsonObject();
|
||||
String dimension = Identifier.parse(record.get("dimension").getAsString()).toString();
|
||||
int x = record.get("x").getAsInt();
|
||||
int y = record.get("y").getAsInt();
|
||||
int z = record.get("z").getAsInt();
|
||||
var position = new Position(dimension, new BlockPos(x, y, z));
|
||||
CauldronApi.Potion potion = null;
|
||||
if (record.has("potion")) {
|
||||
ItemStack bottle = SoupFiles.decode(record.get("potion"), server.registryAccess());
|
||||
potion = api.potion(bottle).orElseThrow();
|
||||
}
|
||||
int levels = record.get("levels").getAsInt();
|
||||
int color = record.get("rgb").getAsInt();
|
||||
var liquid = new Liquid(levels, color, potion);
|
||||
if (liquids.putIfAbsent(position, liquid) != null) {
|
||||
throw new IllegalArgumentException("Duplicate liquid cauldron");
|
||||
}
|
||||
}
|
||||
@@ -121,6 +123,18 @@ public final class LiquidPots implements AutoCloseable {
|
||||
if (next == null) liquids.remove(pos);
|
||||
else liquids.put(pos, next);
|
||||
try {
|
||||
save();
|
||||
if (next == null) removeSurface(pos);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (old == null) liquids.remove(pos);
|
||||
else liquids.put(pos, old);
|
||||
AstraCauldron.LOG.error("Не удалось сохранить жидкость; действие отменено", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void save() throws IOException {
|
||||
var root = new JsonObject();
|
||||
root.addProperty("version", 1);
|
||||
var array = new JsonArray();
|
||||
@@ -142,14 +156,6 @@ public final class LiquidPots implements AutoCloseable {
|
||||
array.add(c);
|
||||
}
|
||||
SoupFiles.write(file, root);
|
||||
if (next == null) removeSurface(pos);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (old == null) liquids.remove(pos);
|
||||
else liquids.put(pos, old);
|
||||
AstraCauldron.LOG.error("Не удалось сохранить жидкость; действие отменено", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean interact(ServerPlayer player, BlockPos blockPos, InteractionHand hand) {
|
||||
@@ -159,10 +165,18 @@ public final class LiquidPots implements AutoCloseable {
|
||||
var liquid = liquids.get(pos);
|
||||
if (hand != InteractionHand.MAIN_HAND) return liquid != null;
|
||||
var state = level.getBlockState(blockPos);
|
||||
var held = player.getMainHandItem();
|
||||
if (!state.is(Blocks.CAULDRON) && !state.is(Blocks.WATER_CAULDRON)) return false;
|
||||
if (liquid == null) return fillVanilla(player, pos);
|
||||
if (liquid.potion == null) return useDyedWater(player, pos, liquid);
|
||||
return usePotion(player, pos, liquid);
|
||||
}
|
||||
|
||||
private boolean fillVanilla(ServerPlayer player, Position pos) {
|
||||
var level = player.level();
|
||||
var blockPos = pos.pos;
|
||||
var held = player.getMainHandItem();
|
||||
var state = level.getBlockState(blockPos);
|
||||
var potion = api.potion(held);
|
||||
if (liquid == null) {
|
||||
if (potion.isPresent() && plainWater(potion.get())) {
|
||||
int current =
|
||||
state.is(Blocks.WATER_CAULDRON)
|
||||
@@ -180,12 +194,8 @@ public final class LiquidPots implements AutoCloseable {
|
||||
return true;
|
||||
}
|
||||
var dye = api.mixDye(OptionalInt.empty(), held);
|
||||
if (AstraCauldron.config().dyeWater
|
||||
&& state.is(Blocks.WATER_CAULDRON)
|
||||
&& dye.isPresent()) {
|
||||
var next =
|
||||
new Liquid(
|
||||
state.getValue(LayeredCauldronBlock.LEVEL), dye.getAsInt(), null);
|
||||
if (AstraCauldron.config().dyeWater && state.is(Blocks.WATER_CAULDRON) && dye.isPresent()) {
|
||||
var next = new Liquid(state.getValue(LayeredCauldronBlock.LEVEL), dye.getAsInt(), null);
|
||||
if (!change(pos, next)) {
|
||||
error(player);
|
||||
return true;
|
||||
@@ -201,8 +211,7 @@ public final class LiquidPots implements AutoCloseable {
|
||||
if (AstraCauldron.config().storePotions
|
||||
&& state.is(Blocks.CAULDRON)
|
||||
&& potion.isPresent()) {
|
||||
var next =
|
||||
new Liquid(1, potion.get().contents().getColor() & 0xFFFFFF, potion.get());
|
||||
var next = new Liquid(1, potion.get().contents().getColor() & 0xFFFFFF, potion.get());
|
||||
if (!change(pos, next)) {
|
||||
error(player);
|
||||
return true;
|
||||
@@ -214,7 +223,11 @@ public final class LiquidPots implements AutoCloseable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (liquid.potion == null) {
|
||||
|
||||
private boolean useDyedWater(ServerPlayer player, Position pos, Liquid liquid) {
|
||||
var level = player.level();
|
||||
var blockPos = pos.pos;
|
||||
var held = player.getMainHandItem();
|
||||
var dye = api.mixDye(OptionalInt.of(liquid.rgb), held);
|
||||
if (AstraCauldron.config().dyeWater && dye.isPresent()) {
|
||||
var next = new Liquid(liquid.levels, dye.getAsInt(), null);
|
||||
@@ -248,7 +261,7 @@ public final class LiquidPots implements AutoCloseable {
|
||||
}
|
||||
// Transform the equipped item, including Creative, preserving
|
||||
// enchantments/damage/name.
|
||||
if (held.getCount() == 1) player.setItemInHand(hand, armor.get());
|
||||
if (held.getCount() == 1) player.setItemInHand(InteractionHand.MAIN_HAND, armor.get());
|
||||
else consumeAndGive(player, 1, armor.get());
|
||||
sound(level, blockPos);
|
||||
say(player, "Броня окрашена. Израсходован один уровень воды.");
|
||||
@@ -281,19 +294,19 @@ public final class LiquidPots implements AutoCloseable {
|
||||
error(player);
|
||||
return true;
|
||||
}
|
||||
consumeAndGive(
|
||||
player,
|
||||
1,
|
||||
api.bottle(
|
||||
new CauldronApi.Potion(
|
||||
new net.minecraft.world.item.alchemy.PotionContents(
|
||||
Potions.WATER),
|
||||
1)));
|
||||
var water = new CauldronApi.Potion(new PotionContents(Potions.WATER), 1);
|
||||
consumeAndGive(player, 1, api.bottle(water));
|
||||
return true;
|
||||
}
|
||||
say(player, "Цветная вода: " + liquid.levels + "/3. Для варки супа нужна чистая вода.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean usePotion(ServerPlayer player, Position pos, Liquid liquid) {
|
||||
var level = player.level();
|
||||
var blockPos = pos.pos;
|
||||
var held = player.getMainHandItem();
|
||||
var potion = api.potion(held);
|
||||
if (potion.isPresent()) {
|
||||
if (!AstraCauldron.config().storePotions) return true;
|
||||
if (!potion.get().equals(liquid.potion)) {
|
||||
@@ -384,12 +397,9 @@ public final class LiquidPots implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void surface(ServerLevel level, Position pos, Liquid liquid) {
|
||||
api.water()
|
||||
.show(
|
||||
level,
|
||||
pos.pos,
|
||||
new ColoredWaterApi.Surface(
|
||||
OWNER, liquid.rgb, .375f + .1875f * liquid.levels));
|
||||
float height = 0.375f + 0.1875f * liquid.levels;
|
||||
var surface = new ColoredWaterApi.Surface(OWNER, liquid.rgb, height);
|
||||
api.water().show(level, pos.pos, surface);
|
||||
}
|
||||
|
||||
private ServerLevel level(Position pos) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package online.astradev.cauldron;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -70,13 +72,7 @@ public final class RegisteredRecipes {
|
||||
held.consume(request.inputCount(), player);
|
||||
if (held.isEmpty()) player.setItemInHand(hand, output);
|
||||
else AstraPlusApi.give(player, output);
|
||||
level.playSound(
|
||||
null,
|
||||
pos,
|
||||
net.minecraft.sounds.SoundEvents.BUCKET_EMPTY,
|
||||
net.minecraft.sounds.SoundSource.BLOCKS,
|
||||
0.5F,
|
||||
1);
|
||||
level.playSound(null, pos, SoundEvents.BUCKET_EMPTY, SoundSource.BLOCKS, 0.5F, 1);
|
||||
player.containerMenu.broadcastChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
import online.astradev.plus.api.ColoredWaterApi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
@@ -51,7 +52,7 @@ public final class SoupPots implements AutoCloseable {
|
||||
|
||||
private final MinecraftServer server;
|
||||
private static final Identifier WATER_OWNER = Identifier.parse("astracauldron:cauldrons");
|
||||
private final online.astradev.plus.api.ColoredWaterApi water;
|
||||
private final ColoredWaterApi water;
|
||||
private final Path file;
|
||||
private final Path configFile;
|
||||
private SoupConfig config;
|
||||
@@ -63,10 +64,7 @@ public final class SoupPots implements AutoCloseable {
|
||||
|
||||
public SoupPots(MinecraftServer server, Path configFile) throws IOException {
|
||||
this.server = server;
|
||||
this.water =
|
||||
online.astradev.plus.api.AstraPlusApi.current()
|
||||
.flatMap(api -> api.coloredWater())
|
||||
.orElseThrow();
|
||||
this.water = AstraPlusApi.current().flatMap(api -> api.coloredWater()).orElseThrow();
|
||||
this.file = server.getWorldPath(LevelResource.ROOT).resolve("astracauldron/cauldrons.json");
|
||||
this.configFile = configFile;
|
||||
reload();
|
||||
@@ -104,9 +102,7 @@ public final class SoupPots implements AutoCloseable {
|
||||
var custom = new SoupConfig.Custom();
|
||||
// Resolve by stable AstraPlus identity; definitions can evolve without invalidating the
|
||||
// registration.
|
||||
var plus =
|
||||
online.astradev.plus.api.AstraPlusApi.current()
|
||||
.flatMap(api -> api.find(player.getMainHandItem()));
|
||||
var plus = AstraPlusApi.current().flatMap(api -> api.find(player.getMainHandItem()));
|
||||
if (plus.isPresent()) custom.astraPlusId = plus.get().id().toString();
|
||||
else
|
||||
custom.item =
|
||||
@@ -157,20 +153,35 @@ public final class SoupPots implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private static void validate(Pot p) {
|
||||
if (p.items.size() > 4
|
||||
|| p.items.stream().anyMatch(i -> i.isEmpty() || i.getCount() != 1)
|
||||
|| p.brewTicks < 0
|
||||
|| p.brewTicks > 1200
|
||||
|| (p.soup.isEmpty()
|
||||
? p.servings != 0 || p.capacity != 0 || p.brewing() || p.items.isEmpty()
|
||||
: p.soup.getCount() != 1
|
||||
|| !Ingredients.isCombined(p.soup)
|
||||
|| p.servings < 1
|
||||
|| p.capacity < p.servings
|
||||
|| p.capacity > 16
|
||||
|| (p.brewing() ? p.items.isEmpty() : !p.items.isEmpty())))
|
||||
throw new IllegalArgumentException("Invalid cauldron contents");
|
||||
private static void validate(Pot pot) {
|
||||
if (pot.items.size() > 4)
|
||||
throw new IllegalArgumentException("Too many cauldron ingredients");
|
||||
for (ItemStack ingredient : pot.items) {
|
||||
if (ingredient.isEmpty() || ingredient.getCount() != 1) {
|
||||
throw new IllegalArgumentException("Cauldron ingredients must be single items");
|
||||
}
|
||||
}
|
||||
if (pot.brewTicks < 0 || pot.brewTicks > 1200) {
|
||||
throw new IllegalArgumentException("Invalid cauldron brewing time");
|
||||
}
|
||||
if (pot.soup.isEmpty()) {
|
||||
if (pot.servings != 0 || pot.capacity != 0 || pot.brewing() || pot.items.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid uncooked cauldron contents");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (pot.soup.getCount() != 1 || !Ingredients.isCombined(pot.soup)) {
|
||||
throw new IllegalArgumentException("Invalid cauldron soup");
|
||||
}
|
||||
if (pot.servings < 1 || pot.capacity < pot.servings || pot.capacity > 16) {
|
||||
throw new IllegalArgumentException("Invalid cauldron servings");
|
||||
}
|
||||
if (pot.brewing()) {
|
||||
if (pot.items.isEmpty())
|
||||
throw new IllegalArgumentException("Brewing requires ingredients");
|
||||
} else if (!pot.items.isEmpty()) {
|
||||
throw new IllegalArgumentException("Finished soup cannot retain ingredients");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean change(Position pos, Pot next) {
|
||||
@@ -433,7 +444,7 @@ public final class SoupPots implements AutoCloseable {
|
||||
water.show(
|
||||
level,
|
||||
pos.pos,
|
||||
new online.astradev.plus.api.ColoredWaterApi.Surface(
|
||||
new ColoredWaterApi.Surface(
|
||||
WATER_OWNER,
|
||||
Ingredients.color(pot.soup),
|
||||
(float) CauldronAnimation.liquidHeight(pot.servings, pot.capacity)));
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package online.astradev.cauldron;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
|
||||
/** Export before AstraPlus's startup pack build; upgrade only known, unmodified defaults. */
|
||||
final class SoupResources {
|
||||
// Bundled flat-colour model in 0.2.0–0.2.3, with normalized newlines and outer whitespace.
|
||||
private static final String FLAT_MODEL_SHA256 =
|
||||
"51b5c2b0561ec815e5ddaff5654ce04fffa0995fc3e5972323f385d58842cd2c";
|
||||
|
||||
private SoupResources() {}
|
||||
|
||||
static void install(Path root) throws IOException {
|
||||
for (String name : List.of("items/combined_soup.json", "models/item/soup_liquid.json")) {
|
||||
String relative = "assets/astradev_soups/" + name;
|
||||
Path target = root.resolve("astraplus/resources").resolve(relative);
|
||||
Files.createDirectories(target.getParent());
|
||||
boolean exists = Files.exists(target, LinkOption.NOFOLLOW_LINKS);
|
||||
if (exists && !(name.equals("models/item/soup_liquid.json") && isFlatDefault(target)))
|
||||
continue;
|
||||
try (var input =
|
||||
SoupResources.class.getResourceAsStream("/astra-resources/" + relative)) {
|
||||
if (input == null) throw new IOException("Missing resource " + relative);
|
||||
if (!exists) Files.copy(input, target);
|
||||
else {
|
||||
Path temp = Files.createTempFile(target.getParent(), "soup-model-", ".tmp");
|
||||
try {
|
||||
Files.copy(input, temp, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.move(
|
||||
temp,
|
||||
target,
|
||||
StandardCopyOption.ATOMIC_MOVE,
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally {
|
||||
Files.deleteIfExists(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFlatDefault(Path path) throws IOException {
|
||||
if (!Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS) || Files.size(path) > 8192)
|
||||
return false;
|
||||
String model = Files.readString(path, UTF_8).replace("\r\n", "\n").trim();
|
||||
try {
|
||||
return HexFormat.of()
|
||||
.formatHex(MessageDigest.getInstance("SHA-256").digest(model.getBytes(UTF_8)))
|
||||
.equals(FLAT_MODEL_SHA256);
|
||||
} catch (NoSuchAlgorithmException impossible) {
|
||||
throw new AssertionError(impossible);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import net.minecraft.world.item.crafting.*;
|
||||
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import online.astradev.cauldron.CauldronHeat;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -21,6 +23,6 @@ public abstract class CampfireHeatMixin {
|
||||
CampfireBlockEntity entity,
|
||||
RecipeManager.CachedCheck<SingleRecipeInput, CampfireCookingRecipe> recipes,
|
||||
CallbackInfo ci) {
|
||||
online.astradev.cauldron.CauldronHeat.tick(level, pos);
|
||||
CauldronHeat.tick(level, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.core.component.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import online.astradev.cauldron.AstraCauldron;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -22,7 +24,7 @@ abstract class SoupStackMixin {
|
||||
if (key == null || !key.identifier().getNamespace().equals("minecraft")) return;
|
||||
switch (key.identifier().getPath()) {
|
||||
case "mushroom_stew", "rabbit_stew", "beetroot_soup", "suspicious_stew" -> {
|
||||
var config = online.astradev.cauldron.AstraCauldron.config();
|
||||
var config = AstraCauldron.config();
|
||||
if (config.normalizeVanillaSoups)
|
||||
components.set(DataComponents.MAX_STACK_SIZE, config.soupStackSize);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ side="SERVER"
|
||||
[[dependencies.astracauldron]]
|
||||
modId="astraplus"
|
||||
type="required"
|
||||
versionRange="[0.9.2,0.10)"
|
||||
versionRange="[0.9.3,0.10)"
|
||||
ordering="AFTER"
|
||||
side="SERVER"
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package online.astradev.cauldron;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.*;
|
||||
|
||||
class SoupResourcesTest {
|
||||
@TempDir Path root;
|
||||
private static final String MODEL = "assets/astradev_soups/models/item/soup_liquid.json";
|
||||
|
||||
@Test
|
||||
void exportsBundledResourcesAndCanRunAgain() throws Exception {
|
||||
SoupResources.install(root);
|
||||
assertArrayEquals(bundled(), Files.readAllBytes(target()));
|
||||
var modified = Files.getLastModifiedTime(target());
|
||||
SoupResources.install(root);
|
||||
assertEquals(modified, Files.getLastModifiedTime(target()));
|
||||
assertTrue(
|
||||
Files.exists(
|
||||
root.resolve(
|
||||
"astraplus/resources/assets/astradev_soups/items/combined_soup.json")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void upgradesFlatDefaultWithEitherLineEnding() throws Exception {
|
||||
try (var input = getClass().getResourceAsStream("/legacy/soup_liquid.json")) {
|
||||
String legacy = new String(input.readAllBytes(), UTF_8).replace("\r\n", "\n");
|
||||
Files.createDirectories(target().getParent());
|
||||
for (String ending : new String[] {"\n", "\r\n"}) {
|
||||
Files.writeString(target(), legacy.replace("\n", ending));
|
||||
SoupResources.install(root);
|
||||
assertArrayEquals(bundled(), Files.readAllBytes(target()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesAdministratorCustomizationOfOldModel() throws Exception {
|
||||
try (var input = getClass().getResourceAsStream("/legacy/soup_liquid.json")) {
|
||||
String custom =
|
||||
new String(input.readAllBytes(), UTF_8)
|
||||
.replace("minecraft:item/bone_meal", "custom:item/soup");
|
||||
Files.createDirectories(target().getParent());
|
||||
Files.writeString(target(), custom);
|
||||
SoupResources.install(root);
|
||||
assertEquals(custom, Files.readString(target()));
|
||||
}
|
||||
}
|
||||
|
||||
private Path target() {
|
||||
return root.resolve("astraplus/resources").resolve(MODEL);
|
||||
}
|
||||
|
||||
private byte[] bundled() throws Exception {
|
||||
try (var input = getClass().getResourceAsStream("/astra-resources/" + MODEL)) {
|
||||
return input.readAllBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user