mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 10:00:54 +01:00
added gravity test block with gui and debug renderer
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package net.xevianlight.aphelion.network;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.xevianlight.aphelion.block.entity.custom.GravityTestBlockEntity;
|
||||
import net.xevianlight.aphelion.network.packet.UpdateGravityTestBlockPacket;
|
||||
|
||||
public class UpdateGravityTestBlockHandler {
|
||||
public static void handleDataOnMain(UpdateGravityTestBlockPacket packet, IPayloadContext context) {
|
||||
context.enqueueWork(() -> {
|
||||
BlockPos pos = packet.pos();
|
||||
float radius = packet.radius();
|
||||
float strength = packet.strength();
|
||||
|
||||
Level level = context.player().level();
|
||||
if (level.getBlockEntity(pos) instanceof GravityTestBlockEntity blockEntity) {
|
||||
blockEntity.setRadius(radius);
|
||||
blockEntity.setStrength(strength);
|
||||
blockEntity.sendUpdate();
|
||||
level.sendBlockUpdated(pos, level.getBlockState(pos), level.getBlockState(pos), Block.UPDATE_ALL);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.xevianlight.aphelion.network.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.xevianlight.aphelion.Aphelion;
|
||||
|
||||
public record UpdateGravityTestBlockPacket(BlockPos pos, float radius, float strength) implements CustomPacketPayload {
|
||||
|
||||
public static final CustomPacketPayload.Type<UpdateGravityTestBlockPacket> TYPE =
|
||||
new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "update_oxygen_test_block"));
|
||||
|
||||
public static final StreamCodec<ByteBuf, UpdateGravityTestBlockPacket> STREAM_CODEC = StreamCodec.composite(
|
||||
BlockPos.STREAM_CODEC,
|
||||
UpdateGravityTestBlockPacket::pos,
|
||||
ByteBufCodecs.FLOAT,
|
||||
UpdateGravityTestBlockPacket::radius,
|
||||
ByteBufCodecs.FLOAT,
|
||||
UpdateGravityTestBlockPacket::strength,
|
||||
UpdateGravityTestBlockPacket::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user