This commit is contained in:
p2vman 2025-05-25 23:13:27 +03:00
parent 38085d0b01
commit 6bec816f4c
10 changed files with 320 additions and 81 deletions

View File

@ -192,6 +192,9 @@ dependencies {
implementation(fg.deobf("com.simibubi.create:create-1.20.1:0.5.1.j")) implementation(fg.deobf("com.simibubi.create:create-1.20.1:0.5.1.j"))
implementation fg.deobf(files("./libs/api-1.1.0+b19b27c4a4.jar")) implementation fg.deobf(files("./libs/api-1.1.0+b19b27c4a4.jar"))
implementation fg.deobf("maven.modrinth:create-copies-cats:0.0.1-1.20.1")
//implementation fg.deobf(files("./libs/framed/FramedBlocks-9.3.0.jar"))
// For more info: // For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html

View File

@ -18,8 +18,10 @@ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.RegistryObject; import net.minecraftforge.registries.RegistryObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import space.eptaproject.vmodaddon.block.TBB; import space.eptaproject.vmodaddon.block.CompactBackupBlock;
import space.eptaproject.vmodaddon.block.TBBE; import space.eptaproject.vmodaddon.block.CompactBackupBlockEntity;
import space.eptaproject.vmodaddon.block.TrackBackupBlock;
import space.eptaproject.vmodaddon.block.TrackBackupBlockEntity;
import space.eptaproject.vmodaddon.util.ModRegistry; import space.eptaproject.vmodaddon.util.ModRegistry;
@Mod(Vmodaddon.MODID) @Mod(Vmodaddon.MODID)
@ -31,13 +33,15 @@ public class Vmodaddon {
public static final RegistryObject<Block> SHIP_VOID_BLOCK; public static final RegistryObject<Block> SHIP_VOID_BLOCK;
public static final RegistryObject<Block> TRAK_BUK; public static final RegistryObject<Block> TRAK_BUK;
public static final RegistryObject<Block> COMPACT_BACKUP;
public static final RegistryObject<BlockEntityType<TrackBackupBlockEntity>> MY_BLOCK_ENTITY;
public static final RegistryObject<BlockEntityType<CompactBackupBlockEntity>> COMPACT_BACKUP_BLOCK_ENTITY;
public static final RegistryObject<BlockEntityType<TBBE>> MY_BLOCK_ENTITY;
public static RegistryObject<Item> MY_BLOCK_ITEM; public static RegistryObject<Item> MY_BLOCK_ITEM;
public static RegistryObject<Item> SHIP_VOID_ITEM; public static RegistryObject<Item> SHIP_VOID_ITEM;
public static RegistryObject<Item> COMPACT_BACKUP_ITEM;
public static final ModRegistry REGISTRY; public static final ModRegistry REGISTRY;
@ -47,15 +51,18 @@ public class Vmodaddon {
static { static {
REGISTRY = new ModRegistry(MODID); REGISTRY = new ModRegistry(MODID);
TRAK_BUK = REGISTRY.BLOCKS.register("track_b", () -> new TBB(BlockBehaviour.Properties.of().mapColor(MapColor.STONE))); TRAK_BUK = REGISTRY.BLOCKS.register("track_b", () -> new TrackBackupBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
SHIP_VOID_BLOCK = REGISTRY.BLOCKS.register("ship_void", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE))); SHIP_VOID_BLOCK = REGISTRY.BLOCKS.register("ship_void", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
COMPACT_BACKUP = REGISTRY.BLOCKS.register("compact_backup", () -> new CompactBackupBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
MY_BLOCK_ENTITY = REGISTRY.BLOCK_ENTITIES.register("my_block_entity", () -> BlockEntityType.Builder.of(TBBE::new, TRAK_BUK.get()).build(null)); MY_BLOCK_ENTITY = REGISTRY.BLOCK_ENTITIES.register("track_backup", () -> BlockEntityType.Builder.of(TrackBackupBlockEntity::new, TRAK_BUK.get()).build(null));
COMPACT_BACKUP_BLOCK_ENTITY = REGISTRY.BLOCK_ENTITIES.register("compact_backup", () -> BlockEntityType.Builder.of(CompactBackupBlockEntity::new, COMPACT_BACKUP.get()).build(null));
EXAMPLE_TAB = REGISTRY.TabBuilder() EXAMPLE_TAB = REGISTRY.TabBuilder()
.push((registry) -> { .push((registry) -> {
MY_BLOCK_ITEM = registry.register("track_b", () -> new BlockItem(TRAK_BUK.get(), new Item.Properties())); MY_BLOCK_ITEM = registry.register("track_b", () -> new BlockItem(TRAK_BUK.get(), new Item.Properties()));
SHIP_VOID_ITEM = registry.register("ship_void", () -> new BlockItem(SHIP_VOID_BLOCK.get(), new Item.Properties())); SHIP_VOID_ITEM = registry.register("ship_void", () -> new BlockItem(SHIP_VOID_BLOCK.get(), new Item.Properties()));
COMPACT_BACKUP_ITEM = registry.register("compact_backup", () -> new BlockItem(COMPACT_BACKUP.get(), new Item.Properties()));
}) })
.build("vmodaddon", Items.BEDROCK.getDefaultInstance()); .build("vmodaddon", Items.BEDROCK.getDefaultInstance());
} }

View File

@ -0,0 +1,23 @@
package space.eptaproject.vmodaddon.block;
import com.simibubi.create.foundation.block.IBE;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import space.eptaproject.vmodaddon.Vmodaddon;
public class CompactBackupBlock extends Block implements IBE<CompactBackupBlockEntity> {
public CompactBackupBlock(Properties properties) {
super(properties);
}
@Override
public BlockEntityType<? extends CompactBackupBlockEntity> getBlockEntityType() {
return Vmodaddon.COMPACT_BACKUP_BLOCK_ENTITY.get();
}
@Override
public Class<CompactBackupBlockEntity> getBlockEntityClass() {
return CompactBackupBlockEntity.class;
}
}

View File

@ -0,0 +1,138 @@
package space.eptaproject.vmodaddon.block;
import edn.stratodonut.drivebywire.wire.ShipWireNetworkManager;
import edn.stratodonut.trackwork.tracks.forces.PhysicsTrackController;
import edn.stratodonut.trackwork.tracks.forces.SimpleWheelController;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.valkyrienskies.core.api.ships.ServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import space.eptaproject.vmodaddon.IPhysicsTrackController;
import space.eptaproject.vmodaddon.ISimpleWheelController;
import space.eptaproject.vmodaddon.Vmodaddon;
public class CompactBackupBlockEntity extends BlockEntity {
private CompoundTag pendingBackupData;
public CompactBackupBlockEntity(BlockPos p_155229_, BlockState p_155230_) {
super(Vmodaddon.COMPACT_BACKUP_BLOCK_ENTITY.get(), p_155229_, p_155230_);
}
@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
{
PhysicsTrackController physicsTrackController = ship.getAttachment(PhysicsTrackController.class);
IPhysicsTrackController controller = (IPhysicsTrackController) physicsTrackController;
if (physicsTrackController != null) {
CompoundTag PhysicsTrackControllerTag = new CompoundTag();
PhysicsTrackControllerTag.putFloat("SuspensionStiffness", controller.getSuspensionStiffness());
{
CompoundTag suspensionAdjust = new CompoundTag();
Vector3dc vec = controller.getSuspensionAdjust();
suspensionAdjust.putDouble("x", vec.x());
suspensionAdjust.putDouble("y", vec.y());
suspensionAdjust.putDouble("z", vec.z());
PhysicsTrackControllerTag.put("suspensionAdjust", suspensionAdjust);
}
tag.put("PhysicsTrackController", PhysicsTrackControllerTag);
}
}
{
SimpleWheelController simpleWheelController = ship.getAttachment(SimpleWheelController.class);
ISimpleWheelController controller = (ISimpleWheelController) simpleWheelController;
if (simpleWheelController != null) {
CompoundTag SimpleWheelControllerTag = new CompoundTag();
SimpleWheelControllerTag.putFloat("SuspensionStiffness", controller.getSuspensionStiffness());
{
CompoundTag suspensionAdjust = new CompoundTag();
Vector3dc vec = controller.getSuspensionAdjust();
suspensionAdjust.putDouble("x", vec.x());
suspensionAdjust.putDouble("y", vec.y());
suspensionAdjust.putDouble("z", vec.z());
SimpleWheelControllerTag.put("suspensionAdjust", suspensionAdjust);
}
tag.put("SimpleWheelController", SimpleWheelControllerTag);
}
}
}
ship = (ServerShip) VSGameUtilsKt.getShipManagingPos(this.level, this.getBlockPos());
if (this.level != null) {
if (this.pendingBackupData == null) {
this.pendingBackupData = new CompoundTag();
}
ShipWireNetworkManager.get(ship).ifPresent((m) -> this.pendingBackupData.merge(m.serialiseToNbt(this.level, this.getBlockPos())));
if (this.pendingBackupData != null) {
tag.put("WireNetwork", this.pendingBackupData);
}
}
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
if (tag.contains("SimpleWheelController")) {
CompoundTag L = tag.getCompound("SimpleWheelController");
SimpleWheelController controller2 = SimpleWheelController.getOrCreate(ship);
if (L.contains("SuspensionStiffness")) {
((ISimpleWheelController) controller2).setSuspensionStiffness(L.getFloat("SuspensionStiffness"));
}
if (L.contains("suspensionAdjust")) {
CompoundTag suspensionAdjust = L.getCompound("suspensionAdjust");
((ISimpleWheelController) controller2).setSuspensionAdjust(new Vector3d(new Vector3d(suspensionAdjust.getDouble("x"), suspensionAdjust.getDouble("y"), suspensionAdjust.getDouble("z"))));
}
}
if (tag.contains("PhysicsTrackController")) {
CompoundTag L = tag.getCompound("PhysicsTrackController");
PhysicsTrackController controller = PhysicsTrackController.getOrCreate(ship);
if (L.contains("SuspensionStiffness")) {
((IPhysicsTrackController) controller).setSuspensionStiffness(L.getFloat("SuspensionStiffness"));
}
if (L.contains("suspensionAdjust")) {
CompoundTag suspensionAdjust = L.getCompound("suspensionAdjust");
((IPhysicsTrackController) controller).setSuspensionAdjust(new Vector3d(suspensionAdjust.getDouble("x"), suspensionAdjust.getDouble("y"), suspensionAdjust.getDouble("z")));
}
}
}
ship = (ServerShip) VSGameUtilsKt.getShipManagingPos(this.level, getBlockPos());
if (ship != null) {
if (tag.contains("WireNetwork", 10)) {
ShipWireNetworkManager.loadIfNotExists(ship, level, tag.getCompound("WireNetwork"), this.getBlockPos(), Rotation.NONE);
this.pendingBackupData = tag.getCompound("WireNetwork");
}
}
}
}

View File

@ -1,68 +0,0 @@
package space.eptaproject.vmodaddon.block;
import edn.stratodonut.trackwork.tracks.forces.PhysicsTrackController;
import edn.stratodonut.trackwork.tracks.forces.SimpleWheelController;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.valkyrienskies.core.api.ships.ServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import space.eptaproject.vmodaddon.IPhysicsTrackController;
import space.eptaproject.vmodaddon.ISimpleWheelController;
import space.eptaproject.vmodaddon.Vmodaddon;
public class TBBE extends BlockEntity {
public TBBE(BlockPos p_155229_, BlockState p_155230_) {
super(Vmodaddon.MY_BLOCK_ENTITY.get(), p_155229_, p_155230_);
}
@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
PhysicsTrackController physicsTrackController = ship.getAttachment(PhysicsTrackController.class);
IPhysicsTrackController controller = (IPhysicsTrackController) physicsTrackController;
if (physicsTrackController != null) {
tag.putFloat("SuspensionStiffness", controller.getSuspensionStiffness());
{
CompoundTag suspensionAdjust = new CompoundTag();
Vector3dc vec = controller.getSuspensionAdjust();
suspensionAdjust.putDouble("x", vec.x());
suspensionAdjust.putDouble("y", vec.y());
suspensionAdjust.putDouble("z", vec.z());
tag.put("suspensionAdjust", suspensionAdjust);
}
}
}
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
PhysicsTrackController controller = PhysicsTrackController.getOrCreate(ship);
SimpleWheelController controller2 = SimpleWheelController.getOrCreate(ship);
if (tag.contains("SuspensionStiffness")) {
((IPhysicsTrackController) controller).setSuspensionStiffness(tag.getFloat("SuspensionStiffness"));
}
if (tag.contains("suspensionAdjust")) {
CompoundTag suspensionAdjust = tag.getCompound("suspensionAdjust");
Vector3dc vector3dc = new Vector3d(suspensionAdjust.getDouble("x"), suspensionAdjust.getDouble("y"), suspensionAdjust.getDouble("z"));
((IPhysicsTrackController) controller).setSuspensionAdjust(new Vector3d(vector3dc));
((ISimpleWheelController) controller2).setSuspensionAdjust(new Vector3d(vector3dc));
}
}
}
}

View File

@ -5,19 +5,19 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import space.eptaproject.vmodaddon.Vmodaddon; import space.eptaproject.vmodaddon.Vmodaddon;
public class TBB extends Block implements IBE<TBBE> { public class TrackBackupBlock extends Block implements IBE<TrackBackupBlockEntity> {
public TBB(Properties properties) { public TrackBackupBlock(Properties properties) {
super(properties); super(properties);
} }
@Override @Override
public BlockEntityType<? extends TBBE> getBlockEntityType() { public BlockEntityType<? extends TrackBackupBlockEntity> getBlockEntityType() {
return Vmodaddon.MY_BLOCK_ENTITY.get(); return Vmodaddon.MY_BLOCK_ENTITY.get();
} }
@Override @Override
public Class<TBBE> getBlockEntityClass() { public Class<TrackBackupBlockEntity> getBlockEntityClass() {
return TBBE.class; return TrackBackupBlockEntity.class;
} }
} }

View File

@ -0,0 +1,108 @@
package space.eptaproject.vmodaddon.block;
import edn.stratodonut.trackwork.tracks.forces.PhysicsTrackController;
import edn.stratodonut.trackwork.tracks.forces.SimpleWheelController;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.valkyrienskies.core.api.ships.ServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import space.eptaproject.vmodaddon.IPhysicsTrackController;
import space.eptaproject.vmodaddon.ISimpleWheelController;
import space.eptaproject.vmodaddon.Vmodaddon;
public class TrackBackupBlockEntity extends BlockEntity {
public TrackBackupBlockEntity(BlockPos p_155229_, BlockState p_155230_) {
super(Vmodaddon.MY_BLOCK_ENTITY.get(), p_155229_, p_155230_);
}
@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
{
PhysicsTrackController physicsTrackController = ship.getAttachment(PhysicsTrackController.class);
IPhysicsTrackController controller = (IPhysicsTrackController) physicsTrackController;
if (physicsTrackController != null) {
CompoundTag PhysicsTrackControllerTag = new CompoundTag();
PhysicsTrackControllerTag.putFloat("SuspensionStiffness", controller.getSuspensionStiffness());
{
CompoundTag suspensionAdjust = new CompoundTag();
Vector3dc vec = controller.getSuspensionAdjust();
suspensionAdjust.putDouble("x", vec.x());
suspensionAdjust.putDouble("y", vec.y());
suspensionAdjust.putDouble("z", vec.z());
PhysicsTrackControllerTag.put("suspensionAdjust", suspensionAdjust);
}
tag.put("PhysicsTrackController", PhysicsTrackControllerTag);
}
}
{
SimpleWheelController simpleWheelController = ship.getAttachment(SimpleWheelController.class);
ISimpleWheelController controller = (ISimpleWheelController) simpleWheelController;
if (simpleWheelController != null) {
CompoundTag SimpleWheelControllerTag = new CompoundTag();
SimpleWheelControllerTag.putFloat("SuspensionStiffness", controller.getSuspensionStiffness());
{
CompoundTag suspensionAdjust = new CompoundTag();
Vector3dc vec = controller.getSuspensionAdjust();
suspensionAdjust.putDouble("x", vec.x());
suspensionAdjust.putDouble("y", vec.y());
suspensionAdjust.putDouble("z", vec.z());
SimpleWheelControllerTag.put("suspensionAdjust", suspensionAdjust);
}
tag.put("SimpleWheelController", SimpleWheelControllerTag);
}
}
}
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
ServerShip ship = (ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, getBlockPos());
if (ship != null) {
if (tag.contains("SimpleWheelController")) {
CompoundTag L = tag.getCompound("SimpleWheelController");
SimpleWheelController controller2 = SimpleWheelController.getOrCreate(ship);
if (L.contains("SuspensionStiffness")) {
((ISimpleWheelController) controller2).setSuspensionStiffness(L.getFloat("SuspensionStiffness"));
}
if (L.contains("suspensionAdjust")) {
CompoundTag suspensionAdjust = L.getCompound("suspensionAdjust");
((ISimpleWheelController) controller2).setSuspensionAdjust(new Vector3d(new Vector3d(suspensionAdjust.getDouble("x"), suspensionAdjust.getDouble("y"), suspensionAdjust.getDouble("z"))));
}
}
if (tag.contains("PhysicsTrackController")) {
CompoundTag L = tag.getCompound("PhysicsTrackController");
PhysicsTrackController controller = PhysicsTrackController.getOrCreate(ship);
if (L.contains("SuspensionStiffness")) {
((IPhysicsTrackController) controller).setSuspensionStiffness(L.getFloat("SuspensionStiffness"));
}
if (L.contains("suspensionAdjust")) {
CompoundTag suspensionAdjust = L.getCompound("suspensionAdjust");
((IPhysicsTrackController) controller).setSuspensionAdjust(new Vector3d(suspensionAdjust.getDouble("x"), suspensionAdjust.getDouble("y"), suspensionAdjust.getDouble("z")));
}
}
}
}
}

View File

@ -39,7 +39,9 @@ public class MixinPlugin implements IMixinConfigPlugin {
return List.of( return List.of(
"BlockPaletteHashMapV1Mixin", "BlockPaletteHashMapV1Mixin",
"PhysicsTrackControllerAccessor", "PhysicsTrackControllerAccessor",
"PhysicsTrackControllerMixin" "PhysicsTrackControllerMixin",
"SimpleWheelControllerAccessor",
"SimpleWheelControllerMixin"
); );
} }
@Override @Override

View File

@ -7,6 +7,12 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SimpleWheelController.class) @Mixin(SimpleWheelController.class)
public interface SimpleWheelControllerAccessor { public interface SimpleWheelControllerAccessor {
@Accessor(value = "suspensionStiffness", remap = false)
float getSuspensionStiffness();
@Accessor(value = "suspensionStiffness", remap = false)
void setSuspensionStiffness(float val);
@Accessor(value = "suspensionAdjust", remap = false) @Accessor(value = "suspensionAdjust", remap = false)
Vector3dc getSuspensionAdjust(); Vector3dc getSuspensionAdjust();

View File

@ -0,0 +1,20 @@
package space.eptaproject.vmodaddon.mixins;
import edn.stratodonut.trackwork.tracks.forces.SimpleWheelController;
import org.joml.Math;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import space.eptaproject.vmodaddon.Config;
import space.eptaproject.vmodaddon.ISimpleWheelController;
@Mixin(SimpleWheelController.class)
public abstract class SimpleWheelControllerMixin implements ISimpleWheelController {
@Shadow private volatile float suspensionStiffness;
@Overwrite(remap = false)
public final float setDamperCoefficient(float delta) {
this.suspensionStiffness = Math.clamp(1, Config.Suspension_Stiffness_LIMIT.get(), this.suspensionStiffness + delta);
return this.suspensionStiffness;
}
}