Move transport and ammunition to authored AstraPlus capabilities
This commit is contained in:
+25
-14
@@ -35,7 +35,8 @@ import net.neoforged.neoforge.common.util.FakePlayerFactory;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
|
||||
import online.astradev.content.rail.*;
|
||||
import online.astradev.content.weapon.*;
|
||||
import online.astradev.plus.capability.transport.rail.CartSpeed;
|
||||
import online.astradev.plus.capability.transport.rail.RailSpeed;
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
import online.astradev.plus.effect.EffectDisplay;
|
||||
|
||||
@@ -66,11 +67,13 @@ public final class ContentVerification {
|
||||
.performPrefixedCommand(
|
||||
server.createCommandSourceStack(), "forceload add 0 0 159 95");
|
||||
if (ticks == 20) {
|
||||
StarterBundleVerification.run();
|
||||
require(
|
||||
AbstractMinecart.useExperimentalMovement(level)
|
||||
== Boolean.getBoolean("astracontent.expectedExperimental"),
|
||||
"requested movement engine enabled");
|
||||
if (Files.exists(Path.of("first-pass.txt"))) {
|
||||
DeclarativeRailVerification.restart(level);
|
||||
var migrated = new BlockPos(10, 100, 90);
|
||||
require(
|
||||
AstraPlusApi.world(level)
|
||||
@@ -92,8 +95,11 @@ public final class ContentVerification {
|
||||
UUID.fromString(Files.readString(Path.of("saved-cart.txt"))));
|
||||
require(saved instanceof AbstractMinecart, "saved minecart restored");
|
||||
require(
|
||||
Math.abs(((CartSpeed) saved).astracontent$limit(level) - 1) < .001,
|
||||
Math.abs(((CartSpeed) saved).astraplus$transportLimit(level) - 1) < .001,
|
||||
"personal speed survives restart on ordinary rails");
|
||||
require(
|
||||
online.astradev.plus.capability.transport.train.CouplingGeometry.front((AbstractMinecart) saved).x < -.99,
|
||||
"physical front survives restart independently of saved yaw");
|
||||
TrainVerification.restart(level);
|
||||
finish(
|
||||
server,
|
||||
@@ -124,6 +130,7 @@ public final class ContentVerification {
|
||||
+ expected);
|
||||
}
|
||||
TrackVerification.run(level);
|
||||
DeclarativeRailVerification.run(level);
|
||||
TrainVerification.run(level);
|
||||
var legacy = new BlockPos(10, 100, 90);
|
||||
level.setBlockAndUpdate(legacy.below(), Blocks.STONE.defaultBlockState());
|
||||
@@ -144,6 +151,10 @@ public final class ContentVerification {
|
||||
}
|
||||
saved.setPos(30.5, 100.0625, 40.5);
|
||||
saved.setDeltaMovement(Vec3.ZERO);
|
||||
saved.setYRot(0);
|
||||
online.astradev.plus.capability.transport.train.CouplingGeometry.restoreFront(saved, new Vec3(-1, 0, 0));
|
||||
require(Math.abs(((CartSpeed) saved).astraplus$transportLimit(level) - 1) < .001,
|
||||
"personal speed exists before shutdown on ordinary rails");
|
||||
level.addFreshEntity(saved);
|
||||
Files.writeString(Path.of("saved-cart.txt"), saved.getUUID().toString());
|
||||
Files.writeString(Path.of("first-pass.txt"), "PASS");
|
||||
@@ -258,8 +269,8 @@ public final class ContentVerification {
|
||||
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)) {
|
||||
online.astradev.plus.AstraPlus.class.getResourceAsStream(
|
||||
"/astra-starter/files/astraplus/resources/" + model)) {
|
||||
require(
|
||||
Arrays.equals(actual.readAllBytes(), source.readAllBytes()),
|
||||
"Bundled model is copied intact from the mod JAR");
|
||||
@@ -274,9 +285,12 @@ public final class ContentVerification {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static online.astradev.plus.api.content.BlockData<Integer> previousRailData()
|
||||
throws Exception {
|
||||
var field = Rails.class.getDeclaredField("PREVIOUS_VARIANTS");
|
||||
var field = online.astradev.plus.capability.transport.LegacyBlockMappings.class.getDeclaredField("mappings");
|
||||
field.setAccessible(true);
|
||||
return (online.astradev.plus.api.content.BlockData<Integer>) field.get(null);
|
||||
var mapping = ((java.util.List<?>) field.get(null)).getFirst();
|
||||
var data = mapping.getClass().getDeclaredField("data");
|
||||
data.setAccessible(true);
|
||||
return (online.astradev.plus.api.content.BlockData<Integer>) data.get(mapping);
|
||||
}
|
||||
|
||||
private static void railDisplay(ServerLevel level) {
|
||||
@@ -375,22 +389,19 @@ public final class ContentVerification {
|
||||
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);
|
||||
new Rails()
|
||||
.use(
|
||||
NeoForge.EVENT_BUS.post(
|
||||
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));
|
||||
new Rails()
|
||||
.use(
|
||||
NeoForge.EVENT_BUS.post(
|
||||
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");
|
||||
new Rails()
|
||||
.use(
|
||||
NeoForge.EVENT_BUS.post(
|
||||
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");
|
||||
@@ -531,11 +542,11 @@ public final class ContentVerification {
|
||||
require(player.getOffhandItem().getCount() == 1, "multishot consumes one ammo");
|
||||
player.stopUsingItem();
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.FIRE_CHARGE, 2));
|
||||
Ammunition.fireCharge(
|
||||
NeoForge.EVENT_BUS.post(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickItem(
|
||||
player, InteractionHand.MAIN_HAND));
|
||||
require(player.getMainHandItem().getCount() == 1, "right click fire charge consumes one");
|
||||
Ammunition.fireCharge(
|
||||
NeoForge.EVENT_BUS.post(
|
||||
new net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickItem(
|
||||
player, InteractionHand.MAIN_HAND));
|
||||
require(
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package online.astradev.content.verification;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityTypes;
|
||||
import net.minecraft.world.entity.vehicle.minecart.Minecart;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.PoweredRailBlock;
|
||||
import net.minecraft.world.level.block.state.properties.RailShape;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
import online.astradev.plus.api.ContentDefinition;
|
||||
import online.astradev.plus.api.RailBehavior;
|
||||
import online.astradev.plus.api.snapshot.SnapshotSource;
|
||||
import online.astradev.plus.api.world.Game;
|
||||
|
||||
/** Actual native movement through a newly authored FILE rail, persisted across a server restart. */
|
||||
final class DeclarativeRailVerification {
|
||||
private static final Identifier ID = Identifier.parse("astracontent:studio_rail_smoke");
|
||||
private static final BlockPos START = new BlockPos(116, 100, 86);
|
||||
|
||||
static void run(ServerLevel level) throws Exception {
|
||||
var api = AstraPlusApi.current().orElseThrow();
|
||||
var original = api.find(Identifier.parse("astracontent:waxed_copper_rail")).orElseThrow();
|
||||
require(original.revision().matches("[a-f0-9]{64}"), "Copper rails are editable FILE documents");
|
||||
var definition = original.document();
|
||||
definition.addProperty("id", ID.toString());
|
||||
definition.addProperty("name", "Created by authoring smoke");
|
||||
var created = api.save(ID, AstraPlusApi.NEW_REVISION, definition);
|
||||
require(Game.snapshot().documents().stream().anyMatch(document -> document.id().equals(ID.toString())
|
||||
&& document.source() == SnapshotSource.FILE), "New rail shares the editor FILE snapshot");
|
||||
for (int x = 110; x <= 145; x++) {
|
||||
var pos = new BlockPos(x, 100, 86);
|
||||
level.setBlock(pos.below(), Blocks.REDSTONE_BLOCK.defaultBlockState(), 2);
|
||||
level.setBlock(pos, Blocks.POWERED_RAIL.defaultBlockState()
|
||||
.setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST).setValue(PoweredRailBlock.POWERED, true), 2);
|
||||
require(AstraPlusApi.world(level).replaceBlock(AstraPlusApi.position(pos), ID.toString()), "Place authored rail");
|
||||
}
|
||||
var saved = save(api, created, 20, 0);
|
||||
double unboosted = step(level, .1).speed();
|
||||
saved = save(api, saved, 20, 80);
|
||||
double accelerated = step(level, .1).speed();
|
||||
require(accelerated - unboosted > .15, "Saved acceleration changes actual native cart velocity: " + unboosted + " -> " + accelerated);
|
||||
saved = save(api, saved, 8, 24);
|
||||
double slow = step(level, .7).distance();
|
||||
saved = save(api, saved, 20, 24);
|
||||
double fast = step(level, .7).distance();
|
||||
require(slow <= .405 && fast - slow > .15, "Saved maxSpeed changes actual cart travel: " + slow + " -> " + fast);
|
||||
save(api, saved, 12, 80);
|
||||
require(Math.abs(RailBehavior.targetSpeed(level, START) - 12) < .001, "New parameters publish to an existing placed identity");
|
||||
System.out.println("PASS declarative rail: create FILE, save acceleration 0->80, real movement, maxSpeed 8->20, persisted 12/80");
|
||||
}
|
||||
|
||||
static void restart(ServerLevel level) {
|
||||
var definition = AstraPlusApi.current().orElseThrow().find(ID).orElseThrow();
|
||||
var rail = definition.document().getAsJsonObject("behaviors").getAsJsonObject("rail");
|
||||
require(rail.get("maxSpeed").getAsDouble() == 12 && rail.get("acceleration").getAsDouble() == 80,
|
||||
"Restart preserves edited parameters without bundled defaults overwriting them");
|
||||
require(AstraPlusApi.world(level).block(AstraPlusApi.position(START)).equals(ID.toString()), "Authored rail identity survives restart");
|
||||
require(Math.abs(RailBehavior.targetSpeed(level, START) - 12) < .001, "Loaded runtime reads persisted parameters");
|
||||
}
|
||||
|
||||
private static ContentDefinition save(AstraPlusApi api, ContentDefinition before, double maxSpeed, double acceleration) throws Exception {
|
||||
JsonObject document = before.document();
|
||||
var rail = document.getAsJsonObject("behaviors").getAsJsonObject("rail");
|
||||
rail.addProperty("maxSpeed", maxSpeed);
|
||||
rail.addProperty("acceleration", acceleration);
|
||||
return api.save(ID, before.revision(), document);
|
||||
}
|
||||
|
||||
private record Step(double speed, double distance) {}
|
||||
|
||||
private static Step step(ServerLevel level, double speed) {
|
||||
var cart = new Minecart(EntityTypes.MINECART, level);
|
||||
cart.setPos(START.getX() + .5, START.getY() + .0625, START.getZ() + .5);
|
||||
cart.setDeltaMovement(new Vec3(speed, 0, 0));
|
||||
double before = cart.getX();
|
||||
cart.tick();
|
||||
var result = new Step(cart.getDeltaMovement().horizontalDistance(), cart.getX() - before);
|
||||
cart.discard();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void require(boolean condition, String message) {
|
||||
if (!condition) throw new AssertionError(message);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package online.astradev.content.verification;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
import online.astradev.plus.AstraPlus;
|
||||
import online.astradev.plus.api.editor.EditorDefinitions;
|
||||
import online.astradev.plus.api.snapshot.SnapshotKind;
|
||||
import online.astradev.plus.api.snapshot.SnapshotSource;
|
||||
import online.astradev.plus.api.world.Game;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** Runs before gameplay on a fresh distribution; no concrete content mod may be loaded. */
|
||||
final class StarterBundleVerification {
|
||||
static void run() throws Exception {
|
||||
for (String forbidden : new String[]{"astracontent", "astracauldron", "astraspears"})
|
||||
require(!ModList.get().isLoaded(forbidden), "Concrete mod is not required: " + forbidden);
|
||||
require(ModList.get().isLoaded("astraplus") && ModList.get().isLoaded("astrapacks"), "Two distribution mods loaded");
|
||||
var kindMap = Map.of("items", SnapshotKind.ITEM, "blocks", SnapshotKind.BLOCK,
|
||||
"mobs", SnapshotKind.MOB, "skills", SnapshotKind.SKILL, "recipes", SnapshotKind.RECIPE,
|
||||
"enchantments", SnapshotKind.ENCHANTMENT);
|
||||
var documents = Game.snapshot().documents().stream().collect(Collectors.toMap(
|
||||
document -> document.kind() + ":" + document.id(), document -> document));
|
||||
int installed = 0, editable = 0, modelFiles = 0;
|
||||
try (var source = AstraPlus.class.getResourceAsStream("/astra-starter/index.json")) {
|
||||
require(source != null, "Distribution embeds a starter manifest");
|
||||
var manifest = JsonParser.parseString(new String(source.readAllBytes(), StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
for (var entry : manifest.getAsJsonArray("files")) {
|
||||
String target = entry.getAsString();
|
||||
require(Files.isRegularFile(FMLPaths.GAMEDIR.get().resolve(target)), "Bundle target installed: " + target);
|
||||
if (target.startsWith("astraplus/models/") && target.endsWith(".bbmodel")) modelFiles++;
|
||||
if (!target.startsWith("astraplus/contents/")) continue;
|
||||
installed++;
|
||||
String[] pieces = target.split("/", 5);
|
||||
var kind = kindMap.get(pieces[3]);
|
||||
require(kind != null, "Every installed content declaration has an editable runtime: " + target);
|
||||
String id = pieces[2] + ":" + pieces[4].substring(0, pieces[4].length() - 5);
|
||||
var document = documents.get(kind + ":" + id);
|
||||
require(document != null, "Authored declaration is visible: " + kind + " " + id);
|
||||
require(document.source() == SnapshotSource.FILE && !document.readOnly(), "Authored declaration is editable FILE: " + id);
|
||||
editable++;
|
||||
}
|
||||
var expectedProviders = new HashSet<String>();
|
||||
for (var value : manifest.getAsJsonArray("capabilities")) {
|
||||
var policy = value.getAsJsonObject();
|
||||
String id = policy.get("id").getAsString();
|
||||
expectedProviders.add(id);
|
||||
require(Files.isRegularFile(FMLPaths.GAMEDIR.get().resolve(policy.get("storage").getAsString())), "Native policy FILE installed: " + id);
|
||||
var document = documents.get(SnapshotKind.MECHANIC + ":" + id);
|
||||
require(document != null && document.source() == SnapshotSource.FILE && !document.readOnly(), "Live FILE policy is editable: " + id);
|
||||
}
|
||||
require(expectedProviders.size() == 5, "Five declared capability policies");
|
||||
require(expectedProviders.contains("astraplus:villager_appearance"), "Native villager appearance is editable policy data");
|
||||
require(EditorDefinitions.all().stream().map(value -> value.id()).collect(Collectors.toSet()).equals(expectedProviders), "Only the declared live providers are installed");
|
||||
}
|
||||
require(installed == 288 && editable == installed, "Exact authored editable content file count: " + installed);
|
||||
require(modelFiles == 141 && AstraPlus.models().catalog().ids().size() == 141, "All 141 models load without content JARs");
|
||||
System.out.println("PASS bare distribution: contentFiles=" + installed + " editableCatalog=" + editable
|
||||
+ " models=" + modelFiles + " mechanics=5; concreteRuntimeMods=0");
|
||||
}
|
||||
|
||||
private static void require(boolean condition, String message) { if (!condition) throw new AssertionError(message); }
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.level.block.state.properties.RailShape;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.rail.*;
|
||||
import online.astradev.plus.capability.transport.rail.RailSpeed;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+6
-6
@@ -15,8 +15,8 @@ import net.minecraft.world.phys.*;
|
||||
import net.neoforged.neoforge.common.util.FakePlayerFactory;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import online.astradev.content.train.*;
|
||||
import online.astradev.content.transport.SlimeBounce;
|
||||
import online.astradev.plus.capability.transport.train.*;
|
||||
import online.astradev.plus.capability.transport.collision.SurfaceBounce;
|
||||
import online.astradev.plus.api.BlockLine;
|
||||
|
||||
import java.nio.file.*;
|
||||
@@ -73,7 +73,7 @@ final class TrainVerification {
|
||||
for (var cart : carts) {
|
||||
cart.setOldPosAndRot();
|
||||
cart.tick();
|
||||
SlimeBounce.flush(cart);
|
||||
SurfaceBounce.flush(cart);
|
||||
}
|
||||
Trains.show(level);
|
||||
}
|
||||
@@ -297,7 +297,7 @@ final class TrainVerification {
|
||||
for (int t = 0; t < 15; t++) {
|
||||
cart.setOldPosAndRot();
|
||||
cart.tick();
|
||||
SlimeBounce.flush(cart);
|
||||
SurfaceBounce.flush(cart);
|
||||
double v = cart.getDeltaMovement().dot(direction(turn, 1));
|
||||
if (v < -.1) {
|
||||
reflected = true;
|
||||
@@ -321,7 +321,7 @@ final class TrainVerification {
|
||||
level.addFreshEntity(boat);
|
||||
boat.setDeltaMovement(dir);
|
||||
boat.move(MoverType.SELF, dir);
|
||||
SlimeBounce.flush(boat);
|
||||
SurfaceBounce.flush(boat);
|
||||
require(boat.getDeltaMovement().dot(dir) < -.99, "boat full speed bounce " + turn);
|
||||
boat.discard();
|
||||
}
|
||||
@@ -362,7 +362,7 @@ final class TrainVerification {
|
||||
level.setBlock(at(4, 0, 0, 0), Blocks.SLIME_BLOCK.defaultBlockState(), 2);
|
||||
var cart = cart(level, at(3, 0, 0, 0), new Vec3(1, 0, .2));
|
||||
cart.move(MoverType.SELF, cart.getDeltaMovement());
|
||||
SlimeBounce.flush(cart);
|
||||
SurfaceBounce.flush(cart);
|
||||
require(
|
||||
Math.abs(cart.getDeltaMovement().x + 1) < .001
|
||||
&& Math.abs(cart.getDeltaMovement().z - .2) < .001,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param([string]$ServerRoot='C:\Users\ScarPC\Documents\NeoForge Server 26.2',[switch]$Experimental)
|
||||
param([string]$ServerRoot='C:\Users\ScarPC\Documents\NeoForge Server 26.2',[switch]$Experimental,[string]$PlusJar)
|
||||
$ErrorActionPreference='Stop'
|
||||
$project=(Resolve-Path "$PSScriptRoot/../..").Path
|
||||
$java = 'java'
|
||||
@@ -18,7 +18,9 @@ server-ip=127.0.0.1
|
||||
server-port=26783
|
||||
online-mode=false
|
||||
level-type=minecraft:flat
|
||||
generator-settings={"layers":[{"block":"minecraft:bedrock","height":1},{"block":"minecraft:dirt","height":2},{"block":"minecraft:grass_block","height":1}],"biome":"minecraft:plains"}
|
||||
generate-structures=false
|
||||
use-native-transport=false
|
||||
view-distance=2
|
||||
simulation-distance=2
|
||||
spawn-protection=0
|
||||
@@ -28,13 +30,13 @@ if($Experimental){'initial-enabled-packs=vanilla,minecart_improvements' | Add-Co
|
||||
'{"build":{"onStartup":true},"astraPacks":{"enabled":false},"editor":{"enabled":false}}' | Set-Content "$output/config/astraplus.json"
|
||||
$plusRoot=Join-Path (Split-Path $project -Parent) 'AstraPlus'
|
||||
$plusVersion=[regex]::Match((Get-Content "$plusRoot/build.gradle.kts" -Raw), '(?m)^version = "([^"]+)"').Groups[1].Value
|
||||
$plus=Get-Item -LiteralPath "$plusRoot/build/libs/AstraPlus-$plusVersion.jar"
|
||||
$plus=Get-Item -LiteralPath $(if ($PlusJar) { $PlusJar } else { "$plusRoot/build/libs/AstraPlus-$plusVersion.jar" })
|
||||
$packsRoot=Join-Path (Split-Path $project -Parent) 'AstraPacks'
|
||||
$packsVersion=[regex]::Match((Get-Content "$packsRoot/build.gradle.kts" -Raw), '(?m)^version = "([^"]+)"').Groups[1].Value
|
||||
Copy-Item -LiteralPath "$packsRoot/build/libs/AstraPacks-$packsVersion.jar" -Destination "$output/mods"
|
||||
'{"enabled":false}' | Set-Content "$output/config/astrapacks.json"
|
||||
$contentVersion=[regex]::Match((Get-Content "$project/build.gradle.kts" -Raw), '(?m)^version = "([^"]+)"').Groups[1].Value
|
||||
Copy-Item -LiteralPath $plus.FullName,"$project/build/libs/AstraContent-$contentVersion.jar","$project/build/libs/AstraContent-$contentVersion-integration-tests.jar" -Destination "$output/mods"
|
||||
Copy-Item -LiteralPath $plus.FullName,"$project/build/libs/AstraContent-$contentVersion-integration-tests.jar" -Destination "$output/mods"
|
||||
Push-Location $output
|
||||
try {
|
||||
foreach($pass in @('gameplay','restart')) {
|
||||
|
||||
@@ -2,30 +2,10 @@ package online.astradev.content;
|
||||
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
import online.astradev.content.rail.CopperRailBlock;
|
||||
import online.astradev.content.rail.CopperRailRecipe;
|
||||
import online.astradev.content.rail.RailCommands;
|
||||
import online.astradev.content.rail.RailKind;
|
||||
import online.astradev.content.rail.Rails;
|
||||
import online.astradev.content.train.Trains;
|
||||
import online.astradev.content.transport.SlimeBounce;
|
||||
import online.astradev.content.weapon.Ammunition;
|
||||
import online.astradev.plus.api.content.ContentModule;
|
||||
|
||||
@Mod(value = "astracontent", dist = Dist.DEDICATED_SERVER)
|
||||
public final class AstraContent {
|
||||
public AstraContent() {
|
||||
var content = new ContentModule("astracontent");
|
||||
for (RailKind kind : RailKind.variants()) {
|
||||
content.block(kind.id().getPath(), new CopperRailBlock(kind));
|
||||
}
|
||||
content.recipe("copper_rail", new CopperRailRecipe());
|
||||
NeoForge.EVENT_BUS.register(new Rails());
|
||||
NeoForge.EVENT_BUS.register(Ammunition.class);
|
||||
NeoForge.EVENT_BUS.register(RailCommands.class);
|
||||
NeoForge.EVENT_BUS.register(Trains.class);
|
||||
NeoForge.EVENT_BUS.register(SlimeBounce.class);
|
||||
// Compatibility shell. AstraPlus' assembled starter pack owns declarations and runtime.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.transport.SlimeBounce;
|
||||
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public abstract class BoatPacketMixin {
|
||||
@Shadow public ServerPlayer player;
|
||||
@Unique private Entity astra$boat;
|
||||
@Unique private Vec3 astra$boatBefore;
|
||||
|
||||
// Run after vanilla's thread check, so packet-thread rescheduling never mutates state.
|
||||
@Inject(
|
||||
method = "handleMoveVehicle",
|
||||
at =
|
||||
@At(
|
||||
value = "INVOKE",
|
||||
target =
|
||||
"Lnet/minecraft/server/level/ServerPlayer;getRootVehicle()Lnet/minecraft/world/entity/Entity;",
|
||||
shift = At.Shift.BEFORE))
|
||||
private void astra$before(ServerboundMoveVehiclePacket packet, CallbackInfo ci) {
|
||||
astra$boat = player.getRootVehicle();
|
||||
astra$boatBefore = astra$boat.position();
|
||||
}
|
||||
|
||||
@Inject(method = "handleMoveVehicle", at = @At("RETURN"))
|
||||
private void astra$after(ServerboundMoveVehiclePacket packet, CallbackInfo ci) {
|
||||
if (astra$boat != null && astra$boatBefore != null) {
|
||||
SlimeBounce.boatPacket(astra$boat, astra$boatBefore);
|
||||
astra$boat = null;
|
||||
astra$boatBefore = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import online.astradev.content.weapon.Ammunition;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Mixin(CrossbowItem.class)
|
||||
public abstract class CrossbowMixin {
|
||||
@Inject(
|
||||
method = {
|
||||
"getSupportedHeldProjectiles()Ljava/util/function/Predicate;",
|
||||
"getAllSupportedProjectiles()Ljava/util/function/Predicate;"
|
||||
},
|
||||
at = @At("RETURN"),
|
||||
cancellable = true)
|
||||
private void astra$ammo(CallbackInfoReturnable<Predicate<ItemStack>> cir) {
|
||||
cir.setReturnValue(cir.getReturnValue().or(Ammunition::accepts));
|
||||
}
|
||||
|
||||
@Inject(method = "createProjectile", at = @At("HEAD"), cancellable = true)
|
||||
private void astra$create(
|
||||
Level level,
|
||||
LivingEntity owner,
|
||||
ItemStack weapon,
|
||||
ItemStack ammo,
|
||||
boolean critical,
|
||||
CallbackInfoReturnable<Projectile> cir) {
|
||||
if (Ammunition.accepts(ammo)) cir.setReturnValue(Ammunition.create(level, owner, ammo));
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.rail.CartSpeed;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(NewMinecartBehavior.class)
|
||||
public abstract class ExperimentalCartMixin extends MinecartBehavior {
|
||||
protected ExperimentalCartMixin(AbstractMinecart cart) {
|
||||
super(cart);
|
||||
}
|
||||
|
||||
@Inject(method = "calculateTrackSpeed", at = @At("RETURN"), cancellable = true)
|
||||
private void astra$exactSpeed(CallbackInfoReturnable<Vec3> cir) {
|
||||
if (!(level() instanceof ServerLevel level)) return;
|
||||
double limit = ((CartSpeed) minecart).astracontent$limit(level);
|
||||
var movement = cir.getReturnValue();
|
||||
if (limit > 0 && movement.horizontalDistance() > limit)
|
||||
cir.setReturnValue(movement.scale(limit / movement.horizontalDistance()));
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.MinecartFurnace;
|
||||
|
||||
import online.astradev.content.rail.CartSpeed;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(MinecartFurnace.class)
|
||||
public abstract class FurnaceCartMixin {
|
||||
@Inject(method = "getMaxSpeed", at = @At("RETURN"), cancellable = true)
|
||||
private void astra$furnace(ServerLevel level, CallbackInfoReturnable<Double> cir) {
|
||||
double limit = ((CartSpeed) this).astracontent$limit(level);
|
||||
if (limit > 0) cir.setReturnValue(limit);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.storage.*;
|
||||
|
||||
import online.astradev.content.rail.CartSpeed;
|
||||
import online.astradev.content.rail.RailSpeed;
|
||||
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.*;
|
||||
|
||||
@Mixin(AbstractMinecart.class)
|
||||
public abstract class MinecartMixin implements CartSpeed {
|
||||
@Unique private double astra$speed;
|
||||
|
||||
@Inject(method = "getMaxSpeed", at = @At("RETURN"), cancellable = true)
|
||||
private void astra$limit(ServerLevel level, CallbackInfoReturnable<Double> cir) {
|
||||
double limit = astracontent$limit(level);
|
||||
if (limit > 0) cir.setReturnValue(limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double astracontent$limit(ServerLevel level) {
|
||||
var cart = (AbstractMinecart) (Object) this;
|
||||
astra$speed = RailSpeed.target(level, cart.getCurrentBlockPosOrRailBelow(), astra$speed);
|
||||
// Preserve existing experimental gamerules until this cart reaches a regulator.
|
||||
if (astra$speed == 0) return 0;
|
||||
double limit = RailSpeed.safeLimit(cart, level, astra$speed / 20);
|
||||
return limit * (cart.isInWater() ? .5 : 1);
|
||||
}
|
||||
|
||||
@Inject(method = "addAdditionalSaveData", at = @At("RETURN"))
|
||||
private void astra$save(ValueOutput out, CallbackInfo ci) {
|
||||
if (astra$speed > 0) out.putDouble("AstraContentSpeed", astra$speed);
|
||||
}
|
||||
|
||||
@Inject(method = "readAdditionalSaveData", at = @At("RETURN"))
|
||||
private void astra$read(ValueInput in, CallbackInfo ci) {
|
||||
double value = in.getDoubleOr("AstraContentSpeed", 0);
|
||||
astra$speed = Double.isFinite(value) && value > 0 ? Math.clamp(value, 2, 30) : 0;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.projectile.EyeOfEnder;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.weapon.PayloadProjectile;
|
||||
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(EyeOfEnder.class)
|
||||
public abstract class PayloadMixin {
|
||||
@Shadow private boolean surviveAfterDeath;
|
||||
|
||||
@Inject(method = "signalTo", at = @At("RETURN"))
|
||||
private void astra$noDuplicate(Vec3 target, CallbackInfo ci) {
|
||||
if (((EyeOfEnder) (Object) this).entityTags().contains(PayloadProjectile.NO_EYE_DROP))
|
||||
surviveAfterDeath = false;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.*;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import online.astradev.content.rail.Rails;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(PoweredRailBlock.class)
|
||||
public abstract class RailBlockMixin extends BaseRailBlock {
|
||||
protected RailBlockMixin(boolean straight, Properties properties) {
|
||||
super(straight, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(
|
||||
Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
super.setPlacedBy(level, pos, state, placer, stack);
|
||||
if (state.is(Blocks.POWERED_RAIL) && level instanceof ServerLevel server)
|
||||
Rails.placed(server, pos, stack);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.block.BaseRailBlock;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.train.Trains;
|
||||
import online.astradev.content.transport.SlimeBounce;
|
||||
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public abstract class SlimeCollisionMixin {
|
||||
@Unique private Vec3 astra$beforeMove;
|
||||
@Unique private Vec3 astra$incoming;
|
||||
|
||||
@Inject(method = "move", at = @At("HEAD"), cancellable = true)
|
||||
private void astra$before(MoverType type, Vec3 delta, CallbackInfo ci) {
|
||||
var entity = (Entity) (Object) this;
|
||||
astra$beforeMove =
|
||||
type == MoverType.SELF && SlimeBounce.supports(entity) ? entity.position() : null;
|
||||
astra$incoming = entity.getDeltaMovement();
|
||||
// Native powered rails can accelerate from zero within this same tick.
|
||||
if (type == MoverType.SELF
|
||||
&& entity instanceof AbstractMinecart cart
|
||||
&& Trains.paused(cart)
|
||||
&& cart.level().getBlockState(cart.getCurrentBlockPosOrRailBelow()).getBlock()
|
||||
instanceof BaseRailBlock) {
|
||||
astra$beforeMove = null;
|
||||
cart.setDeltaMovement(Vec3.ZERO);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "move", at = @At("RETURN"))
|
||||
private void astra$after(MoverType type, Vec3 delta, CallbackInfo ci) {
|
||||
if (astra$beforeMove != null)
|
||||
SlimeBounce.afterMove((Entity) (Object) this, astra$beforeMove, delta, astra$incoming);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.storage.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import online.astradev.content.train.*;
|
||||
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(AbstractMinecart.class)
|
||||
public abstract class TrainCartMixin {
|
||||
@Unique private Vec3 astra$beforePlayerPush;
|
||||
|
||||
@Inject(method = "addAdditionalSaveData", at = @At("RETURN"))
|
||||
private void astra$save(ValueOutput output, CallbackInfo ci) {
|
||||
CouplingGeometry.save((AbstractMinecart) (Object) this, output);
|
||||
}
|
||||
|
||||
@Inject(method = "readAdditionalSaveData", at = @At("RETURN"))
|
||||
private void astra$read(ValueInput input, CallbackInfo ci) {
|
||||
CouplingGeometry.load((AbstractMinecart) (Object) this, input);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "push(Lnet/minecraft/world/entity/Entity;)V",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private void astra$noInternalCollision(Entity other, CallbackInfo ci) {
|
||||
var self = (AbstractMinecart) (Object) this;
|
||||
astra$beforePlayerPush = other instanceof Player ? self.getDeltaMovement() : null;
|
||||
if (other instanceof AbstractMinecart cart && Trains.connected(self, cart)) ci.cancel();
|
||||
}
|
||||
|
||||
@Inject(method = "push(Lnet/minecraft/world/entity/Entity;)V", at = @At("RETURN"))
|
||||
private void astra$playerPush(Entity other, CallbackInfo ci) {
|
||||
var self = (AbstractMinecart) (Object) this;
|
||||
if (astra$beforePlayerPush == null) return;
|
||||
Vec3 impulse = self.getDeltaMovement().subtract(astra$beforePlayerPush);
|
||||
astra$beforePlayerPush = null;
|
||||
if (impulse.horizontalDistanceSqr() > 1e-12) Trains.playerPush(self);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
public interface CartSpeed {
|
||||
/** Blocks per tick, or zero until the cart encounters a powered speed regulator. */
|
||||
double astracontent$limit(ServerLevel level);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import online.astradev.plus.api.content.RailBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Copper variants inherit powered-rail placement, shape, collision and redstone behavior. */
|
||||
public final class CopperRailBlock extends RailBlock {
|
||||
private static final List<String> NAMES =
|
||||
List.of(
|
||||
"Медные рельсы", "Потемневшие медные рельсы",
|
||||
"Состаренные медные рельсы", "Окисленные медные рельсы");
|
||||
private final int age;
|
||||
|
||||
public CopperRailBlock(RailKind kind) {
|
||||
age = kind.age();
|
||||
base("minecraft:powered_rail");
|
||||
String displayName = NAMES.get(age);
|
||||
if (kind.waxed()) displayName = "Вощёные: " + displayName;
|
||||
name(displayName);
|
||||
itemModel(kind.id().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String model(String shape, boolean powered) {
|
||||
String path = "astracontent:rail_display/" + age + "/" + shape;
|
||||
return powered ? path + "_on" : path;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import online.astradev.plus.api.content.Recipe;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class CopperRailRecipe extends Recipe {
|
||||
public CopperRailRecipe() {
|
||||
super(Station.CRAFTING);
|
||||
var ingredients =
|
||||
Map.of(
|
||||
'C', "minecraft:copper_ingot",
|
||||
'S', "minecraft:stick",
|
||||
'R', "minecraft:redstone");
|
||||
pattern(ingredients, "C C", "CSC", "CRC");
|
||||
result("astracontent:copper_rail", 6);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
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.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
|
||||
public final class RailCommands {
|
||||
private RailCommands() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegisterCommandsEvent event) {
|
||||
var give = Commands.literal("give");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
var kind = RailKind.decode(i);
|
||||
give.then(
|
||||
Commands.literal(kind.id().getPath()).executes(context -> give(context, kind)));
|
||||
}
|
||||
event.getDispatcher()
|
||||
.register(
|
||||
Commands.literal("astracontent")
|
||||
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
||||
.then(give));
|
||||
}
|
||||
|
||||
private static int give(CommandContext<CommandSourceStack> context, RailKind kind)
|
||||
throws CommandSyntaxException {
|
||||
var player = context.getSource().getPlayerOrException();
|
||||
var stack = RailItems.create(kind, 64);
|
||||
AstraPlusApi.give(player, stack);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record RailKind(int age, boolean waxed) {
|
||||
private static final List<String> PREFIXES = List.of("", "exposed_", "weathered_", "oxidized_");
|
||||
private static final List<RailKind> VARIANTS =
|
||||
List.of(
|
||||
new RailKind(0, false), new RailKind(1, false),
|
||||
new RailKind(2, false), new RailKind(3, false),
|
||||
new RailKind(0, true), new RailKind(1, true),
|
||||
new RailKind(2, true), new RailKind(3, true));
|
||||
|
||||
public static List<RailKind> variants() {
|
||||
return VARIANTS;
|
||||
}
|
||||
|
||||
public RailKind {
|
||||
if (age < 0 || age > 3) throw new IllegalArgumentException("Oxidation: " + age);
|
||||
}
|
||||
|
||||
public int speed() {
|
||||
return 20 - 4 * age;
|
||||
}
|
||||
|
||||
public int code() {
|
||||
return age + (waxed ? 4 : 0);
|
||||
}
|
||||
|
||||
public static RailKind decode(int code) {
|
||||
return new RailKind(code & 3, (code & 4) != 0);
|
||||
}
|
||||
|
||||
public Identifier id() {
|
||||
return Identifier.fromNamespaceAndPath(
|
||||
"astracontent", (waxed ? "waxed_" : "") + PREFIXES.get(age) + "copper_rail");
|
||||
}
|
||||
|
||||
public static RailKind fromId(Identifier id) {
|
||||
if (!id.getNamespace().equals("astracontent")) return null;
|
||||
int code =
|
||||
switch (id.getPath()) {
|
||||
case "copper_rail" -> 0;
|
||||
case "exposed_copper_rail" -> 1;
|
||||
case "weathered_copper_rail" -> 2;
|
||||
case "oxidized_copper_rail" -> 3;
|
||||
case "waxed_copper_rail" -> 4;
|
||||
case "waxed_exposed_copper_rail" -> 5;
|
||||
case "waxed_weathered_copper_rail" -> 6;
|
||||
case "waxed_oxidized_copper_rail" -> 7;
|
||||
default -> -1;
|
||||
};
|
||||
return code < 0 ? null : VARIANTS.get(code);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.WeatheringCopper;
|
||||
import net.minecraft.world.level.gamerules.GameRules;
|
||||
|
||||
/** Match copper's random-tick selection, age neighborhood and oxidation probability. */
|
||||
final class RailOxidation {
|
||||
private RailOxidation() {}
|
||||
|
||||
static boolean advance(ServerLevel level, BlockPos pos, RailKind kind) {
|
||||
if (kind.waxed() || kind.age() == 3 || !level.isPositionEntityTicking(pos)) return false;
|
||||
int rate = level.getGameRules().get(GameRules.RANDOM_TICK_SPEED);
|
||||
double chance = 1 - Math.pow(1 - .05688889 / 4096, rate);
|
||||
if (level.getRandom().nextDouble() >= chance) return false;
|
||||
int older = 0, same = 0;
|
||||
for (var other : BlockPos.withinManhattan(pos, 4, 4, 4)) {
|
||||
int distance = other.distManhattan(pos);
|
||||
if (distance > 4) break;
|
||||
if (distance == 0 || !level.hasChunkAt(other)) continue;
|
||||
int age = -1;
|
||||
var rail = Rails.find(level, other);
|
||||
if (rail != null && !rail.waxed()) age = rail.age();
|
||||
else if (level.getBlockState(other).getBlock() instanceof WeatheringCopper copper)
|
||||
age = copper.getAge().ordinal();
|
||||
if (age < 0) continue;
|
||||
if (age < kind.age()) return false;
|
||||
if (age > kind.age()) older++;
|
||||
else same++;
|
||||
}
|
||||
double ratio = (older + 1.0) / (older + same + 1.0);
|
||||
return level.getRandom().nextDouble() < ratio * ratio * (kind.age() == 0 ? .75 : 1);
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.RailShape;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class RailSpeed {
|
||||
private RailSpeed() {}
|
||||
|
||||
public static int signalSpeed(int signal) {
|
||||
return Math.clamp(signal, 0, 15) * 2;
|
||||
}
|
||||
|
||||
public static double target(ServerLevel level, BlockPos pos, double previous) {
|
||||
var state = level.getBlockState(pos);
|
||||
if (!state.is(Blocks.POWERED_RAIL) || !state.getValue(PoweredRailBlock.POWERED))
|
||||
return previous;
|
||||
var kind = Rails.find(level, pos);
|
||||
return kind != null ? kind.speed() : Math.max(2, signalSpeed(signal(level, pos)));
|
||||
}
|
||||
|
||||
/** Mirror the vanilla eight-rail power reach, preserving bends, slopes and highest input. */
|
||||
public static int signal(ServerLevel level, BlockPos origin) {
|
||||
record Step(BlockPos pos, int distance) {}
|
||||
var queue = new ArrayDeque<Step>();
|
||||
var seen = new HashSet<BlockPos>();
|
||||
queue.add(new Step(origin, 0));
|
||||
int best = 0;
|
||||
while (!queue.isEmpty()) {
|
||||
var step = queue.removeFirst();
|
||||
if (!seen.add(step.pos) || !level.hasChunkAt(step.pos)) continue;
|
||||
var state = level.getBlockState(step.pos);
|
||||
if (!state.is(Blocks.POWERED_RAIL)) continue;
|
||||
best = Math.max(best, level.getBestNeighborSignal(step.pos));
|
||||
if (best == 15) return best;
|
||||
if (step.distance == 8) continue;
|
||||
var shape = state.getValue(PoweredRailBlock.SHAPE);
|
||||
var exits = AbstractMinecart.exits(shape);
|
||||
for (var exit : List.of(exits.getFirst(), exits.getSecond())) {
|
||||
var adjacent =
|
||||
step.pos.offset(
|
||||
exit.getX(), shape.isSlope() ? exit.getY() + 1 : 0, exit.getZ());
|
||||
for (var candidate : List.of(adjacent, adjacent.below())) {
|
||||
if (!level.hasChunkAt(candidate)) continue;
|
||||
var other = level.getBlockState(candidate);
|
||||
if (other.is(Blocks.POWERED_RAIL)
|
||||
&& connected(
|
||||
step.pos,
|
||||
shape,
|
||||
candidate,
|
||||
other.getValue(PoweredRailBlock.SHAPE)))
|
||||
queue.add(new Step(candidate, step.distance + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static boolean connected(BlockPos a, RailShape sa, BlockPos b, RailShape sb) {
|
||||
var ea = AbstractMinecart.exits(sa);
|
||||
var eb = AbstractMinecart.exits(sb);
|
||||
for (var exitA : List.of(ea.getFirst(), ea.getSecond())) {
|
||||
if (a.getX() + exitA.getX() != b.getX()) continue;
|
||||
if (a.getZ() + exitA.getZ() != b.getZ()) continue;
|
||||
int heightA = exitHeight(a, sa, exitA);
|
||||
for (var exitB : List.of(eb.getFirst(), eb.getSecond())) {
|
||||
if (b.getX() + exitB.getX() != a.getX()) continue;
|
||||
if (b.getZ() + exitB.getZ() != a.getZ()) continue;
|
||||
if (heightA == exitHeight(b, sb, exitB)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int exitHeight(BlockPos pos, RailShape shape, Vec3i exit) {
|
||||
if (shape.isSlope()) return pos.getY() + exit.getY() + 1;
|
||||
return pos.getY();
|
||||
}
|
||||
|
||||
private static boolean stopsFastTravel(BlockState state) {
|
||||
if (state.is(Blocks.DETECTOR_RAIL) || state.is(Blocks.ACTIVATOR_RAIL)) return true;
|
||||
return state.is(Blocks.POWERED_RAIL) && !state.getValue(PoweredRailBlock.POWERED);
|
||||
}
|
||||
|
||||
/** Old movement needs vanilla speed when approaching bends, slopes or the end of a track. */
|
||||
public static double safeLimit(AbstractMinecart cart, ServerLevel level, double limit) {
|
||||
if (AbstractMinecart.useExperimentalMovement(level) || limit <= .4) return limit;
|
||||
var pos = cart.getCurrentBlockPosOrRailBelow();
|
||||
var movement = cart.getDeltaMovement();
|
||||
int dx = (int) Math.signum(movement.x), dz = (int) Math.signum(movement.z);
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
var check = pos.offset(dx * i, 0, dz * i);
|
||||
if (!level.hasChunkAt(check)) return .4;
|
||||
BlockState state = level.getBlockState(check);
|
||||
if (!(state.getBlock() instanceof BaseRailBlock rail))
|
||||
return state.is(Blocks.SLIME_BLOCK) ? limit : .4;
|
||||
RailShape shape = rail.getRailDirection(state, level, check, cart);
|
||||
if (shape != RailShape.NORTH_SOUTH && shape != RailShape.EAST_WEST) return .4;
|
||||
if (i > 0 && stopsFastTravel(state)) return .4;
|
||||
// Never jump over a single slower regulator.
|
||||
if (i > 0) limit = Math.min(limit, target(level, check, limit * 20) / 20);
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import static online.astradev.plus.api.AstraPlusApi.position;
|
||||
import static online.astradev.plus.api.AstraPlusApi.world;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.neoforged.bus.api.*;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.neoforge.event.level.ChunkEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
|
||||
import online.astradev.plus.api.content.BlockData;
|
||||
import online.astradev.plus.api.content.ContentModule;
|
||||
import online.astradev.plus.api.world.BlockPosition;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** Native powered rails own placement, shape, redstone, collision and destruction. */
|
||||
public final class Rails {
|
||||
// Read and retire the storage already used by existing worlds. New blocks use API identities.
|
||||
private static final BlockData<Integer> PREVIOUS_VARIANTS =
|
||||
new ContentModule("astracontent")
|
||||
.blockData("copper_rails", BlockData.integers("rails", 0, 7));
|
||||
|
||||
private record Position(ServerLevel level, BlockPos pos) {}
|
||||
|
||||
private static final Set<Position> ACTIVE = new HashSet<>();
|
||||
|
||||
public Rails() {}
|
||||
|
||||
public static RailKind find(ServerLevel level, BlockPos pos) {
|
||||
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
if (chunk == null) return null;
|
||||
if (!level.getBlockState(pos).is(Blocks.POWERED_RAIL)) return null;
|
||||
String id = world(level).block(position(pos));
|
||||
var kind = RailKind.fromId(Identifier.parse(id));
|
||||
if (kind != null) return kind;
|
||||
Integer code = PREVIOUS_VARIANTS.get(world(level), position(pos)).orElse(null);
|
||||
return code == null ? null : RailKind.decode(code);
|
||||
}
|
||||
|
||||
public static void placed(ServerLevel level, BlockPos pos, ItemStack stack) {
|
||||
clear(level, pos);
|
||||
var kind = RailItems.find(stack);
|
||||
if (kind != null) put(level, pos, kind);
|
||||
}
|
||||
|
||||
public static void put(ServerLevel level, BlockPos pos, RailKind kind) {
|
||||
var world = world(level);
|
||||
var position = position(pos);
|
||||
if (!world.replaceBlock(position, kind.id().toString())) {
|
||||
throw new IllegalStateException("Cannot place copper rail at " + pos);
|
||||
}
|
||||
PREVIOUS_VARIANTS.remove(world, position);
|
||||
ACTIVE.add(new Position(level, pos.immutable()));
|
||||
}
|
||||
|
||||
private static void clear(ServerLevel level, BlockPos pos) {
|
||||
var chunk = level.getChunkSource().getChunkNow(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
if (chunk != null) PREVIOUS_VARIANTS.remove(world(level), position(pos));
|
||||
ACTIVE.remove(new Position(level, pos));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void load(ChunkEvent.Load event) {
|
||||
if (!(event.getLevel() instanceof ServerLevel level)
|
||||
|| !(event.getChunk() instanceof LevelChunk chunk)) return;
|
||||
level.getServer().execute(() -> loadRails(level, chunk));
|
||||
}
|
||||
|
||||
private static void loadRails(ServerLevel level, LevelChunk chunk) {
|
||||
var chunkPos = chunk.getPos();
|
||||
if (level.getChunkSource().getChunkNow(chunkPos.x(), chunkPos.z()) != chunk) return;
|
||||
var origin = new BlockPosition(chunkPos.x() << 4, level.getMinY(), chunkPos.z() << 4);
|
||||
var world = world(level);
|
||||
for (var saved : PREVIOUS_VARIANTS.inChunk(world, origin).entrySet()) {
|
||||
var position = saved.getKey();
|
||||
var pos = new BlockPos(position.x(), position.y(), position.z());
|
||||
if (level.getBlockState(pos).is(Blocks.POWERED_RAIL))
|
||||
put(level, pos, RailKind.decode(saved.getValue()));
|
||||
else PREVIOUS_VARIANTS.remove(world, position);
|
||||
}
|
||||
for (var entry : world.blocksInChunk(origin).entrySet()) {
|
||||
if (RailKind.fromId(Identifier.parse(entry.getValue())) == null) continue;
|
||||
var saved = entry.getKey();
|
||||
var pos = new BlockPos(saved.x(), saved.y(), saved.z());
|
||||
ACTIVE.add(new Position(level, pos));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void unload(ChunkEvent.Unload event) {
|
||||
for (var key : new ArrayList<>(ACTIVE))
|
||||
if (key.level == event.getLevel()
|
||||
&& key.pos.getX() >> 4 == event.getChunk().getPos().x()
|
||||
&& key.pos.getZ() >> 4 == event.getChunk().getPos().z()) {
|
||||
ACTIVE.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void stopped(ServerStoppedEvent event) {
|
||||
ACTIVE.clear();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(ServerTickEvent.Post event) {
|
||||
for (var key : new ArrayList<>(ACTIVE)) {
|
||||
var state = key.level.getBlockState(key.pos);
|
||||
var kind = find(key.level, key.pos);
|
||||
if (kind == null || !state.is(Blocks.POWERED_RAIL)) {
|
||||
clear(key.level, key.pos);
|
||||
continue;
|
||||
}
|
||||
if (RailOxidation.advance(key.level, key.pos, kind)) {
|
||||
kind = new RailKind(kind.age() + 1, false);
|
||||
put(key.level, key.pos, kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void use(PlayerInteractEvent.RightClickBlock event) {
|
||||
if (event.isCanceled()) return;
|
||||
if (!(event.getLevel() instanceof ServerLevel level)) return;
|
||||
var kind = find(level, event.getPos());
|
||||
if (kind == null) return;
|
||||
var item = event.getItemStack();
|
||||
RailKind next;
|
||||
int effect;
|
||||
if (item.is(Items.HONEYCOMB) && !kind.waxed()) {
|
||||
next = new RailKind(kind.age(), true);
|
||||
effect = 3003;
|
||||
} else if (item.getItem() instanceof AxeItem && (kind.waxed() || kind.age() > 0)) {
|
||||
next =
|
||||
kind.waxed()
|
||||
? new RailKind(kind.age(), false)
|
||||
: new RailKind(kind.age() - 1, false);
|
||||
effect = kind.waxed() ? 3004 : 3005;
|
||||
} else return;
|
||||
if (!event.getEntity().mayBuild()) return;
|
||||
put(level, event.getPos(), next);
|
||||
level.levelEvent(null, effect, event.getPos(), 0);
|
||||
if (item.is(Items.HONEYCOMB)) item.consume(1, event.getEntity());
|
||||
else item.hurtAndBreak(1, event.getEntity(), event.getHand().asEquipmentSlot());
|
||||
event.setCanceled(true);
|
||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package online.astradev.content.train;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.block.BaseRailBlock;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public final class CouplingGeometry {
|
||||
// Remember physical ends even when movement reverses. Unloaded carts are not retained.
|
||||
private static final Map<AbstractMinecart, Vec3> FRONTS = new WeakHashMap<>();
|
||||
|
||||
private CouplingGeometry() {}
|
||||
|
||||
public static Vec3 front(AbstractMinecart cart) {
|
||||
Vec3 previous = FRONTS.getOrDefault(cart, Vec3.ZERO);
|
||||
if (previous.lengthSqr() < 0.5) previous = facing(cart);
|
||||
Vec3 direction = railDirection(cart);
|
||||
if (direction == null) direction = previous;
|
||||
else if (direction.dot(previous) < 0) direction = direction.scale(-1);
|
||||
FRONTS.put(cart, direction);
|
||||
return direction;
|
||||
}
|
||||
|
||||
private static Vec3 facing(AbstractMinecart cart) {
|
||||
double yaw = Math.toRadians(cart.getYRot());
|
||||
double x = Math.cos(yaw);
|
||||
double z = Math.sin(yaw);
|
||||
if (AbstractMinecart.useExperimentalMovement(cart.level())) z = -z;
|
||||
return new Vec3(x, 0, z);
|
||||
}
|
||||
|
||||
public static boolean onRail(AbstractMinecart cart) {
|
||||
var position = cart.getCurrentBlockPosOrRailBelow();
|
||||
return cart.level().getBlockState(position).getBlock() instanceof BaseRailBlock;
|
||||
}
|
||||
|
||||
/** Vanilla exit order, without the persistent choice of a front end; null off rails. */
|
||||
public static Vec3 railDirection(AbstractMinecart cart) {
|
||||
var pos = cart.getCurrentBlockPosOrRailBelow();
|
||||
var state = cart.level().getBlockState(pos);
|
||||
if (!(state.getBlock() instanceof BaseRailBlock rail)) return null;
|
||||
var shape = rail.getRailDirection(state, cart.level(), pos, cart);
|
||||
var exits = AbstractMinecart.exits(shape);
|
||||
Vec3 start = new Vec3(exits.getFirst());
|
||||
Vec3 end = new Vec3(exits.getSecond());
|
||||
return end.subtract(start).horizontal().normalize();
|
||||
}
|
||||
|
||||
public static void restoreFront(AbstractMinecart cart, Vec3 direction) {
|
||||
if (!Double.isFinite(direction.x) || !Double.isFinite(direction.z)) {
|
||||
FRONTS.remove(cart);
|
||||
return;
|
||||
}
|
||||
FRONTS.put(cart, direction.horizontal().normalize());
|
||||
}
|
||||
|
||||
public static void save(AbstractMinecart cart, ValueOutput output) {
|
||||
Vec3 front = FRONTS.getOrDefault(cart, Vec3.ZERO);
|
||||
output.putDouble("AstraTrainFrontX", front.x);
|
||||
output.putDouble("AstraTrainFrontZ", front.z);
|
||||
}
|
||||
|
||||
public static void load(AbstractMinecart cart, ValueInput input) {
|
||||
double x = input.getDoubleOr("AstraTrainFrontX", 0);
|
||||
double z = input.getDoubleOr("AstraTrainFrontZ", 0);
|
||||
restoreFront(cart, new Vec3(x, 0, z));
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
FRONTS.clear();
|
||||
}
|
||||
|
||||
public static int hitEnd(Vec3 axis, Vec3 localHit) {
|
||||
double along = localHit.horizontal().dot(axis);
|
||||
double across = Math.abs(localHit.x * axis.z - localHit.z * axis.x);
|
||||
if (Math.abs(along) < .32 || Math.abs(along) <= across * 1.3) return -1;
|
||||
return along > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
public static Vec3 outward(AbstractMinecart cart, int end) {
|
||||
Vec3 direction = front(cart);
|
||||
return end == 0 ? direction : direction.scale(-1);
|
||||
}
|
||||
|
||||
public static Vec3 anchor(AbstractMinecart cart, int end) {
|
||||
Vec3 center = cart.position().add(0, 0.35, 0);
|
||||
Vec3 offset = outward(cart, end).scale(0.48);
|
||||
return center.add(offset);
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package online.astradev.content.train;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.saveddata.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** One authoritative record per chain, including unloaded carts. No duplicated refunds. */
|
||||
public final class TrainData extends SavedData {
|
||||
public record Link(
|
||||
UUID a, int endA, UUID b, int endB, String item, boolean paid, double length) {
|
||||
private static final Codec<UUID> UUID_CODEC =
|
||||
Codec.STRING.xmap(UUID::fromString, UUID::toString);
|
||||
static final Codec<Link> CODEC =
|
||||
RecordCodecBuilder.create(
|
||||
instance -> {
|
||||
var a = UUID_CODEC.fieldOf("a").forGetter(Link::a);
|
||||
var endA = Codec.intRange(0, 1).fieldOf("end_a").forGetter(Link::endA);
|
||||
var b = UUID_CODEC.fieldOf("b").forGetter(Link::b);
|
||||
var endB = Codec.intRange(0, 1).fieldOf("end_b").forGetter(Link::endB);
|
||||
var item = Codec.STRING.fieldOf("item").forGetter(Link::item);
|
||||
var paid = Codec.BOOL.fieldOf("paid").forGetter(Link::paid);
|
||||
var length =
|
||||
Codec.doubleRange(1, 4)
|
||||
.fieldOf("length")
|
||||
.forGetter(Link::length);
|
||||
var fields = instance.group(a, endA, b, endB, item, paid, length);
|
||||
return fields.apply(instance, Link::new);
|
||||
});
|
||||
|
||||
public boolean touches(UUID id) {
|
||||
return a.equals(id) || b.equals(id);
|
||||
}
|
||||
|
||||
public UUID other(UUID id) {
|
||||
return a.equals(id) ? b : a;
|
||||
}
|
||||
|
||||
public int end(UUID id) {
|
||||
return a.equals(id) ? endA : endB;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Codec<TrainData> CODEC =
|
||||
Link.CODEC
|
||||
.listOf()
|
||||
.xmap(TrainData::new, d -> List.copyOf(d.links))
|
||||
.fieldOf("links")
|
||||
.codec();
|
||||
private static final SavedDataType<TrainData> TYPE =
|
||||
new SavedDataType<>(
|
||||
Identifier.fromNamespaceAndPath("astracontent", "trains"),
|
||||
TrainData::new,
|
||||
CODEC);
|
||||
private final List<Link> links = new ArrayList<>();
|
||||
private final Map<UUID, Set<UUID>> components = new HashMap<>();
|
||||
|
||||
public TrainData() {}
|
||||
|
||||
private TrainData(List<Link> links) {
|
||||
this.links.addAll(links);
|
||||
}
|
||||
|
||||
public static TrainData get(ServerLevel level) {
|
||||
return level.getDataStorage().computeIfAbsent(TYPE);
|
||||
}
|
||||
|
||||
public List<Link> links() {
|
||||
return List.copyOf(links);
|
||||
}
|
||||
|
||||
public Link at(UUID cart, int end) {
|
||||
for (Link link : links) {
|
||||
if (link.touches(cart) && link.end(cart) == end) return link;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(Link link) {
|
||||
links.add(link);
|
||||
components.clear();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
public boolean remove(Link link) {
|
||||
boolean removed = links.remove(link);
|
||||
if (removed) {
|
||||
components.clear();
|
||||
setDirty();
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
public Set<UUID> component(UUID root) {
|
||||
var cached = components.get(root);
|
||||
if (cached != null) return cached;
|
||||
var seen = new HashSet<UUID>();
|
||||
var pending = new ArrayDeque<UUID>();
|
||||
pending.add(root);
|
||||
while (!pending.isEmpty()) {
|
||||
var id = pending.removeFirst();
|
||||
if (!seen.add(id)) continue;
|
||||
for (var link : links) if (link.touches(id)) pending.add(link.other(id));
|
||||
}
|
||||
var component = Set.copyOf(seen);
|
||||
// Collision checks reuse topology until a chain changes; ordinary carts are not cached.
|
||||
if (component.size() > 1) {
|
||||
for (UUID cart : component) components.put(cart, component);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
}
|
||||
@@ -1,370 +0,0 @@
|
||||
package online.astradev.content.train;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.phys.*;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityLeaveLevelEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
|
||||
import online.astradev.plus.api.BlockLine;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class Trains {
|
||||
private record DisplayKey(ServerLevel level, TrainData.Link link) {}
|
||||
|
||||
private static final Map<DisplayKey, BlockLine> DISPLAYS = new HashMap<>();
|
||||
private static final Map<ServerLevel, Set<UUID>> PAUSED = new HashMap<>();
|
||||
private static final Map<ServerLevel, Set<UUID>> PLAYER_PUSHES = new HashMap<>();
|
||||
|
||||
private Trains() {}
|
||||
|
||||
public static boolean paused(AbstractMinecart cart) {
|
||||
return PAUSED.getOrDefault(cart.level(), Set.of()).contains(cart.getUUID());
|
||||
}
|
||||
|
||||
public static void playerPush(AbstractMinecart cart) {
|
||||
if (cart.level() instanceof ServerLevel level)
|
||||
PLAYER_PUSHES.computeIfAbsent(level, key -> new HashSet<>()).add(cart.getUUID());
|
||||
}
|
||||
|
||||
public static boolean isChain(ItemStack stack) {
|
||||
return stack.getItem() instanceof BlockItem item && item.getBlock() instanceof ChainBlock;
|
||||
}
|
||||
|
||||
public static boolean connected(AbstractMinecart a, AbstractMinecart b) {
|
||||
return a.level() instanceof ServerLevel level
|
||||
&& b.level() == level
|
||||
&& TrainData.get(level).component(a.getUUID()).contains(b.getUUID());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void interact(PlayerInteractEvent.EntityInteract event) {
|
||||
if (!(event.getTarget() instanceof AbstractMinecart cart)) return;
|
||||
if (!(event.getEntity() instanceof ServerPlayer player)) return;
|
||||
if (!player.isShiftKeyDown()) return;
|
||||
var level = player.level();
|
||||
var item = event.getItemStack();
|
||||
boolean chain = isChain(item);
|
||||
if (!chain && !item.is(ItemTags.PICKAXES)) return;
|
||||
event.setCanceled(true);
|
||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||
if (!player.mayBuild()) return;
|
||||
int end = CouplingGeometry.hitEnd(CouplingGeometry.front(cart), event.getLocation());
|
||||
if (end < 0) {
|
||||
player.sendSystemMessage(
|
||||
Component.literal("Цепь крепится только к переднему или заднему торцу."), true);
|
||||
return;
|
||||
}
|
||||
var data = TrainData.get(level);
|
||||
var existing = data.at(cart.getUUID(), end);
|
||||
if (!chain) {
|
||||
if (existing == null) {
|
||||
player.sendSystemMessage(Component.literal("На этом торце нет цепи."), true);
|
||||
return;
|
||||
}
|
||||
unlink(level, existing, cart, true);
|
||||
item.hurtAndBreak(1, player, event.getHand().asEquipmentSlot());
|
||||
return;
|
||||
}
|
||||
if (existing != null) {
|
||||
player.sendSystemMessage(Component.literal("Этот торец уже сцеплен."), true);
|
||||
return;
|
||||
}
|
||||
Vec3 outward = CouplingGeometry.outward(cart, end);
|
||||
var candidates =
|
||||
level.getEntitiesOfClass(
|
||||
AbstractMinecart.class,
|
||||
cart.getBoundingBox().inflate(3.5),
|
||||
other -> other != cart && other.isAlive());
|
||||
candidates.sort(Comparator.comparingDouble(cart::distanceToSqr));
|
||||
for (var other : candidates) {
|
||||
Vec3 between = other.position().subtract(cart.position());
|
||||
double distance = between.length();
|
||||
if (distance < 1 || distance > 3.5 || Math.abs(between.y) > 1.5) continue;
|
||||
var direction = between.horizontal().normalize();
|
||||
if (direction.dot(outward) < .90) continue;
|
||||
int otherEnd = CouplingGeometry.front(other).dot(direction) > 0 ? 1 : 0;
|
||||
if (CouplingGeometry.outward(other, otherEnd).dot(direction) > -.90
|
||||
|| data.at(other.getUUID(), otherEnd) != null) continue;
|
||||
if (!CouplingGeometry.onRail(cart) || !CouplingGeometry.onRail(other)) continue;
|
||||
var hit =
|
||||
level.clip(
|
||||
new ClipContext(
|
||||
CouplingGeometry.anchor(cart, end),
|
||||
CouplingGeometry.anchor(other, otherEnd),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
cart));
|
||||
if (hit.getType() != HitResult.Type.MISS) continue;
|
||||
data.add(
|
||||
new TrainData.Link(
|
||||
cart.getUUID(),
|
||||
end,
|
||||
other.getUUID(),
|
||||
otherEnd,
|
||||
BuiltInRegistries.ITEM.getKey(item.getItem()).toString(),
|
||||
!player.hasInfiniteMaterials(),
|
||||
distance));
|
||||
item.consume(1, player);
|
||||
player.sendSystemMessage(Component.literal("Вагонетки сцеплены."), true);
|
||||
return;
|
||||
}
|
||||
player.sendSystemMessage(
|
||||
Component.literal(
|
||||
"У этого торца нет подходящей свободной вагонетки в пределах 3,5 блока."),
|
||||
true);
|
||||
}
|
||||
|
||||
public static void unlink(ServerLevel level, TrainData.Link link, Entity at, boolean refund) {
|
||||
if (!TrainData.get(level).remove(link)) return;
|
||||
discard(new DisplayKey(level, link));
|
||||
if (refund && link.paid()) at.spawnAtLocation(level, new ItemStack(chainItem(link)));
|
||||
}
|
||||
|
||||
private static Item chainItem(TrainData.Link link) {
|
||||
var id = Identifier.tryParse(link.item());
|
||||
var item = id == null ? Items.IRON_CHAIN : BuiltInRegistries.ITEM.getValue(id);
|
||||
return item != null && isChain(new ItemStack(item)) ? item : Items.IRON_CHAIN;
|
||||
}
|
||||
|
||||
private static AbstractMinecart cart(ServerLevel level, UUID id) {
|
||||
return level.getEntity(id) instanceof AbstractMinecart cart && cart.isAlive() ? cart : null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void leave(EntityLeaveLevelEvent event) {
|
||||
if (!(event.getEntity() instanceof AbstractMinecart cart)
|
||||
|| !(event.getLevel() instanceof ServerLevel level)) return;
|
||||
var reason = cart.getRemovalReason();
|
||||
for (var link : TrainData.get(level).links())
|
||||
if (link.touches(cart.getUUID())) {
|
||||
// Visibility/unload callbacks can run while vanilla iterates an entity section.
|
||||
// Let the post-tick display pass remove those visuals outside that iteration.
|
||||
if (reason != null
|
||||
&& (reason.shouldDestroy()
|
||||
|| reason == Entity.RemovalReason.CHANGED_DIMENSION))
|
||||
unlink(level, link, cart, true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void pre(ServerTickEvent.Pre event) {
|
||||
for (var level : event.getServer().getAllLevels()) step(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronize momentum along each cart's rail tangent; springs correct chain slack, never
|
||||
* teleport carts.
|
||||
*/
|
||||
public static void step(ServerLevel level) {
|
||||
var pausedCarts = new HashSet<UUID>();
|
||||
PAUSED.put(level, pausedCarts);
|
||||
var playerPushes = PLAYER_PUSHES.remove(level);
|
||||
if (playerPushes == null) playerPushes = Set.of();
|
||||
var data = TrainData.get(level);
|
||||
var links = data.links();
|
||||
var visited = new HashSet<UUID>();
|
||||
for (var seed : links) {
|
||||
if (visited.contains(seed.a())) continue;
|
||||
var signs = directions(seed.a(), links);
|
||||
visited.addAll(signs.keySet());
|
||||
moveTrain(level, links, signs, pausedCarts, playerPushes);
|
||||
}
|
||||
}
|
||||
|
||||
private static void moveTrain(
|
||||
ServerLevel level,
|
||||
List<TrainData.Link> links,
|
||||
Map<UUID, Integer> signs,
|
||||
Set<UUID> pausedCarts,
|
||||
Set<UUID> playerPushes) {
|
||||
var carts = new LinkedHashMap<UUID, AbstractMinecart>();
|
||||
var axes = new HashMap<UUID, Vec3>();
|
||||
boolean paused = false;
|
||||
double momentum = 0;
|
||||
double limit = Double.MAX_VALUE;
|
||||
double controlledMomentum = 0;
|
||||
var controls = new HashSet<UUID>();
|
||||
for (var pair : signs.entrySet()) {
|
||||
var cart = cart(level, pair.getKey());
|
||||
if (cart == null) {
|
||||
paused = true;
|
||||
continue;
|
||||
}
|
||||
carts.put(pair.getKey(), cart);
|
||||
Vec3 tangent = CouplingGeometry.front(cart).scale(pair.getValue());
|
||||
axes.put(pair.getKey(), tangent);
|
||||
if (!CouplingGeometry.onRail(cart)) paused = true;
|
||||
double scale = travelScale(cart);
|
||||
momentum += cart.getDeltaMovement().dot(tangent) * scale;
|
||||
if (playerControls(cart, playerPushes)) {
|
||||
controlledMomentum += alignedSpeed(cart, tangent) * scale;
|
||||
controls.add(cart.getUUID());
|
||||
}
|
||||
limit = Math.min(limit, cart.getMaxSpeed(level));
|
||||
}
|
||||
if (carts.isEmpty()) return;
|
||||
if (paused) {
|
||||
pausedCarts.addAll(carts.keySet());
|
||||
carts.values().forEach(c -> c.setDeltaMovement(Vec3.ZERO));
|
||||
return;
|
||||
}
|
||||
// Player input drives the train as a unit. Averaging it with idle carts diluted
|
||||
// the tiny vanilla rider impulse; a dot product also erased side-on walking pushes.
|
||||
double speed = momentum / carts.size();
|
||||
if (!controls.isEmpty()) speed = controlledMomentum / controls.size();
|
||||
speed = Math.clamp(speed, -limit, limit);
|
||||
var corrections = new HashMap<UUID, Double>();
|
||||
for (var link : links)
|
||||
if (carts.containsKey(link.a()) && carts.containsKey(link.b())) {
|
||||
var a = carts.get(link.a());
|
||||
var b = carts.get(link.b());
|
||||
double distance = a.position().distanceTo(b.position());
|
||||
if (distance > 6) {
|
||||
unlink(level, link, a, true);
|
||||
continue;
|
||||
}
|
||||
double pull = Math.clamp((distance - link.length()) * .22, -.18, .18);
|
||||
double direction = signs.get(link.a()) * (link.endA() == 0 ? 1 : -1);
|
||||
corrections.merge(link.a(), pull * direction, Double::sum);
|
||||
corrections.merge(link.b(), -pull * direction, Double::sum);
|
||||
}
|
||||
for (var pair : carts.entrySet()) {
|
||||
// Followers take up slack; pulling back the driven cart would cancel its 0.001
|
||||
// rider impulse.
|
||||
var cart = pair.getValue();
|
||||
double cartSpeed = speed;
|
||||
if (!controls.contains(pair.getKey())) {
|
||||
cartSpeed += corrections.getOrDefault(pair.getKey(), 0.0);
|
||||
}
|
||||
cartSpeed = Math.clamp(cartSpeed, -limit, limit);
|
||||
Vec3 direction = axes.get(pair.getKey());
|
||||
Vec3 velocity = direction.scale(cartSpeed / travelScale(cart));
|
||||
cart.setDeltaMovement(velocity.x, cart.getDeltaMovement().y, velocity.z);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<UUID, Integer> directions(UUID start, List<TrainData.Link> links) {
|
||||
var signs = new LinkedHashMap<UUID, Integer>();
|
||||
var pending = new ArrayDeque<UUID>();
|
||||
signs.put(start, 1);
|
||||
pending.add(start);
|
||||
while (!pending.isEmpty()) {
|
||||
var id = pending.removeFirst();
|
||||
for (var link : links) {
|
||||
if (!link.touches(id)) continue;
|
||||
var other = link.other(id);
|
||||
if (signs.containsKey(other)) continue;
|
||||
int sign = signs.get(id);
|
||||
if (link.end(id) == link.end(other)) sign = -sign;
|
||||
signs.put(other, sign);
|
||||
pending.add(other);
|
||||
}
|
||||
}
|
||||
return signs;
|
||||
}
|
||||
|
||||
private static boolean playerControls(AbstractMinecart cart, Set<UUID> pushes) {
|
||||
if (pushes.contains(cart.getUUID())) return true;
|
||||
if (!(cart.getFirstPassenger() instanceof ServerPlayer player)) return false;
|
||||
return player.getLastClientMoveIntent().horizontalDistanceSqr() > 0;
|
||||
}
|
||||
|
||||
private static double travelScale(AbstractMinecart cart) {
|
||||
return !AbstractMinecart.useExperimentalMovement(cart.level()) && cart.isVehicle()
|
||||
? .75
|
||||
: 1;
|
||||
}
|
||||
|
||||
private static double alignedSpeed(AbstractMinecart cart, Vec3 tangent) {
|
||||
var movement = cart.getDeltaMovement();
|
||||
double along = movement.dot(tangent);
|
||||
if (Math.abs(along) < 1e-9) {
|
||||
Vec3 railDirection = CouplingGeometry.railDirection(cart);
|
||||
if (railDirection != null) {
|
||||
along = railDirection.dot(tangent);
|
||||
// Vanilla reverses the default exit for perpendicular input in the new engine.
|
||||
if (AbstractMinecart.useExperimentalMovement(cart.level())) along = -along;
|
||||
}
|
||||
}
|
||||
return Math.copySign(movement.horizontalDistance(), along);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void post(ServerTickEvent.Post event) {
|
||||
for (var level : event.getServer().getAllLevels()) show(level);
|
||||
}
|
||||
|
||||
public static void show(ServerLevel level) {
|
||||
var keys = new HashSet<DisplayKey>();
|
||||
for (var link : TrainData.get(level).links()) {
|
||||
var a = cart(level, link.a());
|
||||
var b = cart(level, link.b());
|
||||
if (a == null || b == null) continue;
|
||||
var key = new DisplayKey(level, link);
|
||||
keys.add(key);
|
||||
var display = DISPLAYS.get(key);
|
||||
boolean create = display == null || display.isRemoved();
|
||||
if (create) {
|
||||
var chain = (BlockItem) chainItem(link);
|
||||
display = new BlockLine(level, chain.getBlock().defaultBlockState());
|
||||
}
|
||||
Vec3 start = CouplingGeometry.anchor(a, link.endA());
|
||||
Vec3 end = CouplingGeometry.anchor(b, link.endB());
|
||||
display.connect(start, end);
|
||||
if (create && level.addFreshEntity(display)) DISPLAYS.put(key, display);
|
||||
}
|
||||
for (var key : new ArrayList<>(DISPLAYS.keySet()))
|
||||
if (key.level == level && !keys.contains(key)) discard(key);
|
||||
}
|
||||
|
||||
public static void reverse(AbstractMinecart hit, Vec3 reflected) {
|
||||
if (!(hit.level() instanceof ServerLevel level)) return;
|
||||
var data = TrainData.get(level);
|
||||
var ids = data.component(hit.getUUID());
|
||||
if (ids.size() == 1) {
|
||||
hit.setDeltaMovement(reflected.scale(1 / travelScale(hit)));
|
||||
return;
|
||||
}
|
||||
// Propagate reversal through the closed or open graph, preserving each cart's local travel
|
||||
// direction.
|
||||
var signs = directions(hit.getUUID(), data.links());
|
||||
double speed = reflected.dot(CouplingGeometry.front(hit));
|
||||
for (var id : ids) {
|
||||
var cart = cart(level, id);
|
||||
if (cart != null) {
|
||||
var v =
|
||||
CouplingGeometry.front(cart)
|
||||
.scale(speed * signs.getOrDefault(id, 1) / travelScale(cart));
|
||||
cart.setDeltaMovement(v.x, cart.getDeltaMovement().y, v.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void discard(DisplayKey key) {
|
||||
var display = DISPLAYS.remove(key);
|
||||
if (display != null) display.discard();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void stop(ServerStoppedEvent event) {
|
||||
for (var key : new ArrayList<>(DISPLAYS.keySet())) discard(key);
|
||||
PAUSED.clear();
|
||||
PLAYER_PUSHES.clear();
|
||||
CouplingGeometry.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package online.astradev.content.transport;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.vehicle.boat.AbstractBoat;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.phys.*;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.tick.EntityTickEvent;
|
||||
|
||||
import online.astradev.content.train.Trains;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class SlimeBounce {
|
||||
private static final Map<Entity, Vec3> PENDING = new WeakHashMap<>();
|
||||
private static final Map<Entity, Vec3> BOAT_MOTION = new WeakHashMap<>();
|
||||
|
||||
private SlimeBounce() {}
|
||||
|
||||
public static boolean supports(Entity entity) {
|
||||
return entity.level() instanceof ServerLevel
|
||||
&& (entity instanceof AbstractMinecart || entity instanceof AbstractBoat);
|
||||
}
|
||||
|
||||
public static void afterMove(Entity entity, Vec3 before, Vec3 requested, Vec3 incoming) {
|
||||
if (!supports(entity) || entity.noPhysics) return;
|
||||
Vec3 actual = entity.position().subtract(before);
|
||||
boolean x =
|
||||
Math.abs(requested.x - actual.x) > .00001 && touchesSlime(entity, requested.x, 0);
|
||||
boolean z =
|
||||
Math.abs(requested.z - actual.z) > .00001 && touchesSlime(entity, 0, requested.z);
|
||||
if ((x || z) && requested.horizontalDistance() > .01) {
|
||||
// Experimental rail movement splits one tick into smaller moves at rail boundaries.
|
||||
if (entity instanceof AbstractMinecart cart
|
||||
&& AbstractMinecart.useExperimentalMovement(cart.level()))
|
||||
requested = requested.horizontal().normalize().scale(incoming.horizontalDistance());
|
||||
Vec3 reflected =
|
||||
new Vec3(
|
||||
x ? -requested.x : requested.x,
|
||||
entity.getDeltaMovement().y,
|
||||
z ? -requested.z : requested.z);
|
||||
PENDING.put(entity, reflected);
|
||||
entity.setDeltaMovement(reflected);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check the actual contacted face, not nearby slime or the block beneath the vehicle. */
|
||||
private static boolean touchesSlime(Entity entity, double dx, double dz) {
|
||||
if (dx == 0 && dz == 0) return false;
|
||||
var box = entity.getBoundingBox();
|
||||
double eps = .015;
|
||||
double x0 = contactEdge(dx, box.minX, box.maxX, eps);
|
||||
double x1 = dx != 0 ? x0 : box.maxX - eps;
|
||||
double z0 = contactEdge(dz, box.minZ, box.maxZ, eps);
|
||||
double z1 = dz != 0 ? z0 : box.maxZ - eps;
|
||||
for (var pos :
|
||||
BlockPos.betweenClosed(
|
||||
BlockPos.containing(x0, box.minY + .05, z0),
|
||||
BlockPos.containing(x1, box.maxY - .05, z1)))
|
||||
if (entity.level().hasChunkAt(pos)
|
||||
&& entity.level().getBlockState(pos).is(Blocks.SLIME_BLOCK)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static double contactEdge(double movement, double min, double max, double margin) {
|
||||
if (movement > 0) return max + margin;
|
||||
if (movement < 0) return min - margin;
|
||||
return min + margin;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void afterTick(EntityTickEvent.Post event) {
|
||||
flush(event.getEntity());
|
||||
}
|
||||
|
||||
public static void flush(Entity entity) {
|
||||
var reflected = PENDING.remove(entity);
|
||||
if (reflected == null || entity.isRemoved()) return;
|
||||
if (entity instanceof AbstractMinecart cart) Trains.reverse(cart, reflected);
|
||||
else entity.setDeltaMovement(reflected);
|
||||
entity.hurtMarked = true;
|
||||
if (entity instanceof AbstractBoat)
|
||||
for (var passenger : entity.getPassengers())
|
||||
if (passenger instanceof ServerPlayer player)
|
||||
player.connection.send(new ClientboundSetEntityMotionPacket(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* A vanilla player steers boats on the client. Detect its reported contact and return a vanilla
|
||||
* impulse packet.
|
||||
*/
|
||||
public static void boatPacket(Entity entity, Vec3 before) {
|
||||
if (!(entity instanceof AbstractBoat) || !(entity.level() instanceof ServerLevel)) return;
|
||||
Vec3 motion = entity.position().subtract(before);
|
||||
Vec3 prior = BOAT_MOTION.getOrDefault(entity, motion);
|
||||
Vec3 incoming = prior.horizontalDistance() > motion.horizontalDistance() ? prior : motion;
|
||||
boolean x = Math.abs(incoming.x) > .01 && touchesSlime(entity, incoming.x, 0);
|
||||
boolean z = Math.abs(incoming.z) > .01 && touchesSlime(entity, 0, incoming.z);
|
||||
if (x || z) {
|
||||
var reflected =
|
||||
new Vec3(
|
||||
x ? -incoming.x : incoming.x,
|
||||
entity.getDeltaMovement().y,
|
||||
z ? -incoming.z : incoming.z);
|
||||
PENDING.put(entity, reflected);
|
||||
BOAT_MOTION.put(entity, reflected);
|
||||
flush(entity);
|
||||
} else BOAT_MOTION.put(entity, motion);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package online.astradev.content.weapon;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.*;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.hurtingprojectile.SmallFireball;
|
||||
import net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.WindCharge;
|
||||
import net.minecraft.world.entity.projectile.throwableitemprojectile.*;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
public final class Ammunition {
|
||||
private Ammunition() {}
|
||||
|
||||
public static boolean accepts(ItemStack stack) {
|
||||
return stack.is(Items.ENDER_PEARL)
|
||||
|| stack.is(Items.FIRE_CHARGE)
|
||||
|| stack.is(Items.ENDER_EYE)
|
||||
|| stack.getItem() instanceof EggItem
|
||||
|| stack.is(Items.SNOWBALL)
|
||||
|| stack.is(Items.WIND_CHARGE)
|
||||
|| stack.is(Items.EXPERIENCE_BOTTLE)
|
||||
|| stack.is(Items.TNT);
|
||||
}
|
||||
|
||||
public static Projectile create(Level level, LivingEntity owner, ItemStack ammo) {
|
||||
if (ammo.is(Items.ENDER_PEARL)) return new ThrownEnderpearl(level, owner, ammo);
|
||||
if (ammo.getItem() instanceof EggItem) return new ThrownEgg(level, owner, ammo);
|
||||
if (ammo.is(Items.SNOWBALL)) return new Snowball(level, owner, ammo);
|
||||
if (ammo.is(Items.EXPERIENCE_BOTTLE)) return new ThrownExperienceBottle(level, owner, ammo);
|
||||
if (ammo.is(Items.FIRE_CHARGE)) {
|
||||
var fire = new SmallFireball(level, owner, owner.getLookAngle());
|
||||
fire.setPos(owner.getX(), owner.getEyeY() - .15, owner.getZ());
|
||||
fire.setItem(ammo);
|
||||
return fire;
|
||||
}
|
||||
if (ammo.is(Items.WIND_CHARGE)) {
|
||||
var wind =
|
||||
new WindCharge(
|
||||
level,
|
||||
owner.getX(),
|
||||
owner.getEyeY() - .15,
|
||||
owner.getZ(),
|
||||
owner.getLookAngle());
|
||||
wind.setOwner(owner);
|
||||
return wind;
|
||||
}
|
||||
if (ammo.is(Items.TNT) || ammo.is(Items.ENDER_EYE))
|
||||
return new PayloadProjectile(level, owner, ammo);
|
||||
return null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void fireCharge(PlayerInteractEvent.RightClickItem event) {
|
||||
if (!(event.getLevel() instanceof ServerLevel level)
|
||||
|| !event.getItemStack().is(Items.FIRE_CHARGE)) return;
|
||||
var player = event.getEntity();
|
||||
var stack = event.getItemStack();
|
||||
if (player.getCooldowns().isOnCooldown(stack)) return;
|
||||
var fire = create(level, player, stack);
|
||||
Projectile.spawnProjectile(
|
||||
fire,
|
||||
level,
|
||||
stack,
|
||||
shot ->
|
||||
shot.shootFromRotation(
|
||||
player, player.getXRot(), player.getYRot(), 0, 1.5f, 1));
|
||||
level.playSound(
|
||||
null,
|
||||
player.blockPosition(),
|
||||
SoundEvents.FIRECHARGE_USE,
|
||||
SoundSource.PLAYERS,
|
||||
1,
|
||||
1);
|
||||
player.getCooldowns().addCooldown(stack, 10);
|
||||
player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
|
||||
stack.consume(1, player);
|
||||
event.setCanceled(true);
|
||||
event.setCancellationResult(InteractionResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package online.astradev.content.weapon;
|
||||
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.StructureTags;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.PrimedTnt;
|
||||
import net.minecraft.world.entity.projectile.EyeOfEnder;
|
||||
import net.minecraft.world.entity.projectile.throwableitemprojectile.Snowball;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/** One-tick shooting adapter; the payload itself is a vanilla entity understood by every client. */
|
||||
public final class PayloadProjectile extends Snowball {
|
||||
public static final String NO_EYE_DROP = "astracontent:no_eye_drop";
|
||||
|
||||
public PayloadProjectile(Level level, LivingEntity owner, ItemStack stack) {
|
||||
super(level, owner, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!(level() instanceof ServerLevel level)) return;
|
||||
if (getItem().is(Items.TNT)) {
|
||||
var tnt =
|
||||
new PrimedTnt(
|
||||
level,
|
||||
getX(),
|
||||
getY(),
|
||||
getZ(),
|
||||
getOwner() instanceof LivingEntity living ? living : null);
|
||||
tnt.setDeltaMovement(getDeltaMovement());
|
||||
level.addFreshEntity(tnt);
|
||||
} else {
|
||||
var target =
|
||||
level.findNearestMapStructure(
|
||||
StructureTags.EYE_OF_ENDER_LOCATED, blockPosition(), 100, false);
|
||||
if (target != null) {
|
||||
var eye = new EyeOfEnder(level, getX(), getY(), getZ());
|
||||
eye.setItem(getItem());
|
||||
if (getItem().has(DataComponents.INTANGIBLE_PROJECTILE)) eye.addTag(NO_EYE_DROP);
|
||||
eye.signalTo(Vec3.atLowerCornerOf(target));
|
||||
eye.setDeltaMovement(getDeltaMovement());
|
||||
level.addFreshEntity(eye);
|
||||
} else if (!getItem().has(DataComponents.INTANGIBLE_PROJECTILE))
|
||||
spawnAtLocation(level, getItem().copyWithCount(1));
|
||||
}
|
||||
discard();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
"required": true,
|
||||
"package": "online.astradev.content.mixin",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"mixins": ["CrossbowMixin", "RailBlockMixin", "MinecartMixin", "PayloadMixin", "ExperimentalCartMixin", "FurnaceCartMixin", "TrainCartMixin", "SlimeCollisionMixin", "BoatPacketMixin"],
|
||||
"mixins": [],
|
||||
"injectors": {"defaultRequire": 1}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
{
|
||||
"name": "Медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 20,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"item": "minecraft:honeycomb",
|
||||
"result": "astracontent:waxed_copper_rail",
|
||||
"consume": 1,
|
||||
"levelEvent": 3003
|
||||
}
|
||||
],
|
||||
"weathering": {
|
||||
"group": "astracontent:copper",
|
||||
"stage": 0,
|
||||
"includeVanillaCopper": true,
|
||||
"baseChance": 0.05688889,
|
||||
"tickDenominator": 4096,
|
||||
"neighborRadius": 4,
|
||||
"firstStageModifier": 0.75,
|
||||
"next": "astracontent:exposed_copper_rail"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"name": "Потемневшие медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:exposed_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 16,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"item": "minecraft:honeycomb",
|
||||
"result": "astracontent:waxed_exposed_copper_rail",
|
||||
"consume": 1,
|
||||
"levelEvent": 3003
|
||||
},
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3005
|
||||
}
|
||||
],
|
||||
"weathering": {
|
||||
"group": "astracontent:copper",
|
||||
"stage": 1,
|
||||
"includeVanillaCopper": true,
|
||||
"baseChance": 0.05688889,
|
||||
"tickDenominator": 4096,
|
||||
"neighborRadius": 4,
|
||||
"firstStageModifier": 0.75,
|
||||
"next": "astracontent:weathered_copper_rail"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
{
|
||||
"name": "Окисленные медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:oxidized_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 8,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"item": "minecraft:honeycomb",
|
||||
"result": "astracontent:waxed_oxidized_copper_rail",
|
||||
"consume": 1,
|
||||
"levelEvent": 3003
|
||||
},
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:weathered_copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3005
|
||||
}
|
||||
],
|
||||
"weathering": {
|
||||
"group": "astracontent:copper",
|
||||
"stage": 3,
|
||||
"includeVanillaCopper": true,
|
||||
"baseChance": 0.05688889,
|
||||
"tickDenominator": 4096,
|
||||
"neighborRadius": 4,
|
||||
"firstStageModifier": 0.75
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"name": "Вощёные: Медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:waxed_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/0/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 20,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3004
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"name": "Вощёные: Потемневшие медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:waxed_exposed_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/1/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 16,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:exposed_copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3004
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"name": "Вощёные: Окисленные медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:waxed_oxidized_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/3/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 8,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:oxidized_copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3004
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"name": "Вощёные: Состаренные медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:waxed_weathered_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 12,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:weathered_copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3004
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"name": "Состаренные медные рельсы",
|
||||
"material": "minecraft:powered_rail",
|
||||
"itemModel": "astracontent:weathered_copper_rail",
|
||||
"block": {
|
||||
"nativeBase": true,
|
||||
"base": "minecraft:powered_rail",
|
||||
"appearances": [
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/north_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "north_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/north_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/east_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "east_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/east_west_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_north",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_north",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_north_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_south",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_south",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_south_on",
|
||||
"rotation": 180
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_east",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_east",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_east_on",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "false"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_west",
|
||||
"rotation": -90
|
||||
},
|
||||
{
|
||||
"when": {
|
||||
"shape": "ascending_west",
|
||||
"powered": "true"
|
||||
},
|
||||
"model": "astracontent:rail_display/2/ascending_west_on",
|
||||
"rotation": -90
|
||||
}
|
||||
]
|
||||
},
|
||||
"behaviors": {
|
||||
"rail": {
|
||||
"maxSpeed": 12,
|
||||
"acceleration": 24
|
||||
},
|
||||
"transforms": [
|
||||
{
|
||||
"item": "minecraft:honeycomb",
|
||||
"result": "astracontent:waxed_weathered_copper_rail",
|
||||
"consume": 1,
|
||||
"levelEvent": 3003
|
||||
},
|
||||
{
|
||||
"tool": "axe",
|
||||
"result": "astracontent:exposed_copper_rail",
|
||||
"damage": 1,
|
||||
"levelEvent": 3005
|
||||
}
|
||||
],
|
||||
"weathering": {
|
||||
"group": "astracontent:copper",
|
||||
"stage": 2,
|
||||
"includeVanillaCopper": true,
|
||||
"baseChance": 0.05688889,
|
||||
"tickDenominator": 4096,
|
||||
"neighborRadius": 4,
|
||||
"firstStageModifier": 0.75,
|
||||
"next": "astracontent:oxidized_copper_rail"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"files": [
|
||||
"blocks/copper_rail.json",
|
||||
"blocks/exposed_copper_rail.json",
|
||||
"blocks/weathered_copper_rail.json",
|
||||
"blocks/oxidized_copper_rail.json",
|
||||
"blocks/waxed_copper_rail.json",
|
||||
"blocks/waxed_exposed_copper_rail.json",
|
||||
"blocks/waxed_weathered_copper_rail.json",
|
||||
"blocks/waxed_oxidized_copper_rail.json",
|
||||
"recipes/copper_rail.json"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"variants": [
|
||||
{
|
||||
"id": "astracontent:copper_rail",
|
||||
"age": 0,
|
||||
"waxed": false,
|
||||
"code": 0
|
||||
},
|
||||
{
|
||||
"id": "astracontent:exposed_copper_rail",
|
||||
"age": 1,
|
||||
"waxed": false,
|
||||
"code": 1
|
||||
},
|
||||
{
|
||||
"id": "astracontent:weathered_copper_rail",
|
||||
"age": 2,
|
||||
"waxed": false,
|
||||
"code": 2
|
||||
},
|
||||
{
|
||||
"id": "astracontent:oxidized_copper_rail",
|
||||
"age": 3,
|
||||
"waxed": false,
|
||||
"code": 3
|
||||
},
|
||||
{
|
||||
"id": "astracontent:waxed_copper_rail",
|
||||
"age": 0,
|
||||
"waxed": true,
|
||||
"code": 4
|
||||
},
|
||||
{
|
||||
"id": "astracontent:waxed_exposed_copper_rail",
|
||||
"age": 1,
|
||||
"waxed": true,
|
||||
"code": 5
|
||||
},
|
||||
{
|
||||
"id": "astracontent:waxed_weathered_copper_rail",
|
||||
"age": 2,
|
||||
"waxed": true,
|
||||
"code": 6
|
||||
},
|
||||
{
|
||||
"id": "astracontent:waxed_oxidized_copper_rail",
|
||||
"age": 3,
|
||||
"waxed": true,
|
||||
"code": 7
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"station": "crafting",
|
||||
"name": "Медные рельсы",
|
||||
"inputs": [
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
},
|
||||
{},
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:stick",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:redstone",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:copper_ingot",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"id": "astracontent:copper_rail",
|
||||
"count": 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"primaryNoDropTag": "astracontent:no_eye_drop",
|
||||
"noDropTagAliases": []
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"rules": [
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:ender_pearl"
|
||||
},
|
||||
"kind": "ENDER_PEARL",
|
||||
"crossbow": true
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:fire_charge"
|
||||
},
|
||||
"kind": "SMALL_FIREBALL",
|
||||
"crossbow": true,
|
||||
"parameters": {
|
||||
"eyeOffset": -0.15
|
||||
},
|
||||
"rightClick": {
|
||||
"velocity": 1.5,
|
||||
"inaccuracy": 1,
|
||||
"cooldownTicks": 10,
|
||||
"consume": 1,
|
||||
"sound": {
|
||||
"id": "minecraft:item.firecharge.use",
|
||||
"source": "players",
|
||||
"volume": 1,
|
||||
"pitch": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:ender_eye"
|
||||
},
|
||||
"kind": "ENDER_EYE_PAYLOAD",
|
||||
"crossbow": true,
|
||||
"parameters": {
|
||||
"structureTag": "minecraft:eye_of_ender_located",
|
||||
"searchRadius": 100,
|
||||
"skipKnownStructures": false,
|
||||
"dropWhenNoTarget": true,
|
||||
"intangiblePreventsDrop": true,
|
||||
"velocityScale": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"tag": "minecraft:eggs"
|
||||
},
|
||||
"kind": "EGG",
|
||||
"crossbow": true
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:snowball"
|
||||
},
|
||||
"kind": "SNOWBALL",
|
||||
"crossbow": true
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:wind_charge"
|
||||
},
|
||||
"kind": "WIND_CHARGE",
|
||||
"crossbow": true,
|
||||
"parameters": {
|
||||
"eyeOffset": -0.15
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:experience_bottle"
|
||||
},
|
||||
"kind": "EXPERIENCE_BOTTLE",
|
||||
"crossbow": true
|
||||
},
|
||||
{
|
||||
"selector": {
|
||||
"item": "minecraft:tnt"
|
||||
},
|
||||
"kind": "TNT_PAYLOAD",
|
||||
"crossbow": true,
|
||||
"parameters": {
|
||||
"fuseTicks": 80,
|
||||
"velocityScale": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"description": "Правила дополнительных боеприпасов для арбалета и использования предметов в воздухе. Изменения применяются сразу после сохранения; уже выпущенные ванильные сущности продолжают жить самостоятельно.",
|
||||
"fields": [
|
||||
{
|
||||
"path": "rules",
|
||||
"label": "Правила снарядов",
|
||||
"type": "object",
|
||||
"default": [],
|
||||
"group": "Боеприпасы",
|
||||
"description": "Упорядоченный массив правил. Первое совпавшее правило определяет тип снаряда.",
|
||||
"editor": {
|
||||
"kind": "projectile-rules"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"cartSpeedKey": "AstraContentSpeed",
|
||||
"frontXKey": "AstraTrainFrontX",
|
||||
"frontZKey": "AstraTrainFrontZ",
|
||||
"trainStorageId": "astracontent:trains",
|
||||
"legacyBlocks": [
|
||||
{
|
||||
"storage": "astracontent:copper_rails",
|
||||
"field": "rails",
|
||||
"base": "minecraft:powered_rail",
|
||||
"itemTag": "astracontent:rail",
|
||||
"variants": {
|
||||
"0": "astracontent:copper_rail",
|
||||
"1": "astracontent:exposed_copper_rail",
|
||||
"2": "astracontent:weathered_copper_rail",
|
||||
"3": "astracontent:oxidized_copper_rail",
|
||||
"4": "astracontent:waxed_copper_rail",
|
||||
"5": "astracontent:waxed_exposed_copper_rail",
|
||||
"6": "astracontent:waxed_weathered_copper_rail",
|
||||
"7": "astracontent:waxed_oxidized_copper_rail"
|
||||
}
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"root": "astracontent",
|
||||
"branch": "give",
|
||||
"count": 64,
|
||||
"items": {
|
||||
"copper_rail": "astracontent:copper_rail",
|
||||
"exposed_copper_rail": "astracontent:exposed_copper_rail",
|
||||
"weathered_copper_rail": "astracontent:weathered_copper_rail",
|
||||
"oxidized_copper_rail": "astracontent:oxidized_copper_rail",
|
||||
"waxed_copper_rail": "astracontent:waxed_copper_rail",
|
||||
"waxed_exposed_copper_rail": "astracontent:waxed_exposed_copper_rail",
|
||||
"waxed_weathered_copper_rail": "astracontent:waxed_weathered_copper_rail",
|
||||
"waxed_oxidized_copper_rail": "astracontent:waxed_oxidized_copper_rail"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"rail": {
|
||||
"enabled": true,
|
||||
"signalUnits": 2,
|
||||
"minimumSignalSpeed": 2,
|
||||
"signalReach": 8,
|
||||
"maximumStoredSpeed": 120,
|
||||
"waterMultiplier": 0.5,
|
||||
"safeLookAhead": 2,
|
||||
"cornerSpeed": 0.4
|
||||
},
|
||||
"coupling": {
|
||||
"enabled": true,
|
||||
"linkItems": [
|
||||
"minecraft:iron_chain",
|
||||
"minecraft:copper_chain",
|
||||
"minecraft:exposed_copper_chain",
|
||||
"minecraft:weathered_copper_chain",
|
||||
"minecraft:oxidized_copper_chain",
|
||||
"minecraft:waxed_copper_chain",
|
||||
"minecraft:waxed_exposed_copper_chain",
|
||||
"minecraft:waxed_weathered_copper_chain",
|
||||
"minecraft:waxed_oxidized_copper_chain"
|
||||
],
|
||||
"unlinkTools": [
|
||||
"#minecraft:pickaxes"
|
||||
],
|
||||
"requireSneaking": true,
|
||||
"minimumDistance": 1,
|
||||
"maximumDistance": 3.5,
|
||||
"maximumVerticalDistance": 1.5,
|
||||
"alignment": 0.9,
|
||||
"breakDistance": 6,
|
||||
"springStrength": 0.22,
|
||||
"maximumCorrection": 0.18,
|
||||
"hitEndDistance": 0.32,
|
||||
"hitEndRatio": 1.3,
|
||||
"anchorHeight": 0.35,
|
||||
"anchorOffset": 0.48,
|
||||
"unlinkDamage": 1,
|
||||
"itemCost": 1,
|
||||
"fallbackItem": "minecraft:iron_chain",
|
||||
"messages": {
|
||||
"invalidEnd": "Цепь крепится только к переднему или заднему торцу.",
|
||||
"noLink": "На этом торце нет цепи.",
|
||||
"occupied": "Этот торец уже сцеплен.",
|
||||
"linked": "Вагонетки сцеплены.",
|
||||
"noCandidate": "У этого торца нет подходящей свободной вагонетки."
|
||||
}
|
||||
},
|
||||
"bounce": {
|
||||
"enabled": true,
|
||||
"entityKinds": [
|
||||
"boat",
|
||||
"minecart"
|
||||
],
|
||||
"blocks": [
|
||||
"minecraft:slime_block"
|
||||
],
|
||||
"minimumSpeed": 0.01,
|
||||
"collisionEpsilon": 0.00001,
|
||||
"surfaceMargin": 0.015,
|
||||
"verticalInset": 0.05,
|
||||
"restitution": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
{
|
||||
"description": "Декларативные параметры регулирования скорости, сцепления и отскока. Изменения действуют сразу; сохранённые сцепки не удаляются.",
|
||||
"fields": [
|
||||
{
|
||||
"path": "rail.enabled",
|
||||
"label": "Включено",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"group": "Регулирование скорости"
|
||||
},
|
||||
{
|
||||
"path": "rail.signalUnits",
|
||||
"label": "Скорость на единицу сигнала, блоков/с",
|
||||
"type": "number",
|
||||
"default": 2,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0,
|
||||
"max": 120
|
||||
},
|
||||
{
|
||||
"path": "rail.minimumSignalSpeed",
|
||||
"label": "Минимальная регулируемая скорость",
|
||||
"type": "number",
|
||||
"default": 2,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0,
|
||||
"max": 120
|
||||
},
|
||||
{
|
||||
"path": "rail.signalReach",
|
||||
"label": "Дальность распространения сигнала",
|
||||
"type": "integer",
|
||||
"default": 8,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0,
|
||||
"max": 64
|
||||
},
|
||||
{
|
||||
"path": "rail.maximumStoredSpeed",
|
||||
"label": "Максимальная сохраняемая скорость",
|
||||
"type": "number",
|
||||
"default": 120,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0.1,
|
||||
"max": 120
|
||||
},
|
||||
{
|
||||
"path": "rail.waterMultiplier",
|
||||
"label": "Множитель скорости в воде",
|
||||
"type": "number",
|
||||
"default": 0.5,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0,
|
||||
"max": 1
|
||||
},
|
||||
{
|
||||
"path": "rail.safeLookAhead",
|
||||
"label": "Проверка безопасности впереди, блоков",
|
||||
"type": "integer",
|
||||
"default": 2,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0,
|
||||
"max": 16
|
||||
},
|
||||
{
|
||||
"path": "rail.cornerSpeed",
|
||||
"label": "Скорость на поворотах, блоков/тик",
|
||||
"type": "number",
|
||||
"default": 0.4,
|
||||
"group": "Регулирование скорости",
|
||||
"min": 0.01,
|
||||
"max": 6
|
||||
},
|
||||
{
|
||||
"path": "coupling.enabled",
|
||||
"label": "Включено",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.linkItems",
|
||||
"label": "Предметы сцепления",
|
||||
"type": "strings",
|
||||
"default": [
|
||||
"minecraft:iron_chain",
|
||||
"minecraft:copper_chain",
|
||||
"minecraft:exposed_copper_chain",
|
||||
"minecraft:weathered_copper_chain",
|
||||
"minecraft:oxidized_copper_chain",
|
||||
"minecraft:waxed_copper_chain",
|
||||
"minecraft:waxed_exposed_copper_chain",
|
||||
"minecraft:waxed_weathered_copper_chain",
|
||||
"minecraft:waxed_oxidized_copper_chain"
|
||||
],
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.unlinkTools",
|
||||
"label": "Инструменты расцепления",
|
||||
"type": "strings",
|
||||
"default": [
|
||||
"#minecraft:pickaxes"
|
||||
],
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.requireSneaking",
|
||||
"label": "Требуется приседание",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.minimumDistance",
|
||||
"label": "Минимальная дистанция",
|
||||
"type": "number",
|
||||
"default": 1,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0.1,
|
||||
"max": 32
|
||||
},
|
||||
{
|
||||
"path": "coupling.maximumDistance",
|
||||
"label": "Максимальная дистанция",
|
||||
"type": "number",
|
||||
"default": 3.5,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0.1,
|
||||
"max": 32
|
||||
},
|
||||
{
|
||||
"path": "coupling.maximumVerticalDistance",
|
||||
"label": "Максимальный перепад высот",
|
||||
"type": "number",
|
||||
"default": 1.5,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 32
|
||||
},
|
||||
{
|
||||
"path": "coupling.alignment",
|
||||
"label": "Точность выравнивания",
|
||||
"type": "number",
|
||||
"default": 0.9,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 1
|
||||
},
|
||||
{
|
||||
"path": "coupling.breakDistance",
|
||||
"label": "Дистанция разрыва сцепки",
|
||||
"type": "number",
|
||||
"default": 6,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0.1,
|
||||
"max": 64
|
||||
},
|
||||
{
|
||||
"path": "coupling.springStrength",
|
||||
"label": "Сила натяжения",
|
||||
"type": "number",
|
||||
"default": 0.22,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 4
|
||||
},
|
||||
{
|
||||
"path": "coupling.maximumCorrection",
|
||||
"label": "Максимальная коррекция скорости",
|
||||
"type": "number",
|
||||
"default": 0.18,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 4
|
||||
},
|
||||
{
|
||||
"path": "coupling.hitEndDistance",
|
||||
"label": "Расстояние от центра до торца",
|
||||
"type": "number",
|
||||
"default": 0.32,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 2
|
||||
},
|
||||
{
|
||||
"path": "coupling.hitEndRatio",
|
||||
"label": "Отношение продольного попадания к поперечному",
|
||||
"type": "number",
|
||||
"default": 1.3,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 10
|
||||
},
|
||||
{
|
||||
"path": "coupling.anchorHeight",
|
||||
"label": "Высота крепления",
|
||||
"type": "number",
|
||||
"default": 0.35,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": -4,
|
||||
"max": 4
|
||||
},
|
||||
{
|
||||
"path": "coupling.anchorOffset",
|
||||
"label": "Смещение крепления от центра",
|
||||
"type": "number",
|
||||
"default": 0.48,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 4
|
||||
},
|
||||
{
|
||||
"path": "coupling.unlinkDamage",
|
||||
"label": "Расход прочности инструмента",
|
||||
"type": "integer",
|
||||
"default": 1,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 10000
|
||||
},
|
||||
{
|
||||
"path": "coupling.itemCost",
|
||||
"label": "Расход предмета (0 или 1)",
|
||||
"type": "integer",
|
||||
"default": 1,
|
||||
"group": "Сцепление вагонеток",
|
||||
"min": 0,
|
||||
"max": 1
|
||||
},
|
||||
{
|
||||
"path": "coupling.fallbackItem",
|
||||
"label": "Предмет возврата при неизвестном старом ID",
|
||||
"type": "string",
|
||||
"default": "minecraft:iron_chain",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.messages.invalidEnd",
|
||||
"label": "Сообщение: неверный торец",
|
||||
"type": "string",
|
||||
"default": "Цепь крепится только к переднему или заднему торцу.",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.messages.noLink",
|
||||
"label": "Сообщение: сцепка отсутствует",
|
||||
"type": "string",
|
||||
"default": "На этом торце нет цепи.",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.messages.occupied",
|
||||
"label": "Сообщение: торец занят",
|
||||
"type": "string",
|
||||
"default": "Этот торец уже сцеплен.",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.messages.linked",
|
||||
"label": "Сообщение: сцеплено",
|
||||
"type": "string",
|
||||
"default": "Вагонетки сцеплены.",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "coupling.messages.noCandidate",
|
||||
"label": "Сообщение: нет кандидата",
|
||||
"type": "string",
|
||||
"default": "У этого торца нет подходящей свободной вагонетки.",
|
||||
"group": "Сцепление вагонеток"
|
||||
},
|
||||
{
|
||||
"path": "bounce.enabled",
|
||||
"label": "Включено",
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"group": "Отскок транспорта"
|
||||
},
|
||||
{
|
||||
"path": "bounce.entityKinds",
|
||||
"label": "Типы транспорта (boat, minecart)",
|
||||
"type": "strings",
|
||||
"default": [
|
||||
"boat",
|
||||
"minecart"
|
||||
],
|
||||
"group": "Отскок транспорта"
|
||||
},
|
||||
{
|
||||
"path": "bounce.blocks",
|
||||
"label": "Поверхности отскока",
|
||||
"type": "strings",
|
||||
"default": [
|
||||
"minecraft:slime_block"
|
||||
],
|
||||
"group": "Отскок транспорта"
|
||||
},
|
||||
{
|
||||
"path": "bounce.minimumSpeed",
|
||||
"label": "Минимальная скорость отскока",
|
||||
"type": "number",
|
||||
"default": 0.01,
|
||||
"group": "Отскок транспорта",
|
||||
"min": 0,
|
||||
"max": 4
|
||||
},
|
||||
{
|
||||
"path": "bounce.collisionEpsilon",
|
||||
"label": "Допуск определения столкновения",
|
||||
"type": "number",
|
||||
"default": 0.00001,
|
||||
"group": "Отскок транспорта",
|
||||
"min": 0,
|
||||
"max": 0.1
|
||||
},
|
||||
{
|
||||
"path": "bounce.surfaceMargin",
|
||||
"label": "Допуск контакта поверхности",
|
||||
"type": "number",
|
||||
"default": 0.015,
|
||||
"group": "Отскок транспорта",
|
||||
"min": 0,
|
||||
"max": 0.5
|
||||
},
|
||||
{
|
||||
"path": "bounce.verticalInset",
|
||||
"label": "Отступ проверки по высоте",
|
||||
"type": "number",
|
||||
"default": 0.05,
|
||||
"group": "Отскок транспорта",
|
||||
"min": 0,
|
||||
"max": 0.5
|
||||
},
|
||||
{
|
||||
"path": "bounce.restitution",
|
||||
"label": "Коэффициент отскока",
|
||||
"type": "number",
|
||||
"default": 1,
|
||||
"group": "Отскок транспорта",
|
||||
"min": 0,
|
||||
"max": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -69,21 +69,7 @@ class RailDisplayTransformTest {
|
||||
.rotateY(
|
||||
(float)
|
||||
-Math.toRadians(
|
||||
new CopperRailBlock(
|
||||
new RailKind(
|
||||
age,
|
||||
false))
|
||||
.appearance(
|
||||
java.util.Map
|
||||
.of(
|
||||
"shape",
|
||||
shape
|
||||
.getSerializedName(),
|
||||
"powered",
|
||||
Boolean
|
||||
.toString(
|
||||
powered)))
|
||||
.rotation()))
|
||||
rotation(new RailKind(age, false), shape.getSerializedName(), powered)))
|
||||
.add(.5f, .5f, .5f);
|
||||
float nativeHeight =
|
||||
1f / 16
|
||||
@@ -116,4 +102,15 @@ class RailDisplayTransformTest {
|
||||
private static Vector3f vector(JsonArray a) {
|
||||
return new Vector3f(a.get(0).getAsFloat(), a.get(1).getAsFloat(), a.get(2).getAsFloat());
|
||||
}
|
||||
|
||||
private static float rotation(RailKind kind, String shape, boolean powered) throws Exception {
|
||||
try (var input = RailDisplayTransformTest.class.getResourceAsStream("/content/astracontent/blocks/" + kind.id().getPath() + ".json")) {
|
||||
assertNotNull(input);
|
||||
var doc = JsonParser.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
return doc.getAsJsonObject("block").getAsJsonArray("appearances").asList().stream().map(value -> value.getAsJsonObject())
|
||||
.filter(variant -> variant.getAsJsonObject("when").get("shape").getAsString().equals(shape)
|
||||
&& variant.getAsJsonObject("when").get("powered").getAsBoolean() == powered)
|
||||
.findFirst().orElseThrow().get("rotation").getAsFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,30 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
class RailSpeedTest {
|
||||
@Test
|
||||
void fixedCopperSpeedsAndWaxDoNotChangeLimit() {
|
||||
void defaultsPreserveCopperSpeedsAndWaxDoesNotChangeLimit() throws Exception {
|
||||
for (int age = 0; age < 4; age++) {
|
||||
assertEquals(20 - 4 * age, new RailKind(age, false).speed());
|
||||
assertEquals(20 - 4 * age, new RailKind(age, true).speed());
|
||||
assertEquals(20 - 4 * age, settings(new RailKind(age, false)).get("maxSpeed").getAsDouble());
|
||||
assertEquals(20 - 4 * age, settings(new RailKind(age, true)).get("maxSpeed").getAsDouble());
|
||||
assertEquals(24, settings(new RailKind(age, false)).get("acceleration").getAsDouble());
|
||||
assertEquals(new RailKind(age, true), RailKind.decode(new RailKind(age, true).code()));
|
||||
}
|
||||
}
|
||||
|
||||
private static com.google.gson.JsonObject settings(RailKind kind) throws Exception {
|
||||
try (var input = RailSpeedTest.class.getResourceAsStream("/content/astracontent/blocks/" + kind.id().getPath() + ".json")) {
|
||||
assertNotNull(input);
|
||||
return com.google.gson.JsonParser.parseReader(new java.io.InputStreamReader(input, java.nio.charset.StandardCharsets.UTF_8))
|
||||
.getAsJsonObject().getAsJsonObject("behaviors").getAsJsonObject("rail");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void analogInputIsTwoBlocksPerSecondPerLevel() {
|
||||
for (int i = 0; i <= 15; i++) assertEquals(i * 2, RailSpeed.signalSpeed(i));
|
||||
assertEquals(0, RailSpeed.signalSpeed(-1));
|
||||
assertEquals(30, RailSpeed.signalSpeed(99));
|
||||
void analogPolicyDeclaresTwoBlocksPerSecondPerLevel() throws Exception {
|
||||
try (var input = getClass().getResourceAsStream("/content/policies/transport-defaults.json")) {
|
||||
var rail = com.google.gson.JsonParser.parseReader(new java.io.InputStreamReader(input))
|
||||
.getAsJsonObject().getAsJsonObject("rail");
|
||||
assertEquals(2, rail.get("signalUnits").getAsDouble());
|
||||
assertEquals(8, rail.get("signalReach").getAsInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package online.astradev.content.rail;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/** Legacy eight-value world/item identity adapter. Current behavior lives in editable documents. */
|
||||
public record RailKind(int age, boolean waxed) {
|
||||
private record Legacy(int code, Identifier id, RailKind kind) {}
|
||||
private static final List<Legacy> LEGACY = load();
|
||||
|
||||
public RailKind {
|
||||
if (age < 0 || age > 3) throw new IllegalArgumentException("Legacy oxidation: " + age);
|
||||
}
|
||||
|
||||
private static List<Legacy> load() {
|
||||
try (var input = RailKind.class.getResourceAsStream("/content/astracontent/legacy-rails.json")) {
|
||||
if (input == null) throw new IllegalStateException("Missing legacy rail identity map");
|
||||
var json = JsonParser.parseReader(new InputStreamReader(input, StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
return json.getAsJsonArray("variants").asList().stream().map(value -> {
|
||||
var entry = value.getAsJsonObject();
|
||||
return new Legacy(entry.get("code").getAsInt(), Identifier.parse(entry.get("id").getAsString()),
|
||||
new RailKind(entry.get("age").getAsInt(), entry.get("waxed").getAsBoolean()));
|
||||
}).toList();
|
||||
} catch (java.io.IOException failure) {
|
||||
throw new IllegalStateException("Cannot read legacy rail identity map", failure);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<RailKind> variants() { return LEGACY.stream().map(Legacy::kind).toList(); }
|
||||
|
||||
public int code() {
|
||||
return LEGACY.stream().filter(entry -> entry.kind().equals(this)).findFirst().orElseThrow().code();
|
||||
}
|
||||
|
||||
public static RailKind decode(int code) {
|
||||
return LEGACY.stream().filter(entry -> entry.code() == code).findFirst().orElseThrow().kind();
|
||||
}
|
||||
|
||||
public Identifier id() {
|
||||
return LEGACY.stream().filter(entry -> entry.kind().equals(this)).findFirst().orElseThrow().id();
|
||||
}
|
||||
|
||||
public static RailKind fromId(Identifier id) {
|
||||
return LEGACY.stream().filter(entry -> entry.id().equals(id)).map(Legacy::kind).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package online.astradev.content.rail;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import online.astradev.plus.api.AstraPlusApi;
|
||||
/** Test fixture only: assertions and placement through the same public authoring API. */
|
||||
public final class Rails {
|
||||
public static RailKind find(ServerLevel level, BlockPos pos) {
|
||||
return RailKind.fromId(Identifier.parse(AstraPlusApi.world(level).block(AstraPlusApi.position(pos))));
|
||||
}
|
||||
public static void put(ServerLevel level, BlockPos pos, RailKind kind) {
|
||||
if (!AstraPlusApi.world(level).replaceBlock(AstraPlusApi.position(pos), kind.id().toString()))
|
||||
throw new IllegalStateException("Cannot place test rail");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user