Rocket landing pad block. Added comments. Adjusted rocket values

This commit is contained in:
XevianLight
2026-01-26 21:31:03 -07:00
parent 5e512cae1c
commit f3bd3f891a
59 changed files with 392 additions and 85 deletions

View File

@@ -0,0 +1,77 @@
package net.xevianlight.aphelion.block.custom;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.xevianlight.aphelion.util.ModTags;
import org.jetbrains.annotations.NotNull;
public class LaunchPad extends Block {
public static final BooleanProperty NORTH = BlockStateProperties.NORTH;
public static final BooleanProperty EAST = BlockStateProperties.EAST;
public static final BooleanProperty SOUTH = BlockStateProperties.SOUTH;
public static final BooleanProperty WEST = BlockStateProperties.WEST;
public LaunchPad(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(NORTH, false)
.setValue(EAST, false)
.setValue(SOUTH, false)
.setValue(WEST, false));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST);
}
private static boolean isPad(BlockState st) {
return st.is(ModTags.Blocks.LAUNCH_PAD); // <- make a tag, recommended
}
private BlockState withConnections(LevelAccessor level, BlockPos pos, BlockState state) {
return state
.setValue(NORTH, isPad(level.getBlockState(pos.north())))
.setValue(EAST, isPad(level.getBlockState(pos.east())))
.setValue(SOUTH, isPad(level.getBlockState(pos.south())))
.setValue(WEST, isPad(level.getBlockState(pos.west())));
}
public static Properties getProperties() {
return Properties
.of()
.sound(SoundType.STONE)
.destroyTime(2f)
.explosionResistance(10f)
.requiresCorrectToolForDrops();
}
public static Item.Properties getItemProperties() {
return new Item.Properties();
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return withConnections(ctx.getLevel(), ctx.getClickedPos(), this.defaultBlockState());
}
@Override
public @NotNull BlockState updateShape(@NotNull BlockState state, Direction dir, @NotNull BlockState neighborState,
@NotNull LevelAccessor level, @NotNull BlockPos pos, @NotNull BlockPos neighborPos) {
if (dir.getAxis().isHorizontal()) {
return withConnections(level, pos, state);
}
return state;
}
}

View File

@@ -1,15 +1,15 @@
package net.xevianlight.aphelion.client;
import net.xevianlight.aphelion.network.packet.PartitionData;
import net.xevianlight.aphelion.network.packet.PartitionPayload;
import java.util.Optional;
public final class PartitionClientState {
private static volatile PartitionData last = null;
private static volatile PartitionPayload last = null;
public static void set(PartitionData d) { last = d; }
public static void set(PartitionPayload d) { last = d; }
public static Optional<PartitionData> get() {
public static Optional<PartitionPayload> get() {
return Optional.ofNullable(last);
}

View File

@@ -12,6 +12,7 @@ public class ModBlocks {
public static final DeferredBlock<Block> TEST_BLOCK = BLOCKS.register("test_block", () -> new TestBlock(TestBlock.getProperties()));
public static final DeferredBlock<Block> BLOCK_STEEL = BLOCKS.register("block_steel", () -> new BlockSteel(BlockSteel.getProperties()));
public static final DeferredBlock<Block> LAUNCH_PAD = BLOCKS.register("launch_pad", () -> new LaunchPad(LaunchPad.getProperties()));
public static final DeferredBlock<Block> DIMENSION_CHANGER = BLOCKS.register("dimension_changer", () -> new DimensionChangerBlock(DimensionChangerBlock.getProperties()));
public static final DeferredBlock<Block> ELECTRIC_ARC_FURNACE = BLOCKS.register("electric_arc_furnace", () -> new ElectricArcFurnace(ElectricArcFurnace.getProperties()));
public static final DeferredBlock<Block> ARC_FURNACE_CASING_BLOCK = BLOCKS.register("arc_furnace_casing", () -> new ArcFurnaceCasingBlock(ArcFurnaceCasingBlock.getProperties()));

View File

@@ -41,5 +41,6 @@ public class ModCreativeTabs {
output.accept(ModItems.BLOCK_STEEL);
output.accept(ModItems.ARC_FURNACE_CASING_BLOCK);
output.accept(ModItems.VACUUM_ARC_FURNACE_CONTROLLER);
output.accept(ModItems.LAUNCH_PAD);
}).build());
}

View File

@@ -35,5 +35,6 @@ public static final DeferredItem<Item> MUSIC_DISC_BIT_SHIFT = ITEMS.register("mu
public static final DeferredItem<BlockItem> BLOCK_STEEL = ITEMS.register("block_steel", () -> new BlockItem(ModBlocks.BLOCK_STEEL.get(), BlockSteel.getItemProperties()));
public static final DeferredItem<BlockItem> ARC_FURNACE_CASING_BLOCK = ITEMS.register("arc_furnace_casing", () -> new BlockItem(ModBlocks.ARC_FURNACE_CASING_BLOCK.get(), ArcFurnaceCasingBlock.getItemProperties()));
public static final DeferredItem<BlockItem> VACUUM_ARC_FURNACE_CONTROLLER = ITEMS.register("vacuum_arc_furnace_controller", () -> new BlockItem(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER.get(), VacuumArcFurnaceController.getItemProperties()));
public static final DeferredItem<BlockItem> LAUNCH_PAD = ITEMS.register("launch_pad", () -> new BlockItem(ModBlocks.LAUNCH_PAD.get(), LaunchPad.getItemProperties()));
// public static final DeferredItem<BlockItem> VAF_MULTIBLOCK_DUMMY_BLOCK = ITEMS.register("vaf_multiblock_dummy_block", () -> new BlockItem(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), VAFMultiblockDummyBlock.getItemProperties()));
}

View File

@@ -23,6 +23,8 @@ public class ModSounds {
public static final Supplier<SoundEvent> BIT_SHIFT = registerSoundEvent("bit_shift");
public static final ResourceKey<JukeboxSong> BIT_SHIFT_KEY = createSong("bit_shift");
public static final Supplier<SoundEvent> ROCKET_ENGINE = registerSoundEvent("rocket_engine");
private static Supplier<SoundEvent> registerSoundEvent(String name) {
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, name);
return SOUND_EVENTS.register(name, () -> SoundEvent.createVariableRangeEvent(id));

View File

@@ -24,6 +24,7 @@ public class ModBlockLootTableProvider extends BlockLootSubProvider {
dropSelf(ModBlocks.ARC_FURNACE_CASING_BLOCK.get());
dropSelf(ModBlocks.VACUUM_ARC_FURNACE_CONTROLLER.get());
dropOther(ModBlocks.VAF_MULTIBLOCK_DUMMY_BLOCK.get(), ItemStack.EMPTY.getItem());
dropSelf(ModBlocks.LAUNCH_PAD.get());
}
@Override

View File

@@ -27,6 +27,10 @@ public class ModBlockStateProvider extends BlockStateProvider {
blockWithItem(ModBlocks.BLOCK_STEEL);
blockWithItem(ModBlocks.DIMENSION_CHANGER);
// this is already defined ourselves
// blockItem(ModBlocks.LAUNCH_PAD);
blockItem(ModBlocks.ARC_FURNACE_CASING_BLOCK);
}

View File

@@ -40,5 +40,9 @@ public class ModBlockTagProvider extends BlockTagsProvider {
tag(ModTags.Blocks.STORAGE_BLOCKS)
.add(ModBlocks.BLOCK_STEEL.get());
tag(ModTags.Blocks.LAUNCH_PAD)
.add(ModBlocks.LAUNCH_PAD.get());
}
}

View File

@@ -0,0 +1,42 @@
package net.xevianlight.aphelion.entites.vehicles;
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.sounds.SoundSource;
import net.xevianlight.aphelion.core.init.ModSounds;
public class RocketEngineSound extends AbstractTickableSoundInstance {
private final RocketEntity rocket;
public RocketEngineSound (RocketEntity rocket) {
super(ModSounds.ROCKET_ENGINE.get(), SoundSource.AMBIENT, SoundInstance.createUnseededRandom());
this.rocket = rocket;
this.looping = true;
this.delay = 0;
this.volume = 1;
this.pitch = 1.0f;
this.x = rocket.getX();
this.y = rocket.getY();
this.z = rocket.getZ();
}
@Override
public void tick() {
if (rocket.isRemoved() || rocket.getPhase() != RocketEntity.FlightPhase.ASCEND) {
this.stop();
return;
}
// follow entity
this.x = rocket.getX();
this.y = rocket.getY();
this.z = rocket.getZ();
}
public void killSound() {
stop();
}
}

View File

@@ -1,5 +1,6 @@
package net.xevianlight.aphelion.entites.vehicles;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
@@ -10,7 +11,6 @@ import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ColumnPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
@@ -29,14 +29,12 @@ import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.entity.IEntityWithComplexSpawn;
import net.neoforged.neoforge.fluids.FluidType;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.core.KeyVariables;
import net.xevianlight.aphelion.core.init.ModEntities;
import net.xevianlight.aphelion.util.RocketStructure;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpawn {
@@ -53,12 +51,11 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
private double landingPosX;
private double landingPosZ;
private static final double TELEPORT_Y = 600.0;
private static final double ASCEND_ACCEL = 0.05;
private static final double DESCEND_SPEED = 2;
private static final double TELEPORT_Y = 1000.0;
private static final double ASCEND_ACCEL = 0.0125;
private static final double DESCEND_SPEED = 1;
private double yVel = 0.0;
private boolean jumpWasDown = false;
private static final EntityDataAccessor<Byte> FLIGHT_PHASE =
SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.BYTE);
@@ -101,18 +98,6 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
setPhase(FlightPhase.PREPARE);
}
public Player getFirstPlayerPassenger() {
if (!this.getPassengers().isEmpty()) {
for (int i = 0; i < this.getPassengers().size(); i++) {
if (this.getPassengers().get(i) instanceof Player player) {
return player;
}
}
}
return null;
}
@Override
public void tick() {
super.tick();
@@ -146,11 +131,6 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
}
private void tickPrepare() {
// if (targetDim == this.level().dimension()) {
// setPhase(FlightPhase.IDLE);
// Aphelion.LOGGER.info("Target dimension matches current dimension");
// return;
// }
setPhase(FlightPhase.ASCEND);
}
@@ -189,10 +169,6 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
landingPosZ = getZ();
}
// Compute landing Y in destination
int hx = (int) Math.floor(landingPosX);
int hz = (int) Math.floor(landingPosZ);
double arrivalY = TELEPORT_Y;
var passengers = List.copyOf(getPassengers());
@@ -326,26 +302,24 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
}
}
private RocketEngineSound ascendLoopSound;
private void handleClientFlightPhaseChange(FlightPhase phase) {
switch (phase) {
case IDLE -> {
// var x = 0;
}
case PREPARE -> {
// var x = 1;
case IDLE, PREPARE, TRANSIT, DESCEND, LANDED -> {
Aphelion.LOGGER.info("Rocket state updated to {}", phase);
if (ascendLoopSound != null) {
ascendLoopSound.killSound();
ascendLoopSound = null;
}
}
case ASCEND -> {
// var x = 2;
}
case TRANSIT -> {
// var x = 3;
}
case DESCEND -> {
// var x = 4;
}
case LANDED -> {
// var x = 5;
if (ascendLoopSound == null || ascendLoopSound.isStopped()) {
ascendLoopSound = new RocketEngineSound(this);
Minecraft.getInstance().getSoundManager().play(ascendLoopSound);
}
}
}
}
@@ -382,6 +356,7 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
landingPosX = tag.getDouble("LandingX");
landingPosZ = tag.getDouble("LandingZ");
yVel = tag.getDouble("yVelocity");
if (tag.contains("FlightPhase", Tag.TAG_BYTE)) {
setPhase(FlightPhase.values()[tag.getByte("FlightPhase")]);
@@ -399,9 +374,10 @@ public class RocketEntity extends VehicleEntity implements IEntityWithComplexSpa
tag.putDouble("LandingX", landingPosX);
tag.putDouble("LandingZ", landingPosZ);
tag.putDouble("yVelocity", yVel);
}
public BlockPos getTargetPos() {
public @Nullable BlockPos getTargetPos() {
return targetPos;
}

View File

@@ -5,19 +5,17 @@ import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.handlers.ClientPayloadHandler;
import net.neoforged.neoforge.network.registration.HandlerThread;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.block.dummy.entity.BaseMultiblockDummyBlockEntity;
import net.xevianlight.aphelion.block.dummy.entity.VAFMultiblockDummyBlockEntity;
import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity;
import net.xevianlight.aphelion.block.entity.custom.TestBlockEntity;
import net.xevianlight.aphelion.block.entity.custom.VacuumArcFurnaceControllerEntity;
import net.xevianlight.aphelion.core.init.ModBlockEntities;
import net.xevianlight.aphelion.network.RocketPayloadHandlers;
import net.xevianlight.aphelion.network.ServerPayloadHandler;
import net.xevianlight.aphelion.network.packet.PartitionData;
import net.xevianlight.aphelion.network.PartitionPayloadHandler;
import net.xevianlight.aphelion.network.packet.PartitionPayload;
import net.xevianlight.aphelion.network.packet.RocketLaunchPayload;
@EventBusSubscriber(modid = Aphelion.MOD_ID)
@@ -40,9 +38,9 @@ public class ModBusEvents {
.executesOn(HandlerThread.MAIN);
registrar.playToClient(
PartitionData.TYPE,
PartitionData.STREAM_CODEC,
ServerPayloadHandler::handleDataOnMain
PartitionPayload.TYPE,
PartitionPayload.STREAM_CODEC,
PartitionPayloadHandler::handleDataOnMain
);
registrar.playToServer(

View File

@@ -22,6 +22,8 @@ public final class KeyNetwork {
// consumeClick makes it fire once per press, not every tick held
if (AphelionClient.ROCKET_LAUNCH_KEY.consumeClick() && mc.player.getVehicle() instanceof RocketEntity rocket) {
// Send a packet to the server telling it to try launching the rocket matching this id. The packet only contains the rocketId as an integer.
PacketDistributor.sendToServer(new RocketLaunchPayload(rocket.getId()));
}
}

View File

@@ -3,12 +3,13 @@ package net.xevianlight.aphelion.network;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.client.PartitionClientState;
import net.xevianlight.aphelion.network.packet.PartitionData;
import net.xevianlight.aphelion.network.packet.PartitionPayload;
// Handle packets TO the client FROM the server
public class ServerPayloadHandler {
public class PartitionPayloadHandler {
public static void handleDataOnMain(PartitionData data, IPayloadContext context) {
public static void handleDataOnMain(PartitionPayload data, IPayloadContext context) {
// Set our local partition state to the packet we just received.
PartitionClientState.set(data);
Aphelion.LOGGER.info("Partition packet received! id={}", data.id());
}

View File

@@ -9,28 +9,18 @@ import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.core.space.SpacePartitionSavedData;
import net.xevianlight.aphelion.network.packet.PartitionData;
import net.xevianlight.aphelion.network.packet.PartitionPayload;
import net.xevianlight.aphelion.util.SpacePartitionHelper;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@EventBusSubscriber(modid = Aphelion.MOD_ID)
public final class PartitionSync {
// send once right after join (safe: delayed to next server tick)
private static final Set<UUID> PENDING_JOIN_SEND = new HashSet<>();
@SubscribeEvent
public static void onLogin(PlayerEvent.PlayerLoggedInEvent e) {
if (e.getEntity() instanceof ServerPlayer sp) {
PENDING_JOIN_SEND.add(sp.getUUID());
}
}
private static final java.util.Map<UUID, PartitionData> LAST_SENT = new java.util.HashMap<>();
// Stora all packets we send to all players in a map so we can look it up later
private static final java.util.Map<UUID, PartitionPayload> LAST_SENT = new java.util.HashMap<>();
@SubscribeEvent
public static void onServerTick(ServerTickEvent.Post e) {
@@ -39,24 +29,29 @@ public final class PartitionSync {
// Aphelion.LOGGER.info("WORKS!!!");
for (ServerPlayer sp : server.getPlayerList().getPlayers()) {
PartitionData now = computePartitionFor(sp); // your logic
PartitionData prev = LAST_SENT.get(sp.getUUID());
// Prepare a new packet and compare it with the last one we sent the player
PartitionPayload now = computePartitionFor(sp);
PartitionPayload prev = LAST_SENT.get(sp.getUUID());
// If it is different, send them the new one
if (prev == null || !prev.equals(now)) {
PacketDistributor.sendToPlayer(sp, now);
// Store this packet for later
LAST_SENT.put(sp.getUUID(), now);
}
}
}
private static PartitionData computePartitionFor(ServerPlayer sp) {
// Example: convert player position to partition coords
private static PartitionPayload computePartitionFor(ServerPlayer sp) {
// convert player position to partition coords
int px = (int)Math.floor(sp.getX() / SpacePartitionHelper.SIZE);
int pz = (int)Math.floor(sp.getZ() / SpacePartitionHelper.SIZE);
// Get the orbit for the partition the player is in and create a packet for it
var orbit = SpacePartitionSavedData.get(sp.serverLevel()).getOrbitForPartition(px, pz);
String orbitId = (orbit != null) ? orbit.toString() : "aphelion:orbit/default";
return new PartitionData(orbitId);
return new PartitionPayload(orbitId);
}
}

View File

@@ -7,14 +7,14 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.xevianlight.aphelion.Aphelion;
public record PartitionData (String id) implements CustomPacketPayload {
public static final Type<PartitionData> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "partition_data"));
public record PartitionPayload(String id) implements CustomPacketPayload {
public static final Type<PartitionPayload> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "partition_data"));
public static final StreamCodec<ByteBuf, PartitionData> STREAM_CODEC = StreamCodec.composite(
public static final StreamCodec<ByteBuf, PartitionPayload> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.STRING_UTF8,
PartitionData::id,
PartitionPayload::id,
PartitionData::new
PartitionPayload::new
);
@Override

View File

@@ -17,6 +17,8 @@ public class ModTags {
public static final TagKey<Block> STORAGE_BLOCKS = commonTag("storage_blocks");
public static final TagKey<Block> STORAGE_BLOCKS_STEEL = commonTag("storage_blocks/steel");
public static final TagKey<Block> LAUNCH_PAD = createTag("launch_pad");
private static TagKey<Block> commonTag(String name) {
return BlockTags.create(ResourceLocation.fromNamespaceAndPath("c", name));
}
@@ -25,7 +27,6 @@ public class ModTags {
public static class Items {
public static final TagKey<Item> TEST_TAG = createTag("test_tag");
public static final TagKey<Item> INGOTS = commonTag("ingots");
public static final TagKey<Item> STORAGE_BLOCKS = commonTag("storage_blocks");
public static final TagKey<Item> STORAGE_BLOCKS_STEEL = commonTag("storage_blocks/steel");
public static final TagKey<Item> INGOT_ALUMINUM = commonTag("ingots/aluminum");

View File

@@ -2,7 +2,9 @@ package net.xevianlight.aphelion.util;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
@@ -135,4 +137,37 @@ public final class RocketStructure {
return new Extents(minX, minY, minZ, maxX, maxY, maxZ);
}
public static RocketStructure capture(Level level, BlockPos origin, int rx, int ry, int rz) {
return new RocketStructure(s -> {
for (int dy = -ry; dy <= ry; dy++) {
for (int dx = -rx; dx <= rx; dx++) {
for (int dz = -rz; dz <= rz; dz++) {
BlockPos p = origin.offset(dx, dy, dz);
BlockState st = level.getBlockState(p);
// Skip air and unbreakables/forbidden blocks as you like
if (st.isAir()) continue;
// Optional: ignore the assembler block itself
// if (p.equals(origin)) continue;
s.add(dx, dy, dz, st);
}
}
}
});
}
public static void clearCaptured(Level level, BlockPos origin, RocketStructure struct) {
for (int i = 0; i < struct.size(); i++) {
int packed = struct.packedPosAt(i);
int dx = RocketStructure.unpackX(packed);
int dy = RocketStructure.unpackY(packed);
int dz = RocketStructure.unpackZ(packed);
BlockPos wp = origin.offset(dx, dy, dz);
level.setBlock(wp, Blocks.AIR.defaultBlockState(), 3);
}
}
}