Use shared item delivery and simplify command registration
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# AstraCauldron
|
# AstraCauldron
|
||||||
|
|
||||||
Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**.
|
Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**.
|
||||||
Требуется **AstraPlus 0.9.x**.
|
Требуется **AstraPlus 0.9.2+**.
|
||||||
Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks.
|
Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks.
|
||||||
|
|
||||||
## Режимы котла
|
## Режимы котла
|
||||||
|
|||||||
+2
-2
@@ -3,10 +3,10 @@ plugins {
|
|||||||
id("net.neoforged.moddev") version "2.0.146"
|
id("net.neoforged.moddev") version "2.0.146"
|
||||||
}
|
}
|
||||||
group = "online.astradev"
|
group = "online.astradev"
|
||||||
version = "0.3.3"
|
version = "0.3.4"
|
||||||
repositories { mavenCentral() }
|
repositories { mavenCentral() }
|
||||||
val astraPlusApi = providers.gradleProperty("astraPlusApi")
|
val astraPlusApi = providers.gradleProperty("astraPlusApi")
|
||||||
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.1.jar")
|
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.2.jar")
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(files(astraPlusApi))
|
compileOnly(files(astraPlusApi))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package online.astradev.cauldron;
|
package online.astradev.cauldron;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.*;
|
import com.mojang.brigadier.arguments.*;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -156,115 +158,67 @@ public final class AstraCauldron {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void commands(RegisterCommandsEvent event) {
|
private void commands(RegisterCommandsEvent event) {
|
||||||
var command =
|
var command = Commands.literal("cauldron").executes(this::help);
|
||||||
Commands.literal("cauldron")
|
|
||||||
.executes(
|
|
||||||
c -> {
|
|
||||||
c.getSource()
|
|
||||||
.sendSuccess(
|
|
||||||
() ->
|
|
||||||
Component.literal(
|
|
||||||
"Краситель + вода: окрашивание"
|
|
||||||
+ " брони. Зелье + пустой"
|
|
||||||
+ " котёл: хранение и"
|
|
||||||
+ " стрелы с эффектом."
|
|
||||||
+ " Еда/зелья + полный"
|
|
||||||
+ " котёл воды: 4"
|
|
||||||
+ " ингредиента супа,"
|
|
||||||
+ " Shift+ПКМ — варка,"
|
|
||||||
+ " миска — порция."),
|
|
||||||
false);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
command.then(
|
command.then(
|
||||||
Commands.literal("reload")
|
Commands.literal("reload")
|
||||||
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
|
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
|
||||||
.executes(
|
.executes(this::reload));
|
||||||
c -> {
|
var saturation =
|
||||||
try {
|
Commands.argument("saturation", FloatArgumentType.floatArg(0))
|
||||||
requirePots().reload();
|
.executes(this::registerIngredient);
|
||||||
c.getSource()
|
var nutrition =
|
||||||
.sendSuccess(
|
Commands.argument("nutrition", IntegerArgumentType.integer(0)).then(saturation);
|
||||||
() ->
|
var id = Commands.argument("id", StringArgumentType.word()).then(nutrition);
|
||||||
Component.literal(
|
|
||||||
"AstraCauldron: настройки"
|
|
||||||
+ " применены."),
|
|
||||||
true);
|
|
||||||
return 1;
|
|
||||||
} catch (Exception e) {
|
|
||||||
c.getSource()
|
|
||||||
.sendFailure(
|
|
||||||
Component.literal(
|
|
||||||
"Ошибка: "
|
|
||||||
+ e.getMessage()
|
|
||||||
+ ". Прежние настройки"
|
|
||||||
+ " сохранены."));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
command.then(
|
command.then(
|
||||||
Commands.literal("register")
|
Commands.literal("register")
|
||||||
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
|
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
|
||||||
.then(
|
.then(id));
|
||||||
Commands.argument("id", StringArgumentType.word())
|
|
||||||
.then(
|
|
||||||
Commands.argument(
|
|
||||||
"nutrition",
|
|
||||||
IntegerArgumentType.integer(0))
|
|
||||||
.then(
|
|
||||||
Commands.argument(
|
|
||||||
"saturation",
|
|
||||||
FloatArgumentType
|
|
||||||
.floatArg(
|
|
||||||
0))
|
|
||||||
.executes(
|
|
||||||
c -> {
|
|
||||||
try {
|
|
||||||
requirePots()
|
|
||||||
.register(
|
|
||||||
StringArgumentType
|
|
||||||
.getString(
|
|
||||||
c,
|
|
||||||
"id"),
|
|
||||||
c.getSource()
|
|
||||||
.getPlayerOrException(),
|
|
||||||
IntegerArgumentType
|
|
||||||
.getInteger(
|
|
||||||
c,
|
|
||||||
"nutrition"),
|
|
||||||
FloatArgumentType
|
|
||||||
.getFloat(
|
|
||||||
c,
|
|
||||||
"saturation"));
|
|
||||||
c.getSource()
|
|
||||||
.sendSuccess(
|
|
||||||
() ->
|
|
||||||
Component
|
|
||||||
.literal(
|
|
||||||
"Ингредиент"
|
|
||||||
+ " зарегистрирован."),
|
|
||||||
true);
|
|
||||||
return 1;
|
|
||||||
} catch (
|
|
||||||
Exception
|
|
||||||
e) {
|
|
||||||
c.getSource()
|
|
||||||
.sendFailure(
|
|
||||||
Component
|
|
||||||
.literal(
|
|
||||||
"Ошибка"
|
|
||||||
+ " регистрации:"
|
|
||||||
+ " "
|
|
||||||
+ e
|
|
||||||
.getMessage()));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
})))));
|
|
||||||
var root = event.getDispatcher().register(command);
|
var root = event.getDispatcher().register(command);
|
||||||
event.getDispatcher()
|
event.getDispatcher()
|
||||||
.register(Commands.literal("soups").redirect(root).executes(root.getCommand()));
|
.register(Commands.literal("soups").redirect(root).executes(root.getCommand()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int help(CommandContext<CommandSourceStack> context) {
|
||||||
|
var message =
|
||||||
|
Component.literal(
|
||||||
|
"Краситель + вода: окрашивание брони. Зелье + пустой котёл: хранение и"
|
||||||
|
+ " стрелы с эффектом. Еда/зелья + полный котёл воды: 4 ингредиента"
|
||||||
|
+ " супа, Shift+ПКМ — варка, миска — порция.");
|
||||||
|
context.getSource().sendSuccess(() -> message, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int reload(CommandContext<CommandSourceStack> context) {
|
||||||
|
try {
|
||||||
|
requirePots().reload();
|
||||||
|
context.getSource()
|
||||||
|
.sendSuccess(
|
||||||
|
() -> Component.literal("AstraCauldron: настройки применены."), true);
|
||||||
|
return 1;
|
||||||
|
} catch (Exception error) {
|
||||||
|
String message = "Ошибка: " + error.getMessage() + ". Прежние настройки сохранены.";
|
||||||
|
context.getSource().sendFailure(Component.literal(message));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int registerIngredient(CommandContext<CommandSourceStack> context) {
|
||||||
|
try {
|
||||||
|
String id = StringArgumentType.getString(context, "id");
|
||||||
|
var player = context.getSource().getPlayerOrException();
|
||||||
|
int nutrition = IntegerArgumentType.getInteger(context, "nutrition");
|
||||||
|
float saturation = FloatArgumentType.getFloat(context, "saturation");
|
||||||
|
requirePots().register(id, player, nutrition, saturation);
|
||||||
|
context.getSource()
|
||||||
|
.sendSuccess(() -> Component.literal("Ингредиент зарегистрирован."), true);
|
||||||
|
return 1;
|
||||||
|
} catch (Exception error) {
|
||||||
|
context.getSource()
|
||||||
|
.sendFailure(Component.literal("Ошибка регистрации: " + error.getMessage()));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static SoupPots requirePots() {
|
private static SoupPots requirePots() {
|
||||||
if (pots == null) throw new IllegalStateException("AstraCauldron ещё не запущен");
|
if (pots == null) throw new IllegalStateException("AstraCauldron ещё не запущен");
|
||||||
return pots;
|
return pots;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.minecraft.world.level.block.*;
|
|||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
|
|
||||||
import online.astradev.plus.api.*;
|
import online.astradev.plus.api.*;
|
||||||
|
import online.astradev.plus.api.AstraPlusApi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
@@ -408,9 +409,7 @@ public final class LiquidPots implements AutoCloseable {
|
|||||||
|
|
||||||
private static void consumeAndGive(ServerPlayer player, int count, ItemStack result) {
|
private static void consumeAndGive(ServerPlayer player, int count, ItemStack result) {
|
||||||
player.getMainHandItem().consume(count, player);
|
player.getMainHandItem().consume(count, player);
|
||||||
player.getInventory().add(result);
|
AstraPlusApi.give(player, result);
|
||||||
if (!result.isEmpty()) player.drop(result, false);
|
|
||||||
player.containerMenu.broadcastChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sound(ServerLevel level, BlockPos pos) {
|
private static void sound(ServerLevel level, BlockPos pos) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.minecraft.world.level.block.CampfireBlock;
|
|||||||
import net.minecraft.world.level.block.LayeredCauldronBlock;
|
import net.minecraft.world.level.block.LayeredCauldronBlock;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
|
||||||
|
import online.astradev.plus.api.AstraPlusApi;
|
||||||
import online.astradev.plus.api.CauldronRecipeEvent;
|
import online.astradev.plus.api.CauldronRecipeEvent;
|
||||||
|
|
||||||
/** Java and editor recipes use the same matching and transactional liquid consumption. */
|
/** Java and editor recipes use the same matching and transactional liquid consumption. */
|
||||||
@@ -68,10 +69,7 @@ public final class RegisteredRecipes {
|
|||||||
ItemStack held = player.getItemInHand(hand);
|
ItemStack held = player.getItemInHand(hand);
|
||||||
held.consume(request.inputCount(), player);
|
held.consume(request.inputCount(), player);
|
||||||
if (held.isEmpty()) player.setItemInHand(hand, output);
|
if (held.isEmpty()) player.setItemInHand(hand, output);
|
||||||
else {
|
else AstraPlusApi.give(player, output);
|
||||||
player.getInventory().add(output);
|
|
||||||
if (!output.isEmpty()) player.drop(output, false);
|
|
||||||
}
|
|
||||||
level.playSound(
|
level.playSound(
|
||||||
null,
|
null,
|
||||||
pos,
|
pos,
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import net.minecraft.world.level.block.*;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
|
|
||||||
|
import online.astradev.plus.api.AstraPlusApi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -491,9 +493,7 @@ public final class SoupPots implements AutoCloseable {
|
|||||||
|
|
||||||
private static void give(ServerPlayer player, ItemStack item) {
|
private static void give(ServerPlayer player, ItemStack item) {
|
||||||
Ingredients.normalize(item);
|
Ingredients.normalize(item);
|
||||||
player.getInventory().add(item);
|
AstraPlusApi.give(player, item);
|
||||||
if (!item.isEmpty()) player.drop(item, false);
|
|
||||||
player.containerMenu.broadcastChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void say(ServerPlayer player, String text) {
|
private static void say(ServerPlayer player, String text) {
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ side="SERVER"
|
|||||||
[[dependencies.astracauldron]]
|
[[dependencies.astracauldron]]
|
||||||
modId="astraplus"
|
modId="astraplus"
|
||||||
type="required"
|
type="required"
|
||||||
versionRange="[0.9,0.10)"
|
versionRange="[0.9.2,0.10)"
|
||||||
ordering="AFTER"
|
ordering="AFTER"
|
||||||
side="SERVER"
|
side="SERVER"
|
||||||
|
|||||||
Reference in New Issue
Block a user