Declare copper rails through AstraPlus and simplify train state
This commit is contained in:
+197
-11
@@ -1,8 +1,21 @@
|
||||
package online.astradev.content.verification;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.DisconnectionDetails;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
|
||||
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
|
||||
import net.minecraft.network.protocol.common.ServerboundResourcePackPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
@@ -23,6 +36,8 @@ import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
|
||||
import online.astradev.content.rail.*;
|
||||
import online.astradev.content.weapon.*;
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
import online.astradev.plus.effect.EffectDisplay;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
@@ -56,6 +71,18 @@ public final class ContentVerification {
|
||||
== Boolean.getBoolean("astracontent.expectedExperimental"),
|
||||
"requested movement engine enabled");
|
||||
if (Files.exists(Path.of("first-pass.txt"))) {
|
||||
var migrated = new BlockPos(10, 100, 90);
|
||||
require(
|
||||
AstraPlusApi.world(level)
|
||||
.block(AstraPlusApi.position(migrated))
|
||||
.equals("astracontent:waxed_weathered_copper_rail"),
|
||||
"Previous rail storage migrates to the shared registry on chunk load");
|
||||
require(
|
||||
previousRailData()
|
||||
.get(AstraPlusApi.world(level), AstraPlusApi.position(migrated))
|
||||
.isEmpty(),
|
||||
"Migrated rail no longer has a second identity");
|
||||
railDisplay(level);
|
||||
for (int age = 0; age < 4; age++)
|
||||
require(
|
||||
Rails.find(level, new BlockPos(2, 100, age * 4)).age() == age,
|
||||
@@ -75,11 +102,14 @@ public final class ContentVerification {
|
||||
return;
|
||||
}
|
||||
setup(level);
|
||||
bundledResources();
|
||||
packResponses(level);
|
||||
ammunition(level);
|
||||
}
|
||||
if (ticks == 129)
|
||||
for (int age = 0; age < 4; age++) previousX[age] = carts.get(age).getX();
|
||||
if (ticks == 130) {
|
||||
railDisplay(level);
|
||||
for (int age = 0; age < 4; age++) {
|
||||
var cart = carts.get(age);
|
||||
double actual = cart.getX() - previousX[age];
|
||||
@@ -95,6 +125,10 @@ public final class ContentVerification {
|
||||
}
|
||||
TrackVerification.run(level);
|
||||
TrainVerification.run(level);
|
||||
var legacy = new BlockPos(10, 100, 90);
|
||||
level.setBlockAndUpdate(legacy.below(), Blocks.STONE.defaultBlockState());
|
||||
level.setBlockAndUpdate(legacy, Blocks.POWERED_RAIL.defaultBlockState());
|
||||
previousRailData().put(AstraPlusApi.world(level), AstraPlusApi.position(legacy), 6);
|
||||
var saved = new Minecart(EntityTypes.MINECART, level);
|
||||
saved.setPos(2.5, 100.0625, .5);
|
||||
saved.setDeltaMovement(.1, 0, 0);
|
||||
@@ -129,6 +163,137 @@ public final class ContentVerification {
|
||||
}
|
||||
}
|
||||
|
||||
private static void packResponses(ServerLevel level) throws Exception {
|
||||
Class<?> runtimeType = Class.forName("online.astradev.packs.PackRuntime");
|
||||
Object runtime = runtimeType.getField("INSTANCE").get(null);
|
||||
Object config = runtimeType.getMethod("config").invoke(runtime);
|
||||
var enabled = config.getClass().getField("enabled");
|
||||
boolean previous = enabled.getBoolean(config);
|
||||
var readyField = EffectDisplay.class.getDeclaredField("READY");
|
||||
readyField.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
var ready = (Set<UUID>) readyField.get(null);
|
||||
var profile = new GameProfile(UUID.randomUUID(), "PackResponseTest");
|
||||
var connection = new Connection(PacketFlow.SERVERBOUND);
|
||||
var cookie = CommonListenerCookie.createInitial(profile, false);
|
||||
var configuration =
|
||||
new ServerConfigurationPacketListenerImpl(level.getServer(), connection, cookie);
|
||||
var gamePlayer = FakePlayerFactory.getMinecraft(level);
|
||||
var previousConnection = gamePlayer.connection;
|
||||
var gameConnection = new Connection(PacketFlow.SERVERBOUND);
|
||||
var gameCookie = CommonListenerCookie.createInitial(gamePlayer.getGameProfile(), false);
|
||||
var game =
|
||||
new ServerGamePacketListenerImpl(
|
||||
level.getServer(), gameConnection, gamePlayer, gameCookie);
|
||||
try {
|
||||
enabled.setBoolean(config, true);
|
||||
for (ServerCommonPacketListenerImpl listener : List.of(configuration, game)) {
|
||||
UUID player = listener.getOwner().id();
|
||||
ready.remove(player);
|
||||
UUID request = UUID.randomUUID();
|
||||
var push =
|
||||
new ClientboundResourcePackPushPacket(
|
||||
request,
|
||||
"http://localhost/test.zip",
|
||||
"0".repeat(40),
|
||||
false,
|
||||
Optional.empty());
|
||||
listener.send(push);
|
||||
listener.handleResourcePackResponse(
|
||||
new ServerboundResourcePackPacket(
|
||||
UUID.randomUUID(),
|
||||
ServerboundResourcePackPacket.Action.SUCCESSFULLY_LOADED));
|
||||
require(!ready.contains(player), "Unrelated pack response ignored");
|
||||
var response =
|
||||
new ServerboundResourcePackPacket(
|
||||
request, ServerboundResourcePackPacket.Action.SUCCESSFULLY_LOADED);
|
||||
listener.handleResourcePackResponse(response);
|
||||
require(
|
||||
ready.contains(player),
|
||||
"AstraPacks response reaches effect renderer: "
|
||||
+ listener.getClass().getSimpleName());
|
||||
listener.send(new ClientboundResourcePackPopPacket(Optional.of(request)));
|
||||
require(
|
||||
!ready.contains(player),
|
||||
"Removing resource pack disables effect rendering");
|
||||
listener.handleResourcePackResponse(response);
|
||||
require(
|
||||
!ready.contains(player),
|
||||
"Removed pack cannot be reactivated by a late reply");
|
||||
}
|
||||
UUID disconnectRequest = UUID.randomUUID();
|
||||
configuration.send(
|
||||
new ClientboundResourcePackPushPacket(
|
||||
disconnectRequest,
|
||||
"http://localhost/test.zip",
|
||||
"0".repeat(40),
|
||||
false,
|
||||
Optional.empty()));
|
||||
var disconnectReply =
|
||||
new ServerboundResourcePackPacket(
|
||||
disconnectRequest,
|
||||
ServerboundResourcePackPacket.Action.SUCCESSFULLY_LOADED);
|
||||
configuration.handleResourcePackResponse(disconnectReply);
|
||||
require(ready.contains(profile.id()), "Configuration ready before disconnect");
|
||||
configuration.onDisconnect(
|
||||
new DisconnectionDetails(Component.literal("Test complete")));
|
||||
configuration.handleResourcePackResponse(disconnectReply);
|
||||
require(
|
||||
!ready.contains(profile.id()),
|
||||
"Disconnected configuration leaves no ready state");
|
||||
System.out.println(
|
||||
"PASS pack responses: configuration, gameplay, stale replies and removal");
|
||||
} finally {
|
||||
gamePlayer.connection = previousConnection;
|
||||
enabled.setBoolean(config, previous);
|
||||
ready.remove(profile.id());
|
||||
ready.remove(game.getOwner().id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void bundledResources() throws Exception {
|
||||
try (var zip = new java.util.zip.ZipFile("astraplus/output/AstraPlus.zip")) {
|
||||
String model = "assets/astracontent/models/rail_display/0/ascending_north.json";
|
||||
var entry = zip.getEntry(model);
|
||||
require(entry != null, "Standard mod assets are included without registration");
|
||||
try (var actual = zip.getInputStream(entry);
|
||||
var source =
|
||||
online.astradev.content.AstraContent.class.getResourceAsStream(
|
||||
"/" + model)) {
|
||||
require(
|
||||
Arrays.equals(actual.readAllBytes(), source.readAllBytes()),
|
||||
"Bundled model is copied intact from the mod JAR");
|
||||
}
|
||||
require(
|
||||
zip.getEntry("assets/astracontent/lang/ru_ru.json") != null,
|
||||
"Bundled translations included");
|
||||
require(zip.getEntry("assets.index") == null, "No resource index required");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static online.astradev.plus.api.content.BlockData<Integer> previousRailData()
|
||||
throws Exception {
|
||||
var field = Rails.class.getDeclaredField("PREVIOUS_VARIANTS");
|
||||
field.setAccessible(true);
|
||||
return (online.astradev.plus.api.content.BlockData<Integer>) field.get(null);
|
||||
}
|
||||
|
||||
private static void railDisplay(ServerLevel level) {
|
||||
var pos = new BlockPos(2, 100, 0);
|
||||
var displays = level.getEntitiesOfClass(Display.ItemDisplay.class, new AABB(pos));
|
||||
require(displays.size() == 1, "API restores exactly one display per copper rail");
|
||||
var display = displays.getFirst();
|
||||
require(
|
||||
display.entityTags().contains("astraplus:block_part"),
|
||||
"Rail display belongs to the API");
|
||||
require(!display.shouldBeSaved(), "Visual does not duplicate saved block identity");
|
||||
var model = display.getSlot(0).get().get(DataComponents.ITEM_MODEL);
|
||||
require(
|
||||
model.toString().equals("astracontent:rail_display/0/east_west_on"),
|
||||
"API selects the powered model for the native rail shape");
|
||||
}
|
||||
|
||||
private void setup(ServerLevel level) {
|
||||
var ingredients =
|
||||
List.of(
|
||||
@@ -154,7 +319,7 @@ public final class ContentVerification {
|
||||
"native crafting recipe makes six copper rails");
|
||||
for (int code = 0; code < 8; code++)
|
||||
require(
|
||||
RailItems.find(Rails.stack(RailKind.decode(code), 1)).code() == code,
|
||||
RailItems.find(RailItems.create(RailKind.decode(code), 1)).code() == code,
|
||||
"item variant " + code);
|
||||
for (int age = 0; age < 4; age++) {
|
||||
int z = age * 4;
|
||||
@@ -176,7 +341,7 @@ public final class ContentVerification {
|
||||
}
|
||||
var pos = new BlockPos(5, 100, 24);
|
||||
level.setBlockAndUpdate(pos.below(), Blocks.STONE.defaultBlockState());
|
||||
var item = Rails.stack(new RailKind(2, false), 2);
|
||||
var item = RailItems.create(new RailKind(2, false), 2);
|
||||
var context =
|
||||
new UseOnContext(
|
||||
level,
|
||||
@@ -188,25 +353,46 @@ public final class ContentVerification {
|
||||
require(item.getItem().useOn(context).consumesAction(), "native BlockItem placement");
|
||||
require(level.getBlockState(pos).is(Blocks.POWERED_RAIL), "real vanilla carrier");
|
||||
require(Rails.find(level, pos).age() == 2, "placement preserves variant");
|
||||
var world = AstraPlusApi.world(level);
|
||||
var position = AstraPlusApi.position(pos);
|
||||
require(
|
||||
world.block(position).equals("astracontent:weathered_copper_rail"),
|
||||
"Copper rail belongs to the shared block registry");
|
||||
var placedState = level.getBlockState(pos);
|
||||
require(
|
||||
world.replaceBlock(position, "astracontent:exposed_copper_rail"),
|
||||
"Replace a registered block variant");
|
||||
require(
|
||||
level.getBlockState(pos) == placedState,
|
||||
"Variant replacement retains native shape and power");
|
||||
require(
|
||||
world.blocksInChunk(position)
|
||||
.get(position)
|
||||
.equals("astracontent:exposed_copper_rail"),
|
||||
"Chunk exposes the updated registered identity");
|
||||
Rails.put(level, pos, new RailKind(2, false));
|
||||
require(item.getCount() == 1, "placement consumes exactly one");
|
||||
var player = FakePlayerFactory.getMinecraft(level);
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.HONEYCOMB, 2));
|
||||
var hit = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
|
||||
Rails.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickBlock(
|
||||
player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
new Rails()
|
||||
.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
|
||||
.RightClickBlock(player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
require(Rails.find(level, pos).waxed(), "waxing native rail");
|
||||
require(player.getMainHandItem().getCount() == 1, "wax consumes one honeycomb");
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.IRON_AXE));
|
||||
Rails.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickBlock(
|
||||
player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
new Rails()
|
||||
.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
|
||||
.RightClickBlock(player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
require(
|
||||
!Rails.find(level, pos).waxed() && Rails.find(level, pos).age() == 2,
|
||||
"axe removes wax first");
|
||||
Rails.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickBlock(
|
||||
player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
new Rails()
|
||||
.use(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
|
||||
.RightClickBlock(player, InteractionHand.MAIN_HAND, pos, hit));
|
||||
require(Rails.find(level, pos).age() == 1, "axe removes one oxidation stage");
|
||||
Rails.put(level, pos, new RailKind(2, false));
|
||||
var drops = Block.getDrops(level.getBlockState(pos), level, pos, null);
|
||||
|
||||
+8
-5
@@ -17,6 +17,7 @@ import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import online.astradev.content.train.*;
|
||||
import online.astradev.content.transport.SlimeBounce;
|
||||
import online.astradev.plus.api.BlockLine;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
@@ -108,6 +109,7 @@ final class TrainVerification {
|
||||
require(data.links().isEmpty(), "side cannot attach");
|
||||
click(level, a, Items.IRON_CHAIN, new Vec3(.49, .2, 0));
|
||||
require(data.links().size() == 1, "front auto couples");
|
||||
require(Trains.connected(a, b), "connected component after coupling");
|
||||
require(player.getMainHandItem().getCount() == 7, "one chain consumed");
|
||||
click(level, a, Items.IRON_CHAIN, new Vec3(.49, .2, 0));
|
||||
require(
|
||||
@@ -116,13 +118,14 @@ final class TrainVerification {
|
||||
Trains.show(level);
|
||||
Trains.show(level);
|
||||
require(
|
||||
level.getEntitiesOfClass(ChainDisplay.class, a.getBoundingBox().inflate(5)).size()
|
||||
level.getEntitiesOfClass(BlockLine.class, a.getBoundingBox().inflate(5)).size()
|
||||
== 1,
|
||||
"one visible vanilla chain");
|
||||
int drops =
|
||||
level.getEntitiesOfClass(ItemEntity.class, a.getBoundingBox().inflate(5)).size();
|
||||
click(level, b, Items.IRON_PICKAXE, new Vec3(-.49, .2, 0));
|
||||
require(data.links().isEmpty(), "detach from opposite end");
|
||||
require(!Trains.connected(a, b), "component cache invalidated after uncoupling");
|
||||
require(
|
||||
level.getEntitiesOfClass(ItemEntity.class, a.getBoundingBox().inflate(5)).size()
|
||||
== drops + 1,
|
||||
@@ -176,7 +179,7 @@ final class TrainVerification {
|
||||
var carts = new ArrayList<Minecart>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
var c = cart(level, path.get(1 + i * 2).pos(), direction(turn, .5));
|
||||
((CartFrame) c).astracontent$front(direction(turn, 1));
|
||||
CouplingGeometry.restoreFront(c, direction(turn, 1));
|
||||
carts.add(c);
|
||||
}
|
||||
link(level, carts.get(0), carts.get(1));
|
||||
@@ -253,7 +256,7 @@ final class TrainVerification {
|
||||
.subtract(Vec3.atCenterOf(positions.get(i)))
|
||||
.normalize();
|
||||
var c = cart(level, positions.get(i), dir.scale(.3));
|
||||
((CartFrame) c).astracontent$front(dir);
|
||||
CouplingGeometry.restoreFront(c, dir);
|
||||
carts.add(c);
|
||||
}
|
||||
for (int i = 0; i < carts.size() - 1; i++) link(level, carts.get(i), carts.get(i + 1));
|
||||
@@ -333,7 +336,7 @@ final class TrainVerification {
|
||||
var direction = direction(turn, 1);
|
||||
for (int x = 4; x <= 8; x += 2) {
|
||||
var c = cart(level, at(x, 0, 0, turn), direction);
|
||||
((CartFrame) c).astracontent$front(direction);
|
||||
CouplingGeometry.restoreFront(c, direction);
|
||||
carts.add(c);
|
||||
}
|
||||
link(level, carts.get(0), carts.get(1));
|
||||
@@ -385,7 +388,7 @@ final class TrainVerification {
|
||||
require(a != null && b != null && Trains.connected(a, b), "saved train restored");
|
||||
Trains.show(level);
|
||||
require(
|
||||
level.getEntitiesOfClass(ChainDisplay.class, a.getBoundingBox().inflate(5)).size()
|
||||
level.getEntitiesOfClass(BlockLine.class, a.getBoundingBox().inflate(5)).size()
|
||||
== 1,
|
||||
"one chain recreated after restart");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user