Use AstraPlus block storage and item delivery APIs
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
# AstraContent 0.2.2
|
# AstraContent 0.2.3
|
||||||
|
|
||||||
Серверный мод для Minecraft 26.2, NeoForge 26.2.0.79 и Java 25.
|
Серверный мод для Minecraft 26.2, NeoForge 26.2.0.79 и Java 25.
|
||||||
**На клиент мод устанавливать не нужно.** Для медного оформления используется обычный
|
**На клиент мод устанавливать не нужно.** Для медного оформления используется обычный
|
||||||
серверный ресурспак AstraPlus. AstraPlus 0.9.x обязателен для сборки ресурсов;
|
серверный ресурспак AstraPlus. AstraPlus 0.9.2+ обязателен для сборки ресурсов;
|
||||||
AstraPacks раздаёт их игрокам, если установлен и настроен.
|
AstraPacks раздаёт их игрокам, если установлен и настроен.
|
||||||
|
|
||||||
## Арбалет и огненный заряд
|
## Арбалет и огненный заряд
|
||||||
@@ -115,7 +115,7 @@ Shift + ПКМ киркой по выбранному торцу снимает
|
|||||||
|
|
||||||
## Установка и разработка
|
## Установка и разработка
|
||||||
|
|
||||||
Рабочий JAR: `C:\Users\ScarPC\Documents\NeoForge Server 26.2\mods\AstraContent-0.2.2.jar`.
|
Рабочий JAR: `C:\Users\ScarPC\Documents\NeoForge Server 26.2\mods\AstraContent-0.2.3.jar`.
|
||||||
После установки требуется перезапуск сервера. При запуске добавляются только отсутствующие
|
После установки требуется перезапуск сервера. При запуске добавляются только отсутствующие
|
||||||
ресурсы в `astraplus/resources/assets/astracontent`; правки администратора не заменяются.
|
ресурсы в `astraplus/resources/assets/astracontent`; правки администратора не заменяются.
|
||||||
При выключенной стартовой сборке ресурспака выполнить `/astraplus build`.
|
При выключенной стартовой сборке ресурспака выполнить `/astraplus build`.
|
||||||
|
|||||||
+2
-1
@@ -3,9 +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.2.2"
|
version = "0.2.3"
|
||||||
repositories { mavenCentral() }
|
repositories { mavenCentral() }
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly(files("../AstraPlus/build/libs/AstraPlus-0.9.2.jar"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.4")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.4")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import online.astradev.content.weapon.Ammunition;
|
|||||||
public final class AstraContent {
|
public final class AstraContent {
|
||||||
public AstraContent(IEventBus bus) {
|
public AstraContent(IEventBus bus) {
|
||||||
Defaults.install(FMLPaths.GAMEDIR.get());
|
Defaults.install(FMLPaths.GAMEDIR.get());
|
||||||
Rails.register(bus);
|
Rails.register();
|
||||||
NeoForge.EVENT_BUS.register(Rails.class);
|
|
||||||
NeoForge.EVENT_BUS.register(Ammunition.class);
|
NeoForge.EVENT_BUS.register(Ammunition.class);
|
||||||
NeoForge.EVENT_BUS.register(online.astradev.content.rail.RailCommands.class);
|
NeoForge.EVENT_BUS.register(online.astradev.content.rail.RailCommands.class);
|
||||||
NeoForge.EVENT_BUS.register(online.astradev.content.train.Trains.class);
|
NeoForge.EVENT_BUS.register(online.astradev.content.train.Trains.class);
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package online.astradev.content.rail;
|
package online.astradev.content.rail;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
|
|
||||||
|
import online.astradev.plus.api.AstraPlusApi;
|
||||||
|
|
||||||
public final class RailCommands {
|
public final class RailCommands {
|
||||||
private RailCommands() {}
|
private RailCommands() {}
|
||||||
|
|
||||||
@@ -13,15 +19,7 @@ public final class RailCommands {
|
|||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
var kind = RailKind.decode(i);
|
var kind = RailKind.decode(i);
|
||||||
give.then(
|
give.then(
|
||||||
Commands.literal(kind.id().getPath())
|
Commands.literal(kind.id().getPath()).executes(context -> give(context, kind)));
|
||||||
.executes(
|
|
||||||
ctx -> {
|
|
||||||
var player = ctx.getSource().getPlayerOrException();
|
|
||||||
var stack = Rails.stack(kind, 64);
|
|
||||||
if (!player.getInventory().add(stack))
|
|
||||||
player.drop(stack, false);
|
|
||||||
return 1;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
event.getDispatcher()
|
event.getDispatcher()
|
||||||
.register(
|
.register(
|
||||||
@@ -29,4 +27,12 @@ public final class RailCommands {
|
|||||||
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
||||||
.then(give));
|
.then(give));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int give(CommandContext<CommandSourceStack> context, RailKind kind)
|
||||||
|
throws CommandSyntaxException {
|
||||||
|
var player = context.getSource().getPlayerOrException();
|
||||||
|
var stack = Rails.stack(kind, 64);
|
||||||
|
AstraPlusApi.give(player, stack);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package online.astradev.content.rail;
|
package online.astradev.content.rail;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import static online.astradev.plus.api.AstraPlusApi.position;
|
||||||
|
import static online.astradev.plus.api.AstraPlusApi.world;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
@@ -10,39 +11,23 @@ import net.minecraft.world.level.block.Blocks;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.neoforged.bus.api.*;
|
import net.neoforged.bus.api.*;
|
||||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.neoforged.neoforge.event.level.ChunkEvent;
|
import net.neoforged.neoforge.event.level.ChunkEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||||
import net.neoforged.neoforge.registries.*;
|
|
||||||
|
import online.astradev.plus.api.content.BlockData;
|
||||||
|
import online.astradev.plus.api.content.ContentRegistry;
|
||||||
|
import online.astradev.plus.api.world.BlockPosition;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/** Native powered rails own placement, shape, redstone, collision and destruction. */
|
/** Native powered rails own placement, shape, redstone, collision and destruction. */
|
||||||
public final class Rails {
|
public final class Rails {
|
||||||
private static final DeferredRegister<AttachmentType<?>> TYPES =
|
private static final BlockData<Integer> DATA =
|
||||||
DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, "astracontent");
|
new ContentRegistry("astracontent")
|
||||||
public static final Supplier<AttachmentType<Map<Long, Integer>>> DATA =
|
.blockData("copper_rails", BlockData.integers("rails", 0, 7));
|
||||||
TYPES.register(
|
|
||||||
"copper_rails",
|
|
||||||
() ->
|
|
||||||
AttachmentType.<Map<Long, Integer>>builder(() -> new HashMap<>())
|
|
||||||
.serialize(
|
|
||||||
Codec.unboundedMap(
|
|
||||||
Codec.STRING.xmap(
|
|
||||||
Long::parseLong,
|
|
||||||
String::valueOf),
|
|
||||||
Codec.intRange(0, 7))
|
|
||||||
.xmap(
|
|
||||||
map ->
|
|
||||||
(Map<Long, Integer>)
|
|
||||||
new HashMap<>(map),
|
|
||||||
map -> map)
|
|
||||||
.fieldOf("rails"),
|
|
||||||
map -> !map.isEmpty())
|
|
||||||
.build());
|
|
||||||
|
|
||||||
private record Position(ServerLevel level, BlockPos pos) {}
|
private record Position(ServerLevel level, BlockPos pos) {}
|
||||||
|
|
||||||
@@ -53,14 +38,14 @@ public final class Rails {
|
|||||||
|
|
||||||
private Rails() {}
|
private Rails() {}
|
||||||
|
|
||||||
public static void register(IEventBus bus) {
|
public static void register() {
|
||||||
TYPES.register(bus);
|
NeoForge.EVENT_BUS.register(Rails.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RailKind find(ServerLevel level, BlockPos pos) {
|
public static RailKind find(ServerLevel level, BlockPos pos) {
|
||||||
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
||||||
if (chunk == null || !chunk.hasData(DATA)) return null;
|
if (chunk == null) return null;
|
||||||
Integer code = chunk.getData(DATA).get(pos.asLong());
|
Integer code = DATA.get(world(level), position(pos)).orElse(null);
|
||||||
return code == null ? null : RailKind.decode(code);
|
return code == null ? null : RailKind.decode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +69,7 @@ public final class Rails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void put(ServerLevel level, BlockPos pos, RailKind kind) {
|
public static void put(ServerLevel level, BlockPos pos, RailKind kind) {
|
||||||
var chunk = level.getChunkAt(pos);
|
DATA.put(world(level), position(pos), kind.code());
|
||||||
chunk.getData(DATA).put(pos.asLong(), kind.code());
|
|
||||||
chunk.markUnsaved();
|
|
||||||
ACTIVE.putIfAbsent(new Position(level, pos.immutable()), null);
|
ACTIVE.putIfAbsent(new Position(level, pos.immutable()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,9 +87,7 @@ public final class Rails {
|
|||||||
|
|
||||||
private static void clear(ServerLevel level, BlockPos pos) {
|
private static void clear(ServerLevel level, BlockPos pos) {
|
||||||
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
||||||
if (chunk != null
|
if (chunk != null) DATA.remove(world(level), position(pos));
|
||||||
&& chunk.hasData(DATA)
|
|
||||||
&& chunk.getData(DATA).remove(pos.asLong()) != null) chunk.markUnsaved();
|
|
||||||
var display = ACTIVE.remove(new Position(level, pos));
|
var display = ACTIVE.remove(new Position(level, pos));
|
||||||
if (display != null) display.discard();
|
if (display != null) display.discard();
|
||||||
}
|
}
|
||||||
@@ -115,24 +96,17 @@ public final class Rails {
|
|||||||
public static void load(ChunkEvent.Load event) {
|
public static void load(ChunkEvent.Load event) {
|
||||||
if (!(event.getLevel() instanceof ServerLevel level)
|
if (!(event.getLevel() instanceof ServerLevel level)
|
||||||
|| !(event.getChunk() instanceof LevelChunk chunk)) return;
|
|| !(event.getChunk() instanceof LevelChunk chunk)) return;
|
||||||
level.getServer()
|
level.getServer().execute(() -> restoreDisplays(level, chunk));
|
||||||
.execute(
|
}
|
||||||
() -> {
|
|
||||||
if (level.getChunkSource()
|
private static void restoreDisplays(ServerLevel level, LevelChunk chunk) {
|
||||||
.getChunkNow(
|
var chunkPos = chunk.getPos();
|
||||||
chunk.getPos().x(), chunk.getPos().z())
|
if (level.getChunkSource().getChunkNow(chunkPos.x(), chunkPos.z()) != chunk) return;
|
||||||
!= chunk
|
var origin = new BlockPosition(chunkPos.x() << 4, level.getMinY(), chunkPos.z() << 4);
|
||||||
|| !chunk.hasData(DATA)) return;
|
for (var saved : DATA.inChunk(world(level), origin).keySet()) {
|
||||||
chunk.getData(DATA)
|
var pos = new BlockPos(saved.x(), saved.y(), saved.z());
|
||||||
.forEach(
|
ACTIVE.putIfAbsent(new Position(level, pos), null);
|
||||||
(packed, code) -> {
|
}
|
||||||
var pos = BlockPos.of(packed);
|
|
||||||
if (pos.getX() >> 4 == chunk.getPos().x()
|
|
||||||
&& pos.getZ() >> 4 == chunk.getPos().z())
|
|
||||||
ACTIVE.putIfAbsent(
|
|
||||||
new Position(level, pos), null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -17,22 +17,20 @@ public final class TrainData extends SavedData {
|
|||||||
Codec.STRING.xmap(UUID::fromString, UUID::toString);
|
Codec.STRING.xmap(UUID::fromString, UUID::toString);
|
||||||
static final Codec<Link> CODEC =
|
static final Codec<Link> CODEC =
|
||||||
RecordCodecBuilder.create(
|
RecordCodecBuilder.create(
|
||||||
i ->
|
instance -> {
|
||||||
i.group(
|
var a = UUID_CODEC.fieldOf("a").forGetter(Link::a);
|
||||||
UUID_CODEC.fieldOf("a").forGetter(Link::a),
|
var endA = Codec.intRange(0, 1).fieldOf("end_a").forGetter(Link::endA);
|
||||||
Codec.intRange(0, 1)
|
var b = UUID_CODEC.fieldOf("b").forGetter(Link::b);
|
||||||
.fieldOf("end_a")
|
var endB = Codec.intRange(0, 1).fieldOf("end_b").forGetter(Link::endB);
|
||||||
.forGetter(Link::endA),
|
var item = Codec.STRING.fieldOf("item").forGetter(Link::item);
|
||||||
UUID_CODEC.fieldOf("b").forGetter(Link::b),
|
var paid = Codec.BOOL.fieldOf("paid").forGetter(Link::paid);
|
||||||
Codec.intRange(0, 1)
|
var length =
|
||||||
.fieldOf("end_b")
|
Codec.doubleRange(1, 4)
|
||||||
.forGetter(Link::endB),
|
.fieldOf("length")
|
||||||
Codec.STRING.fieldOf("item").forGetter(Link::item),
|
.forGetter(Link::length);
|
||||||
Codec.BOOL.fieldOf("paid").forGetter(Link::paid),
|
var fields = instance.group(a, endA, b, endB, item, paid, length);
|
||||||
Codec.doubleRange(1, 4)
|
return fields.apply(instance, Link::new);
|
||||||
.fieldOf("length")
|
});
|
||||||
.forGetter(Link::length))
|
|
||||||
.apply(i, Link::new));
|
|
||||||
|
|
||||||
public boolean touches(UUID id) {
|
public boolean touches(UUID id) {
|
||||||
return a.equals(id) || b.equals(id);
|
return a.equals(id) || b.equals(id);
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ side="SERVER"
|
|||||||
[[dependencies.astracontent]]
|
[[dependencies.astracontent]]
|
||||||
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