feat: 改为多角度的玩偶

This commit is contained in:
叁玖领域 2026-03-15 13:10:55 +08:00
parent 0c2a589a0c
commit 6c6883b767
72 changed files with 993 additions and 249 deletions

View File

@ -248,6 +248,9 @@ public enum Lib39LangKey implements ILangKeyValueCollection {
addLang(LangKeyValue.copyOf(
Lib39Blocks.DOLL, ModPartEnum.BLOCK, dollName
));
addLang(LangKeyValue.copyOf(
Lib39Blocks.WALL_DOLL, ModPartEnum.BLOCK, dollName
));
addLang(LangKeyValue.ofKey(
"tooltip.lib39.content.doll.hover.1", ModPartEnum.DESCRIPTION,
"§eSkinOwner §7:§a %s ", "§e皮肤所有者§7:§a%s", "§e皮膚所有者§7:§a%s", "§e膚主§7:§a%s"

View File

@ -635,8 +635,10 @@ public class WheelWidget extends AbstractWidget {
float pixelOuterRadius = outerRadius * guiScale;
float pixelAntiAliasing = 2.0f * guiScale; // 抗锯齿范围
System.out.println("Shader Params - Center: (" + pixelCenterX + ", " + pixelCenterY +
"), InnerRadius: " + pixelInnerRadius + ", OuterRadius: " + pixelOuterRadius);
// if (Services.PLATFORM.isDevelopmentEnvironment()) {
// System.out.println("Shader Params - Center: (" + pixelCenterX + ", " + pixelCenterY +
// "), InnerRadius: " + pixelInnerRadius + ", OuterRadius: " + pixelOuterRadius);
// }
ShaderInstance shader = Lib39Shaders.getRingShader();
shader.safeGetUniform("Center").set(pixelCenterX, pixelCenterY);

View File

@ -11,11 +11,15 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SkullBlock;
import net.minecraft.world.level.block.WallSkullBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.client.model.DollModel;
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
import top.r3944realms.lib39.content.block.DollBlock;
import top.r3944realms.lib39.content.block.AbstractDollBlock;
import top.r3944realms.lib39.content.block.WallDollBlock;
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
import top.r3944realms.lib39.util.lang.Pair;
@ -37,14 +41,15 @@ public class DollBlockEntityRenderer implements BlockEntityRenderer<DollBlockEnt
@Override
public void render(@NotNull DollBlockEntity dollBlockEntity, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight, int packedOverlay) {
BlockState blockState = dollBlockEntity.getBlockState();
if (blockState.getBlock() instanceof DollBlock) {
Direction facing = blockState.getValue(DollBlock.FACING);
if (blockState.getBlock() instanceof AbstractDollBlock dollBlock) {
boolean isWall = dollBlock instanceof WallDollBlock;
Direction direction = isWall ? blockState.getValue(WallSkullBlock.FACING) : null;
float rotation = isWall ? direction.toYRot() : RotationSegment.convertToDegrees(blockState.getValue(SkullBlock.ROTATION));
GameProfile profile = dollBlockEntity.getOwnerProfile();
Pair<ResourceLocation, Boolean> resourceLocationBooleanPair = DollItemRenderer.loadSkin(profile);
poseStack.pushPose();
poseStack.translate(0.5, 1.5, 0.5);
poseStack.scale(1.0F, -1.0F, -1.0F);
float rotation = facing.toYRot();
poseStack.mulPose(Axis.YP.rotationDegrees(rotation));
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(resourceLocationBooleanPair.first));
this.dollModel.slim = resourceLocationBooleanPair.second;

View File

@ -0,0 +1,226 @@
package top.r3944realms.lib39.content.block;
import com.mojang.authlib.GameProfile;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
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.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
import top.r3944realms.lib39.content.block.property.DollPose;
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
import top.r3944realms.lib39.core.register.Lib39Items;
import top.r3944realms.lib39.core.register.Lib39SoundEvents;
import top.r3944realms.lib39.util.GameProfileHelper;
import java.util.List;
/**
* The type Abstract doll block.
*/
@SuppressWarnings("deprecation")
public abstract class AbstractDollBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
/**
* The constant WATERLOGGED.
*/
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
private static final Properties properties = Properties.of()
.instrument(NoteBlockInstrument.BASEDRUM)
.sound(SoundType.WOOL)
.pushReaction(PushReaction.DESTROY)
.strength(0f, 10f)
.noOcclusion();
private static final double PARTICLE_OFFSET_RANGE = 0.25;
private static final double PARTICLE_HEIGHT_OFFSET = 1.0;
private static final double PARTICLE_HEIGHT_VARIANCE = 0.2;
private static final float NOTE_COLOR_DIVISOR = 24.0F;
private static final int MAX_NOTE_COLORS = 4;
private static final float BASE_VOLUME = 1.0f;
private static final float PITCH_VARIANCE = 0.5f;
private static final float BASE_PITCH = 0.75f;
private static final VoxelShape DOLL_SHAPE = Block.box(2.0d, 0.0d, 2.0d, 14.0d, 12.0d, 14.0d);
/**
* The constant POSE.
*/
public static final EnumProperty<DollPose> POSE = EnumProperty.create("pose", DollPose.class);
/**
* Instantiates a new Abstract doll block.
*/
public AbstractDollBlock() {
super(properties);
}
@Override
public boolean canBeReplaced(@NotNull BlockState state, @NotNull BlockPlaceContext useContext) {
return false;
}
@Override
public @NotNull BlockState updateShape(@NotNull BlockState currentState, @NotNull Direction direction, @NotNull BlockState neighborState,
@NotNull LevelAccessor level, @NotNull BlockPos currentPos, @NotNull BlockPos neighborPos) {
if (currentState.getValue(WATERLOGGED)) {
level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}
return super.updateShape(currentState, direction, neighborState, level, currentPos, neighborPos);
}
@Override
public @NotNull FluidState getFluidState(@NotNull BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}
@Override
public @NotNull InteractionResult use(@NotNull BlockState blockState, @NotNull Level level, @NotNull BlockPos blockPos, @NotNull Player player,
@NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
if (level instanceof ServerLevel serverLevel) {
// 播放粒子效果
spawnNoteParticles(serverLevel, blockPos);
// 播放音效
playDollSound(serverLevel, blockPos);
}
return InteractionResult.SUCCESS;
}
/**
* 在玩偶位置生成音符粒子效果
*/
private void spawnNoteParticles(ServerLevel serverLevel, BlockPos blockPos) {
Vec3 particlePosition = calculateParticlePosition(serverLevel, blockPos);
float noteColor = calculateNoteColor(serverLevel);
serverLevel.sendParticles(ParticleTypes.NOTE,
particlePosition.x(), particlePosition.y(), particlePosition.z(),
0, noteColor, 0, 0, 1);
}
/**
* 计算粒子生成位置添加随机偏移
*/
private @NotNull Vec3 calculateParticlePosition(@NotNull ServerLevel serverLevel, BlockPos blockPos) {
return Vec3.atBottomCenterOf(blockPos).add(
(serverLevel.getRandom().nextFloat() - 0.5) * PARTICLE_OFFSET_RANGE * 2,
PARTICLE_HEIGHT_OFFSET + serverLevel.getRandom().nextFloat() * PARTICLE_HEIGHT_VARIANCE,
(serverLevel.getRandom().nextFloat() - 0.5) * PARTICLE_OFFSET_RANGE * 2
);
}
/**
* 计算音符粒子的颜色
*/
private float calculateNoteColor(@NotNull ServerLevel serverLevel) {
return serverLevel.getRandom().nextInt(MAX_NOTE_COLORS) / NOTE_COLOR_DIVISOR;
}
/**
* 播放玩偶音效
*/
private void playDollSound(@NotNull ServerLevel serverLevel, BlockPos blockPos) {
float pitch = BASE_PITCH + serverLevel.random.nextFloat() * PITCH_VARIANCE;
serverLevel.playSound(null, blockPos, Lib39SoundEvents.DUCK_TOY.get(),
SoundSource.BLOCKS, BASE_VOLUME, pitch);
}
@Override
public @NotNull VoxelShape getShape(@NotNull BlockState blockState, @NotNull BlockGetter level, @NotNull BlockPos blockPos, @NotNull CollisionContext context) {
return DOLL_SHAPE;
}
public @NotNull VoxelShape getOcclusionShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos) {
return Shapes.empty();
}
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return Lib39BlockEntities.DOLL_BLOCK_ENTITY.get().create(blockPos, blockState);
}
@SuppressWarnings("deprecation")
@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Override
public @NotNull ItemStack getCloneItemStack(@NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull BlockState state) {
ItemStack stack = super.getCloneItemStack(level, pos, state);
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof DollBlockEntity doll) {
GameProfile profile = doll.getOwnerProfile();
if (profile != null) {
GameProfileHelper.saveProfileToItemStack(stack, profile);
}
}
return stack;
}
/**
* 最重要的方法重写掉落逻辑
*/
@Override
@NotNull
public List<ItemStack> getDrops(@NotNull BlockState state, @NotNull LootParams.Builder params) {
// 获取方块实体
BlockEntity blockEntity = params.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof DollBlockEntity dollEntity) {
List<ItemStack> customDrops = getCustomDrops(dollEntity, params);
if (customDrops != null) return customDrops;
}
return super.getDrops(state, params);
}
@Override
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(WATERLOGGED, POSE);
}
/**
* 生成自定义掉落物
*/
@Nullable
private List<ItemStack> getCustomDrops(DollBlockEntity dollEntity, LootParams.Builder params) {
if (params.getOptionalParameter(LootContextParams.THIS_ENTITY) instanceof Player player) {
if (player.isCreative()) {
return List.of();
}
}
GameProfile profile = dollEntity.getOwnerProfile();
if (profile != null) {
ItemStack instance = Lib39Items.DOLL.get().getDefaultInstance();
GameProfileHelper.saveProfileToItemStack(instance, profile);
return List.of(instance);
}
return null;
}
}

View File

@ -1,235 +1,65 @@
package top.r3944realms.lib39.content.block;
import com.mojang.authlib.GameProfile;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
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.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
import top.r3944realms.lib39.content.block.property.DollPose;
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
import top.r3944realms.lib39.core.register.Lib39Items;
import top.r3944realms.lib39.core.register.Lib39SoundEvents;
import top.r3944realms.lib39.util.GameProfileHelper;
import java.util.List;
/**
* The type Doll block.
*/
@SuppressWarnings("deprecation")
public class DollBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock, EntityBlock {
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public class DollBlock extends AbstractDollBlock{
/**
* The constant POSE.
* The constant MAX.
*/
public static final EnumProperty<DollPose> POSE = EnumProperty.create("pose", DollPose.class);
public static final int MAX = RotationSegment.getMaxSegmentIndex();
private static final VoxelShape DOLL_SHAPE = Block.box(2.0d, 0.0d, 2.0d, 14.0d, 12.0d, 14.0d);
private static final Properties properties = Properties.of()
.instrument(NoteBlockInstrument.BASEDRUM)
.sound(SoundType.WOOL)
.pushReaction(PushReaction.DESTROY)
.strength(0f, 10f)
.noOcclusion();
private static final double PARTICLE_OFFSET_RANGE = 0.25;
private static final double PARTICLE_HEIGHT_OFFSET = 1.0;
private static final double PARTICLE_HEIGHT_VARIANCE = 0.2;
private static final float NOTE_COLOR_DIVISOR = 24.0F;
private static final int MAX_NOTE_COLORS = 4;
private static final float BASE_VOLUME = 1.0f;
private static final float PITCH_VARIANCE = 0.5f;
private static final float BASE_PITCH = 0.75f;
private static final int ROTATIONS = MAX + 1;
/**
* The constant ROTATION.
*/
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
/**
* Instantiates a new Doll block.
*/
public DollBlock() {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.SOUTH)
.setValue(POSE, DollPose.DEFAULT)
.setValue(WATERLOGGED, false));
}
@Override
public boolean canBeReplaced(@NotNull BlockState state, @NotNull BlockPlaceContext useContext) {
return false;
}
@Override
public @NotNull BlockState updateShape(@NotNull BlockState currentState, @NotNull Direction direction, @NotNull BlockState neighborState,
@NotNull LevelAccessor level, @NotNull BlockPos currentPos, @NotNull BlockPos neighborPos) {
if (currentState.getValue(WATERLOGGED)) {
level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}
return super.updateShape(currentState, direction, neighborState, level, currentPos, neighborPos);
}
@Override
public @NotNull FluidState getFluidState(@NotNull BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}
@Override
public @NotNull InteractionResult use(@NotNull BlockState blockState, @NotNull Level level, @NotNull BlockPos blockPos, @NotNull Player player,
@NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
if (level instanceof ServerLevel serverLevel) {
// 播放粒子效果
spawnNoteParticles(serverLevel, blockPos);
// 播放音效
playDollSound(serverLevel, blockPos);
}
return InteractionResult.SUCCESS;
}
/**
* 在玩偶位置生成音符粒子效果
*/
private void spawnNoteParticles(ServerLevel serverLevel, BlockPos blockPos) {
Vec3 particlePosition = calculateParticlePosition(serverLevel, blockPos);
float noteColor = calculateNoteColor(serverLevel);
serverLevel.sendParticles(ParticleTypes.NOTE,
particlePosition.x(), particlePosition.y(), particlePosition.z(),
0, noteColor, 0, 0, 1);
}
/**
* 计算粒子生成位置添加随机偏移
*/
private @NotNull Vec3 calculateParticlePosition(@NotNull ServerLevel serverLevel, BlockPos blockPos) {
return Vec3.atBottomCenterOf(blockPos).add(
(serverLevel.getRandom().nextFloat() - 0.5) * PARTICLE_OFFSET_RANGE * 2,
PARTICLE_HEIGHT_OFFSET + serverLevel.getRandom().nextFloat() * PARTICLE_HEIGHT_VARIANCE,
(serverLevel.getRandom().nextFloat() - 0.5) * PARTICLE_OFFSET_RANGE * 2
super();
this.registerDefaultState(
this.stateDefinition.any()
.setValue(POSE, DollPose.DEFAULT)
.setValue(WATERLOGGED, false)
.setValue(ROTATION, 0)
);
}
/**
* 计算音符粒子的颜色
*/
private float calculateNoteColor(@NotNull ServerLevel serverLevel) {
return serverLevel.getRandom().nextInt(MAX_NOTE_COLORS) / NOTE_COLOR_DIVISOR;
}
/**
* 播放玩偶音效
*/
private void playDollSound(@NotNull ServerLevel serverLevel, BlockPos blockPos) {
float pitch = BASE_PITCH + serverLevel.random.nextFloat() * PITCH_VARIANCE;
serverLevel.playSound(null, blockPos, Lib39SoundEvents.DUCK_TOY.get(),
SoundSource.BLOCKS, BASE_VOLUME, pitch);
}
@Override
public @Nullable BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
boolean isWaterlogged = fluidState.getType() == Fluids.WATER;
return this.defaultBlockState()
.setValue(FACING, context.getHorizontalDirection().getOpposite())
.setValue(WATERLOGGED, isWaterlogged)
.setValue(POSE, DollPose.DEFAULT);
BlockState stateForPlacement = super.getStateForPlacement(context);
return stateForPlacement != null ? stateForPlacement.setValue(ROTATION, RotationSegment.convertToSegment((context.getRotation()+180) % 360)) : null;
}
@Override
public @NotNull VoxelShape getShape(@NotNull BlockState blockState, @NotNull BlockGetter level, @NotNull BlockPos blockPos, @NotNull CollisionContext context) {
return DOLL_SHAPE;
public @NotNull BlockState rotate(@NotNull BlockState state, @NotNull Rotation rotation) {
return state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), ROTATIONS));
}
@Override
public @NotNull BlockState mirror(@NotNull BlockState state, @NotNull Mirror mirror) {
return state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), ROTATIONS));
}
@Override
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING, WATERLOGGED, POSE);
}
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return Lib39BlockEntities.DOLL_BLOCK_ENTITY.get().create(blockPos, blockState);
}
@SuppressWarnings("deprecation")
@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Override
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) {
ItemStack stack = super.getCloneItemStack(level, pos, state);
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof DollBlockEntity doll) {
GameProfile profile = doll.getOwnerProfile();
if (profile != null) {
GameProfileHelper.saveProfileToItemStack(stack, profile);
}
}
return stack;
}
/**
* 最重要的方法重写掉落逻辑
*/
@Override
@NotNull
public List<ItemStack> getDrops(@NotNull BlockState state, @NotNull LootParams.Builder params) {
// 获取方块实体
BlockEntity blockEntity = params.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof DollBlockEntity dollEntity) {
List<ItemStack> customDrops = getCustomDrops(dollEntity, params);
if (customDrops != null) return customDrops;
}
return super.getDrops(state, params);
}
/**
* 生成自定义掉落物
*/
@Nullable
private List<ItemStack> getCustomDrops(DollBlockEntity dollEntity, LootParams.Builder params) {
if (params.getOptionalParameter(LootContextParams.THIS_ENTITY) instanceof Player player) {
if (player.isCreative()) {
return List.of();
}
}
GameProfile profile = dollEntity.getOwnerProfile();
if (profile != null) {
ItemStack instance = Lib39Items.DOLL.get().getDefaultInstance();
GameProfileHelper.saveProfileToItemStack(instance, profile);
return List.of(instance);
}
return null;
builder.add(ROTATION);
}
}

View File

@ -0,0 +1,56 @@
package top.r3944realms.lib39.content.block;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.content.block.property.DollPose;
/**
* The type Wall doll block.
*/
@SuppressWarnings({"deprecation"})
public class WallDollBlock extends AbstractDollBlock {
/**
* The constant FACING.
*/
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
/**
* Instantiates a new Wall doll block.
*/
public WallDollBlock() {
super();
this.registerDefaultState(
this.stateDefinition.any()
.setValue(POSE, DollPose.DEFAULT)
.setValue(WATERLOGGED, false)
.setValue(FACING, Direction.NORTH)
);
}
public @NotNull BlockState rotate(@NotNull BlockState state, @NotNull Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}
public @NotNull BlockState mirror(@NotNull BlockState state, @NotNull Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}
@Override
public @Nullable BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
BlockState stateForPlacement = super.getStateForPlacement(context);
return stateForPlacement != null ? stateForPlacement.setValue(FACING, context.getHorizontalDirection().getOpposite()) : null;
}
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
}

View File

@ -1,11 +1,12 @@
package top.r3944realms.lib39.content.item;
import com.mojang.authlib.GameProfile;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.StandingAndWallBlockItem;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
@ -18,14 +19,14 @@ import java.util.List;
/**
* The type Doll item.
*/
public class DollItem extends BlockItem implements Equipable {
public class DollItem extends StandingAndWallBlockItem implements Equipable {
/**
* Instantiates a new Doll item.
*
* @param properties the properties
*/
public DollItem(Properties properties) {
super(Lib39Blocks.DOLL.get(), properties);
super(Lib39Blocks.DOLL.get(), Lib39Blocks.WALL_DOLL.get(), properties, Direction.DOWN);
}

View File

@ -13,5 +13,9 @@ public class Lib39Blocks {
* The constant DOLL.
*/
public static Supplier<Block> DOLL;
/**
* The Wall doll.
*/
public static Supplier<Block> WALL_DOLL;
}

View File

@ -4,6 +4,9 @@ plugins {
id 'multiloader-loader'
id 'fabric-loom'
}
repositories {
maven { url 'https://maven.covers1624.net/' }
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.layered {
@ -18,6 +21,7 @@ dependencies {
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
implementation project(":common")
testImplementation "net.fabricmc:fabric-loader-junit:${fabric_loader_version}"
localRuntime 'net.covers1624:DevLogin:0.1.0.5'
}
loom {
@ -36,10 +40,13 @@ loom {
runs {
client {
client()
client()
ideConfigGenerated true
programArgs '--launch_target', 'net.fabricmc.loader.impl.launch.knot.KnotClient'
mainClass.set 'net.covers1624.devlogin.DevLogin'
setConfigName("Fabric Client")
ideConfigGenerated(true)
runDir("run")
programArgs "--username", "R3944Realms"
def args = [
"-Dlib39.modid=${mod_id}".toString(),
"-Dlib39.output=${generatedOutput}".toString(),
@ -74,9 +81,6 @@ loom {
]
vmArgs.addAll(args)
}
gameTest {
}
}
}

View File

@ -8,6 +8,9 @@ import top.r3944realms.lib39.core.register.FabricLib39Items;
import top.r3944realms.lib39.core.register.FabricLib39SoundEvents;
import top.r3944realms.lib39.example.FabricLib39Example;
/**
* The type Lib 39 fabric.
*/
public class Lib39Fabric implements ModInitializer {
@Override

View File

@ -9,6 +9,9 @@ import top.r3944realms.lib39.client.ShaderRegistry;
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
import top.r3944realms.lib39.core.network.FabricNetworkHandler;
/**
* The type Lib 39 fabric client.
*/
public class Lib39FabricClient implements ClientModInitializer {
@Override
public void onInitializeClient() {

View File

@ -17,41 +17,68 @@ public class AnvilUpdateCallback {
public interface AnvilUpdate {
/**
* 当铁砧内容改变时调用
* @param left 左侧输入槽的物品
* @param right 右侧输入槽的物品
*
* @param left 左侧输入槽的物品
* @param right 右侧输入槽的物品
* @param outputSlot 输出槽的物品
* @param name 输入的名字
* @param baseCost 基础花费
* @param player 玩家
* @param name 输入的名字
* @param baseCost 基础花费
* @param player 玩家
* @return AnvilUpdateResult 包含处理结果如果返回null则继续默认处理
*/
AnvilUpdateResult onAnvilUpdate(ItemStack left, ItemStack right, ItemStack outputSlot,
String name, int baseCost, Player player);
}
/**
/**
* 铁砧更新结果
*/
public record AnvilUpdateResult(ItemStack output, int cost, int materialCost, boolean cancel) {
/**
* Cancelled anvil update result.
*
* @return the anvil update result
*/
public static AnvilUpdateResult cancelled() {
return new AnvilUpdateResult(ItemStack.EMPTY, 0, 0, true);
}
public static AnvilUpdateResult passed() {
/**
* Passed anvil update result.
*
* @return the anvil update result
*/
public static AnvilUpdateResult passed() {
return new AnvilUpdateResult(ItemStack.EMPTY, 0, 0, false);
}
public static AnvilUpdateResult withOutput(ItemStack output, int cost, int materialCost) {
/**
* With output anvil update result.
*
* @param output the output
* @param cost the cost
* @param materialCost the material cost
* @return the anvil update result
*/
public static AnvilUpdateResult withOutput(ItemStack output, int cost, int materialCost) {
return new AnvilUpdateResult(output, cost, materialCost, false);
}
/**
* Should override boolean.
*
* @return the boolean
*/
public boolean shouldOverride() {
return !output.isEmpty();
}
}
// 创建事件实例
/**
* The constant EVENT.
*/
// 创建事件实例
public static final Event<AnvilUpdate> EVENT = EventFactory.createArrayBacked(
AnvilUpdate.class,
(listeners) -> (left, right, outputSlot, name, baseCost, player) -> {

View File

@ -33,7 +33,7 @@ public interface MinecraftSetUpServiceCallback {
*
* @param services the services
* @param mainThreadExecutor the main thread executor
* @return 结果枚举
* @return 结果枚举 action result
*/
ActionResult load(Services services, Executor mainThreadExecutor);
}

View File

@ -12,9 +12,19 @@ import top.r3944realms.lib39.core.command.model.CommandNode;
import top.r3944realms.lib39.core.command.model.CommandPath;
import top.r3944realms.lib39.core.command.model.Parameter;
/**
* The interface Register command help callback.
*/
@FunctionalInterface
public interface RegisterCommandHelpCallback {
/**
* Register action result.
*
* @param registrar the registrar
* @return the action result
*/
ActionResult register(RegisterCommandHelpCallback.Registrar registrar);
/**
* 创建 Event 实例
*/
@ -30,6 +40,10 @@ public interface RegisterCommandHelpCallback {
return ActionResult.PASS;
}
);
/**
* The interface Registrar.
*/
interface Registrar {
/**
* Gets id.
@ -66,6 +80,7 @@ public interface RegisterCommandHelpCallback {
* @param description 命令描述
*/
void registerHelp(CommandNode CommandNode, MutableComponent description);
/**
* 注册命令帮助信息
*
@ -73,6 +88,7 @@ public interface RegisterCommandHelpCallback {
* @param descriptionKey 命令描述的语言键
*/
void registerHelp(CommandNode CommandNode, String descriptionKey);
/**
* 注册命令参数
*
@ -81,6 +97,10 @@ public interface RegisterCommandHelpCallback {
*/
void registerParameters(CommandPath commandPath, Parameter.Builder parametersBuilder);
}
/**
* The type Command help registrar.
*/
record CommandHelpRegistrar(LiteralArgumentBuilder<CommandSourceStack> builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
@Override
public ResourceLocation getID() {

View File

@ -21,6 +21,7 @@ public interface SyncManagerRegisterCallback {
* 注册同步管理器的回调方法
*
* @param registrar 注册器实例
* @return the action result
*/
ActionResult registerSyncManagers(Registrar registrar);
@ -47,6 +48,8 @@ public interface SyncManagerRegisterCallback {
/**
* 获取 Fabric 同步管理器实例
*
* @return the sync data 2 lookup manager
*/
SyncData2LookupManager manager();
@ -120,6 +123,10 @@ public interface SyncManagerRegisterCallback {
}
}
}
/**
* The type Sync manager registrar.
*/
record SyncManagerRegistrar(
SyncData2LookupManager manager) implements SyncManagerRegisterCallback.Registrar {

View File

@ -4,25 +4,50 @@ import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.multiplayer.ClientLevel;
/**
* The interface Client world callback.
*/
public interface ClientWorldCallback {
/**
* The constant LOAD.
*/
Event<ClientWorldCallback.Load> LOAD = EventFactory.createArrayBacked(ClientWorldCallback.Load.class, (callbacks) -> (world) -> {
for (Load callback : callbacks) {
callback.onWorldLoad(world);
}
});
/**
* The constant UNLOAD.
*/
Event<ClientWorldCallback.Unload> UNLOAD = EventFactory.createArrayBacked(ClientWorldCallback.Unload.class, (callbacks) -> (world) -> {
for (Unload callback : callbacks) {
callback.onWorldUnload(world);
}
});
/**
* The interface Unload.
*/
@FunctionalInterface
interface Unload {
/**
* On world unload.
*
* @param clientLevel the client level
*/
void onWorldUnload(ClientLevel clientLevel);
}
/**
* The interface Load.
*/
@FunctionalInterface
interface Load {
/**
* On world load.
*
* @param clientLevel the client level
*/
void onWorldLoad(ClientLevel clientLevel);
}
}

View File

@ -4,7 +4,13 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import top.r3944realms.lib39.client.renderer.block.DollBlockEntityRenderer;
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
/**
* The type Block entity renderer registry.
*/
public class BlockEntityRendererRegistry {
/**
* Register.
*/
public static void register() {
BlockEntityRenderers.register(
Lib39BlockEntities.DOLL_BLOCK_ENTITY.get(),

View File

@ -4,7 +4,13 @@ import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
import top.r3944realms.lib39.core.register.Lib39Items;
/**
* The type Item renderer registry.
*/
public class ItemRendererRegistry {
/**
* Register.
*/
public static void register() {
BuiltinItemRendererRegistry.INSTANCE.register(
Lib39Items.DOLL.get(),

View File

@ -3,7 +3,13 @@ package top.r3944realms.lib39.client;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import top.r3944realms.lib39.client.model.DollModel;
/**
* The type Layer definition registry.
*/
public class LayerDefinitionRegistry {
/**
* Register.
*/
public static void register() {
EntityModelLayerRegistry.registerModelLayer(
DollModel.LAYER_LOCATION, DollModel::createBodyLayer

View File

@ -5,7 +5,13 @@ import net.fabricmc.fabric.api.client.rendering.v1.CoreShaderRegistrationCallbac
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.client.shader.Lib39Shaders;
/**
* The type Shader registry.
*/
public class ShaderRegistry {
/**
* Register.
*/
public static void register() {
CoreShaderRegistrationCallback.EVENT.register( context -> {
context.register(

View File

@ -44,7 +44,13 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
/**
* The type Fabric common event handler.
*/
public class FabricCommonEventHandler {
/**
* The Sync data 2 manager.
*/
static volatile SyncData2LookupManager syncData2Manager;
private static boolean isSync2MInitialized = false;
private static ServerLevel sl;
@ -57,6 +63,7 @@ public class FabricCommonEventHandler {
public static ServerLevel getServerLevel() {
return sl;
}
/**
* Gets sync data 2 manager.
*
@ -65,6 +72,13 @@ public class FabricCommonEventHandler {
public static SyncData2LookupManager getSyncData2Manager() {
return syncData2Manager;
}
/**
* On server world load.
*
* @param server the server
* @param serverLevel the server level
*/
public static void onServerWorldLoad(MinecraftServer server, ServerLevel serverLevel) {
if (!serverLevel.dimension().equals(Level.OVERWORLD)) return;
synchronized (FabricCommonEventHandler.class) {
@ -80,6 +94,12 @@ public class FabricCommonEventHandler {
}
/**
* On server world un load.
*
* @param server the server
* @param serverLevel the server level
*/
public static void onServerWorldUnLoad(MinecraftServer server, @NotNull ServerLevel serverLevel) {
if (!serverLevel.dimension().equals(Level.OVERWORLD)) return;
sl = null;
@ -87,6 +107,11 @@ public class FabricCommonEventHandler {
isSync2MInitialized = false;
}
/**
* On server tick.
*
* @param server the server
*/
public static void onServerTick(MinecraftServer server) {
if (syncData2Manager == null) return;
if (server.getTickCount() % 10 == 0)
@ -94,6 +119,12 @@ public class FabricCommonEventHandler {
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
}
/**
* On entity join world.
*
* @param entity the entity
* @param level the level
*/
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
@ -104,6 +135,12 @@ public class FabricCommonEventHandler {
}
}
/**
* On entity leave world.
*
* @param entity the entity
* @param level the level
*/
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
@ -115,6 +152,7 @@ public class FabricCommonEventHandler {
}
private static final Map<Supplier<Block>, ResourceKey<CreativeModeTab>[]> itemAddMap = new ConcurrentHashMap<>();
private static final Map<ResourceKey<CreativeModeTab>, List<Supplier<Block>>> tabToItemsMap = new ConcurrentHashMap<>();
/**
* Add item to tabs.
*
@ -131,6 +169,9 @@ public class FabricCommonEventHandler {
}
}
/**
* Init common.
*/
public static void initCommon() {
try {
Class.forName("top.r3944realms.lib39.base.command.Lib39CommandHelpManager");
@ -166,7 +207,16 @@ public class FabricCommonEventHandler {
new Lib39HelpCommand(commandDispatcher, commandBuildContext);
});
}
/**
* The type Client opt.
*/
public static class ClientOpt implements IClientOnly {
/**
* On client world load.
*
* @param clientLevel the client level
*/
public static void onClientWorldLoad(@NotNull ClientLevel clientLevel) {
synchronized (FabricCommonEventHandler.ClientOpt.class) {
IClientOnly.check(() -> {
@ -180,6 +230,12 @@ public class FabricCommonEventHandler {
});
}
}
/**
* On client world un load.
*
* @param clientLevel the client level
*/
public static void onClientWorldUnLoad(@NotNull ClientLevel clientLevel) {
synchronized (FabricCommonEventHandler.ClientOpt.class) {
IClientOnly.check(() -> ILevelHelper.LevelHelper.CLIENT.setLevel(null));
@ -187,6 +243,9 @@ public class FabricCommonEventHandler {
}
}
/**
* Init client.
*/
public static void initClient() {
ClientWorldCallback.LOAD.register(ClientOpt::onClientWorldLoad);
ClientWorldCallback.LOAD.register(ClientOpt::onClientWorldUnLoad);

View File

@ -3,6 +3,9 @@ package top.r3944realms.lib39.core.network;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPacket;
/**
* The type Fabric network handler.
*/
public class FabricNetworkHandler {
/**

View File

@ -19,13 +19,23 @@ import top.r3944realms.lib39.core.sync.SyncData2Manager;
import java.util.Optional;
/**
* The type Sync nbt lookup data entity s 2 c packet.
*/
public record SyncNBTLookupDataEntityS2CPacket(int entityId, ResourceLocation id, CompoundTag data) implements FabricPacket {
/**
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
*/
public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
Lib39.rl("sync_nbt_lookup_data_entity");
/**
* The constant TYPE.
*/
public static final PacketType<SyncNBTLookupDataEntityS2CPacket> TYPE = PacketType.create(
SYNC_NBT_LOOKUP_PACKET_ID,
buf -> new SyncNBTLookupDataEntityS2CPacket(buf.readInt(), buf.readResourceLocation(), buf.readNbt())
);
/**
* Instantiates a new Sync nbt data s 2 c pack.
*
@ -50,6 +60,13 @@ public record SyncNBTLookupDataEntityS2CPacket(int entityId, ResourceLocation id
}
/**
* Receive.
*
* @param packet the packet
* @param localPlayer the local player
* @param packetSender the packet sender
*/
public static void receive(@NotNull SyncNBTLookupDataEntityS2CPacket packet, @NotNull LocalPlayer localPlayer, PacketSender packetSender) {
Level level = localPlayer.level();
Entity entity = level.getEntity(packet.entityId);

View File

@ -14,13 +14,25 @@ import java.util.function.Supplier;
* The type Lib 39 block entities.
*/
public class FabricLib39BlockEntities {
/**
* Init.
*/
@SuppressWarnings("DataFlowIssue")
public static void init() {
Lib39BlockEntities.DOLL_BLOCK_ENTITY = register("doll", BlockEntityType.Builder
.of(DollBlockEntity::new, Lib39Blocks.DOLL.get())
.of(DollBlockEntity::new, Lib39Blocks.DOLL.get(), Lib39Blocks.WALL_DOLL.get())
.build(null)
);
}
/**
* Register @ not null supplier.
*
* @param <T> the type parameter
* @param path the path
* @param blockEntityType the block entity type
* @return the @ not null supplier
*/
@Contract(pure = true)
public static <T extends BlockEntityType<?>> @NotNull Supplier<T> register(String path, T blockEntityType) {
T item = Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, Lib39.rl(path), blockEntityType);

View File

@ -7,6 +7,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.content.block.DollBlock;
import top.r3944realms.lib39.content.block.WallDollBlock;
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
import java.util.function.Supplier;
@ -15,13 +16,30 @@ import java.util.function.Supplier;
* The type Lib 39 blocks.
*/
public class FabricLib39Blocks {
public static void init() {
/**
* Init.
*/
public static void init() {
Lib39Blocks.DOLL = BlockRegistryBuilder
.create()
.withName("doll")
.registerBlock((name , block) -> register(name, block.get()), DollBlock::new)
.build();
Lib39Blocks.WALL_DOLL = BlockRegistryBuilder
.create()
.withName("wall_doll")
.registerBlock((name , block) -> register(name, block.get()), WallDollBlock::new)
.build();
}
/**
* Register @ not null supplier.
*
* @param <T> the type parameter
* @param path the path
* @param block the block
* @return the @ not null supplier
*/
@Contract(pure = true)
public static <T extends Block> @NotNull Supplier<T> register(String path, T block) {
T item = Registry.register(BuiltInRegistries.BLOCK, Lib39.rl(path), block);

View File

@ -14,9 +14,21 @@ import java.util.function.Supplier;
* The type Ex lib 39 items.
*/
public class FabricLib39Items {
/**
* Init.
*/
public static void init() {
Lib39Items.DOLL = register("doll", new DollItem(new Item.Properties()));
}
/**
* Register @ not null supplier.
*
* @param <T> the type parameter
* @param path the path
* @param item the item
* @return the @ not null supplier
*/
@Contract(pure = true)
public static <T extends Item> @NotNull Supplier<T> register(String path, T item) {
T register = Registry.register(BuiltInRegistries.ITEM, Lib39.rl(path), item);

View File

@ -13,9 +13,21 @@ import java.util.function.Supplier;
* The type Lib 39 sound events.
*/
public class FabricLib39SoundEvents {
/**
* Init.
*/
public static void init() {
Lib39SoundEvents.DUCK_TOY = register("duck_toy", SoundEvent.createFixedRangeEvent(Lib39SoundEvents.RL_DUCK_TOY, 32.0f));
}
/**
* Register @ not null supplier.
*
* @param <T> the type parameter
* @param path the path
* @param soundEvent the sound event
* @return the @ not null supplier
*/
@Contract(pure = true)
public static <T extends SoundEvent> @NotNull Supplier<T> register(String path, T soundEvent) {
T register = Registry.register(BuiltInRegistries.SOUND_EVENT, Lib39.rl(path), soundEvent);

View File

@ -2,6 +2,19 @@ package top.r3944realms.lib39.core.sync;
import net.minecraft.world.entity.Entity;
/**
* The interface Entity api look up impl extend.
*
* @param <A> the type parameter
* @param <C> the type parameter
*/
public interface IEntityApiLookUpImplExtend<A, C> {
/**
* Lib 39 find without check a.
*
* @param entity the entity
* @param context the context
* @return the a
*/
A lib39$findWithoutCheck(Entity entity, C context);
}

View File

@ -9,6 +9,9 @@ import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPac
import java.util.List;
/**
* The interface Fabric update.
*/
public interface IFabricUpdate extends IUpdate {
default void update() {
ServerLevel serverLevel = FabricCommonEventHandler.getServerLevel();

View File

@ -5,9 +5,30 @@ import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
/**
* The interface Lib 39 sync data holder.
*/
public interface ILib39SyncDataHolder {
/**
* Lib 39 get sync data compound tag.
*
* @return the compound tag
*/
CompoundTag lib39$getSyncData();
/**
* Lib 39 set sync data.
*
* @param tag the tag
*/
void lib39$setSyncData(CompoundTag tag);
/**
* Lib 39 inject save sync data compound tag.
*
* @param tag the tag
* @return the compound tag
*/
default CompoundTag lib39$injectSaveSyncData(CompoundTag tag) {
if (lib39$getSyncData() != null && !lib39$getSyncData().isEmpty()) {
tag.put("Lib39Data", lib39$getSyncData());
@ -15,22 +36,43 @@ public interface ILib39SyncDataHolder {
return tag;
}
/**
* Lib 39 inject load sync data.
*
* @param tag the tag
*/
default void lib39$injectLoadSyncData(@NotNull CompoundTag tag) {
if (tag.contains("Lib39Data", Tag.TAG_COMPOUND)) {
lib39$setSyncData(tag.getCompound("Lib39Data"));
}
}
/**
* Save sync data.
*
* @param syncData the sync data
*/
default void saveSyncData(@NotNull NBTEntitySyncData syncData) {
lib39$getSyncData().put(syncData.id.toDebugFileName(), syncData.serializeNBT());
}
/**
* Load sync data.
*
* @param syncData the sync data
*/
default void loadSyncData(NBTEntitySyncData syncData) {
if (syncData != null && lib39$getSyncData().contains(syncData.id.toDebugFileName())) {
syncData.deserializeNBT(lib39$getSyncData().getCompound(syncData.id.toDebugFileName()));
}
}
/**
* Gets holder.
*
* @param entity the entity
* @return the holder
*/
static ILib39SyncDataHolder getHolder(Entity entity) {
return (ILib39SyncDataHolder) entity;
}

View File

@ -10,7 +10,13 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* The type Sync data 2 lookup manager.
*/
public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupManager.TypedSyncEntry<? extends ISyncData<?>>> {
/**
* The Typed entries.
*/
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
@Override
@ -18,12 +24,17 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
return typedEntries;
}
/**
* The type Typed sync entry.
*
* @param <T> the type parameter
*/
protected static class TypedSyncEntry<T extends ISyncData<?>> extends SyncData2Manager.TypedSyncEntry<Entity, T> {
/**
* Instantiates a new Typed sync entry for Fabric
*
* @param manager the manager
* @param apiLookup the EntityApiLookup instance
* @param manager the manager
* @param apiLookup the EntityApiLookup instance
*/
@SuppressWarnings("unchecked")
public TypedSyncEntry(ISyncManager<Entity, T> manager, @Nullable EntityApiLookup<T, Void> apiLookup) {
@ -40,10 +51,10 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
/**
* 使用自定义提供器注册管理器
*
* @param <T> the type parameter
* @param key the key
* @param manager the manager
* @param dataClass the data class
* @param <T> the type parameter
* @param key the key
* @param manager the manager
* @param dataClass the data class
*/
public <T extends ISyncData<?>> void registerManager(
ResourceLocation key,
@ -62,9 +73,9 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
/**
* 绑定 EntityApiLookup用于分离注册的情况
*
* @param <T> the type parameter
* @param key the key
* @param apiLookup the EntityApiLookup
* @param <T> the type parameter
* @param key the key
* @param apiLookup the EntityApiLookup
*/
public <T extends ISyncData<?>> void bindApiLookup(ResourceLocation key, EntityApiLookup<T, Void> apiLookup) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
@ -94,6 +105,11 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
/**
* 更新条目的 EntityApiLookup
*
* @param <T> the type parameter
* @param id the id
* @param entry the entry
* @param newApiLookup the new api lookup
*/
protected <T extends ISyncData<?>> void updateApiLookupInEntry(
ResourceLocation id,

View File

@ -6,8 +6,25 @@ import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
/**
* The type Sync lookup provider.
*
* @param <T> the type parameter
*/
public abstract class SyncLookupProvider<T extends NBTEntitySyncData> implements EntityApiLookup.EntityApiProvider<T, Void> {
/**
* Create empty lookup t.
*
* @param entity the entity
* @return the t
*/
protected abstract T createEmptyLookup(Entity entity);
/**
* Gets id.
*
* @return the id
*/
protected abstract ResourceLocation getId();
@SuppressWarnings("unchecked")
@Override

View File

@ -6,8 +6,12 @@ import top.r3944realms.lib39.example.core.event.FabricExCommonEventHandler;
import top.r3944realms.lib39.example.core.network.FabricExNetworkHandler;
import top.r3944realms.lib39.example.core.register.FabricExLib39Items;
/**
* The type Fabric lib 39 example.
*/
public class FabricLib39Example {
private static boolean registered = false;
/**
* Instantiates a new Lib 39 example.
*/
@ -17,6 +21,10 @@ public class FabricLib39Example {
registered = true;
}
}
/**
* Init.
*/
public void init() {
FabricExCommonEventHandler.init();
FabricExLib39Items.init();

View File

@ -4,7 +4,13 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
/**
* The type Fabric test sync lookup provider.
*/
public class FabricTestSyncLookupProvider extends SyncLookupProvider<AbstractedTestSyncData> {
/**
* The constant INSTANCE.
*/
public static final FabricTestSyncLookupProvider INSTANCE = new FabricTestSyncLookupProvider();
@Override

View File

@ -13,8 +13,16 @@ import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
import top.r3944realms.lib39.example.content.data.FabricTestSyncData;
import top.r3944realms.lib39.example.core.network.FabricClientDataPacket;
/**
* The type Fabric fabric item.
*/
public class FabricFabricItem extends AbstractFabricItem {
/**
* Instantiates a new Fabric fabric item.
*
* @param properties the properties
*/
public FabricFabricItem(Properties properties) {
super(properties);
}
@ -31,6 +39,12 @@ public class FabricFabricItem extends AbstractFabricItem {
}
}
/**
* Gets static data.
*
* @param target the target
* @return the static data
*/
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
try {
AbstractedTestSyncData abstractData = EntityApiLookup.get(FabricTestSyncData.ID, AbstractedTestSyncData.class, Void.class).find(target, null);
@ -43,6 +57,13 @@ public class FabricFabricItem extends AbstractFabricItem {
return null;
}
/**
* Handle client data from packet.
*
* @param player the player
* @param clientData the client data
* @param targetEntityId the target entity id
*/
public static void handleClientDataFromPacket(@NotNull ServerPlayer player, AbstractedTestSyncData clientData, int targetEntityId) {
Entity target = player.level().getEntity(targetEntityId);

View File

@ -5,8 +5,16 @@ import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
import top.r3944realms.lib39.example.content.data.FabricTestSyncData;
/**
* The type Fabric neo forge item.
*/
public class FabricNeoForgeItem extends AbstractNeoForgeItem {
/**
* Instantiates a new Fabric neo forge item.
*
* @param properties the properties
*/
public FabricNeoForgeItem(Properties properties) {
super(properties);
}

View File

@ -9,7 +9,10 @@ import top.r3944realms.lib39.core.compat.ICompat;
* The type Lib 39 compat.
*/
public class FabricLib39Compat implements ICompat {
boolean initialized = false;
/**
* The Initialized.
*/
boolean initialized = false;
/**
* The constant INSTANCE.
*/

View File

@ -3,6 +3,9 @@ package top.r3944realms.lib39.example.core.compat;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.compat.CompatManager;
/**
* The type Fabric lib 39 compat manager.
*/
public class FabricLib39CompatManager extends CompatManager {
/**
* Instantiates a new Compat manager.

View File

@ -14,6 +14,9 @@ import top.r3944realms.lib39.example.core.compat.FabricLib39CompatManager;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* The type Fabric ex common event handler.
*/
public class FabricExCommonEventHandler {
/**
* Gets compat manager.
@ -35,6 +38,10 @@ public class FabricExCommonEventHandler {
* The Compat manager.
*/
static volatile CompatManager compatManager;
/**
* Init.
*/
public static void init() {
SyncManagerRegisterCallback.EVENT.register(registrar -> {
registrar.register(

View File

@ -16,8 +16,14 @@ import top.r3944realms.lib39.example.content.item.FabricFabricItem;
* The type Client data packet.
*/
public class FabricClientDataPacket implements FabricPacket {
/**
* The constant CLIENT_TEST_DATA.
*/
public static final ResourceLocation CLIENT_TEST_DATA =
Lib39.rl("client_test_data");
/**
* The constant TYPE.
*/
public static final PacketType<FabricClientDataPacket> TYPE = PacketType.create(
CLIENT_TEST_DATA,
FabricClientDataPacket::new
@ -58,6 +64,13 @@ public class FabricClientDataPacket implements FabricPacket {
return TYPE;
}
/**
* Receive.
*
* @param packet the packet
* @param serverPlayer the server player
* @param packetSender the packet sender
*/
public static void receive(@NotNull FabricClientDataPacket packet, @NotNull ServerPlayer serverPlayer, PacketSender packetSender) {
FabricFabricItem.handleClientDataFromPacket(serverPlayer, packet.clientData, packet.targetEntityId);
}

View File

@ -2,6 +2,9 @@ package top.r3944realms.lib39.example.core.network;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
/**
* The type Fabric ex network handler.
*/
public class FabricExNetworkHandler {
/**
* 注册服务器接收的数据包

View File

@ -10,6 +10,9 @@ import top.r3944realms.lib39.example.content.item.ForgeItem;
* The type Ex lib 39 items.
*/
public class FabricExLib39Items {
/**
* Init.
*/
public static void init() {
ExLib39Items.FABRIC = FabricLib39Items.register("fabric", new FabricFabricItem(
new Item.Properties()

View File

@ -14,6 +14,12 @@ import top.r3944realms.lib39.core.sync.IEntityApiLookUpImplExtend;
import java.util.List;
import java.util.Objects;
/**
* The type Mixin api look up.
*
* @param <A> the type parameter
* @param <C> the type parameter
*/
@SuppressWarnings("UnstableApiUsage")
@Mixin(value = EntityApiLookupImpl.class, remap = false)
public class MixinApiLookUpImpl<A, C> implements IEntityApiLookUpImplExtend<A, C> {

View File

@ -15,8 +15,16 @@ import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
import java.util.UUID;
/**
* The type Mixin entity.
*/
@Mixin(Entity.class)
public abstract class MixinEntity implements ILib39SyncDataHolder {
/**
* Gets uuid.
*
* @return the uuid
*/
@Shadow public abstract UUID getUUID();
@Unique

View File

@ -13,6 +13,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import top.r3944realms.lib39.api.callback.AnvilUpdateCallback;
/**
* The type Mixin anvil menu.
*/
@Mixin(AnvilMenu.class)
public abstract class MixinAnvilMenu extends AbstractContainerMenu {
@Shadow
@ -25,6 +28,12 @@ public abstract class MixinAnvilMenu extends AbstractContainerMenu {
@Unique
private Player cachedPlayer;
/**
* Instantiates a new Mixin anvil menu.
*
* @param menuType the menu type
* @param containerId the container id
*/
protected MixinAnvilMenu(@Nullable MenuType<?> menuType, int containerId) {
super(menuType, containerId);
}

View File

@ -26,6 +26,9 @@ import javax.annotation.Nullable;
*/
@Mixin(Minecraft.class)
public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnable> implements WindowEventHandler {
/**
* The Level.
*/
@Shadow @Nullable public ClientLevel level;
/**
@ -36,16 +39,30 @@ public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnabl
public MixinMinecraft(String name) {
super(name);
}
/**
* Set level callback.
*
* @param levelClient the level client
* @param original the original
*/
@WrapMethod(method = "setLevel")
public void setLevel$callback(ClientLevel levelClient, Operation<Void> original) {
if (levelClient != null) ClientWorldCallback.UNLOAD.invoker().onWorldUnload(levelClient);
original.call(levelClient);
}
/**
* Clear level callback.
*
* @param original the original
*/
@WrapMethod(method = "clearLevel()V")
public void clearLevel$callback(Operation<Void> original) {
if (level != null) ClientWorldCallback.UNLOAD.invoker().onWorldUnload(level);
original.call();
}
/**
* Set level setup.
*

View File

@ -18,8 +18,24 @@ import top.r3944realms.lib39.api.callback.client.ClientWorldCallback;
import java.util.function.Supplier;
/**
* The type Mixin client level.
*/
@Mixin(ClientLevel.class)
public abstract class MixinClientLevel extends Level {
/**
* Instantiates a new Mixin client level.
*
* @param levelData the level data
* @param dimension the dimension
* @param registryAccess the registry access
* @param dimensionTypeRegistration the dimension type registration
* @param profiler the profiler
* @param isClientSide the is client side
* @param isDebug the is debug
* @param biomeZoomSeed the biome zoom seed
* @param maxChainedNeighborUpdates the max chained neighbor updates
*/
protected MixinClientLevel(WritableLevelData levelData, ResourceKey<Level> dimension, RegistryAccess registryAccess, Holder<DimensionType> dimensionTypeRegistration, Supplier<ProfilerFiller> profiler, boolean isClientSide, boolean isDebug, long biomeZoomSeed, int maxChainedNeighborUpdates) {
super(levelData, dimension, registryAccess, dimensionTypeRegistration, profiler, isClientSide, isDebug, biomeZoomSeed, maxChainedNeighborUpdates);
}

View File

@ -7,7 +7,13 @@ import top.r3944realms.lib39.api.callback.RegisterCommandHelpCallback;
import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.platform.services.IHelpCommandHook;
/**
* The enum Fabric help command hook.
*/
public enum FabricHelpCommandHook implements IHelpCommandHook {
/**
* Instance fabric help command hook.
*/
INSTANCE;
@Override

View File

@ -11,6 +11,9 @@ import top.r3944realms.lib39.platform.services.IUtilHelper;
import java.util.Objects;
/**
* The type Fabric platform helper.
*/
public class FabricPlatformHelper implements IPlatformHelper {
@Override

View File

@ -4,7 +4,13 @@ import top.r3944realms.lib39.platform.services.IUtilHelper;
import top.r3944realms.lib39.util.FabricBlockRegistryBuilder;
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
/**
* The enum Fabric util helper.
*/
public enum FabricUtilHelper implements IUtilHelper {
/**
* Instance fabric util helper.
*/
INSTANCE;
@Override
public BlockRegistryBuilder getBlockRegistryBuilder() {

View File

@ -8,6 +8,9 @@ import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
import java.util.function.Supplier;
/**
* The type Fabric block registry builder.
*/
public class FabricBlockRegistryBuilder extends BlockRegistryBuilder {
@SafeVarargs
@Override

View File

@ -22,6 +22,7 @@ legacyForge {
validateAccessTransformers = true
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
def generated = project(':common').file('src/generated/resources/')
if (at.exists()) {
accessTransformers = ["src/main/resources/META-INF/accesstransformer.cfg"]
}

View File

@ -13,6 +13,6 @@ public class Lib39BlockLootTable extends BlockLootTables {
*/
public Lib39BlockLootTable() {
super(ForgeLib39Blocks.BLOCKS);
dropSelf(Lib39Blocks.DOLL);
dropSelf(Lib39Blocks.DOLL, Lib39Blocks.WALL_DOLL);
}
}

View File

@ -3,7 +3,6 @@ package top.r3944realms.lib39.base.datagen.provider;
import net.minecraft.core.Direction;
import net.minecraft.data.PackOutput;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ModelFile;
@ -39,15 +38,16 @@ public class Lib39BlockStatesProvider extends BlockStateProvider {
models().existingFileHelper
);
getVariantBuilder(doll).forAllStates(state -> {
Direction direction = state.getValue(BlockStateProperties.HORIZONTAL_FACING);
int rotationY = getMainNorthRotationY(direction);
getVariantBuilder(doll).forAllStates(state -> ConfiguredModel.builder()
.modelFile(modelFile)
.build());
Block wallDoll = Lib39Blocks.WALL_DOLL.get();
getVariantBuilder(wallDoll).forAllStates(state -> ConfiguredModel.builder()
.modelFile(modelFile)
.build());
return ConfiguredModel.builder()
.modelFile(modelFile)
.rotationY(rotationY)
.build();
});
}
@Contract(pure = true)

View File

@ -7,7 +7,15 @@ import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
import java.util.function.Consumer;
/**
* The type Forge doll item.
*/
public class ForgeDollItem extends DollItem {
/**
* Instantiates a new Forge doll item.
*
* @param properties the properties
*/
public ForgeDollItem(Properties properties) {
super(properties);
}

View File

@ -19,11 +19,30 @@ import java.util.function.Consumer;
*/
@SuppressWarnings("unused")
public abstract class ForgeCompatManager extends CompatManager {
protected final IEventBus modEventBus, gameEventBus;
/**
* The Mod event bus.
*/
protected final IEventBus modEventBus, /**
* The Game event bus.
*/
gameEventBus;
/**
* The Compats.
*/
protected final Map<ResourceLocation, IForgeCompat> compats = new HashMap<>();
// 存储事件监听器配置
/**
* The Listener configs.
*/
// 存储事件监听器配置
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
/**
* Instantiates a new Forge compat manager.
*
* @param id the id
* @param modEventBus the mod event bus
* @param gameEventBus the game event bus
*/
public ForgeCompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
super(id);
this.modEventBus = modEventBus;
@ -223,6 +242,9 @@ public abstract class ForgeCompatManager extends CompatManager {
addListenerForCompat(compatId, null, bus);
}
/**
* The type Listener config.
*/
protected static class ListenerConfig {
/**
* The Compat id.

View File

@ -30,6 +30,7 @@ public class ClientEventHandler {
* On register shaders.
*
* @param event the event
* @throws IOException the io exception
*/
@SubscribeEvent
public static void onRegisterShaders(RegisterShadersEvent event) throws IOException {

View File

@ -220,6 +220,7 @@ public class CommonEventHandler {
public static class Mod extends CommonEventHandler {
private static final Map<Supplier<Block>, ResourceKey<CreativeModeTab>[]> itemAddMap = new ConcurrentHashMap<>();
private static final Map<ResourceKey<CreativeModeTab>, List<Supplier<Block>>> tabToItemsMap = new ConcurrentHashMap<>();
/**
* On fml common setup.
*

View File

@ -20,7 +20,7 @@ public class ForgeLib39BlockEntities {
//noinspection DataFlowIssue
Lib39BlockEntities.DOLL_BLOCK_ENTITY = BLOCK_ENTITY_TYPES.register("doll",
() -> BlockEntityType.Builder
.of(DollBlockEntity::new, Lib39Blocks.DOLL.get())
.of(DollBlockEntity::new, Lib39Blocks.DOLL.get(), Lib39Blocks.WALL_DOLL.get())
.build(null)
);
}

View File

@ -6,6 +6,7 @@ import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.content.block.DollBlock;
import top.r3944realms.lib39.content.block.WallDollBlock;
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
/**
@ -23,8 +24,14 @@ public class ForgeLib39Blocks {
.withName("doll")
.registerBlock(BLOCKS::register, DollBlock::new)
.build();
Lib39Blocks.WALL_DOLL = BlockRegistryBuilder
.create()
.withName("wall_doll")
.registerBlock(BLOCKS::register, WallDollBlock::new)
.build();
}
/**
* Register.
*

View File

@ -3,6 +3,9 @@ package top.r3944realms.lib39.core.sync;
import top.r3944realms.lib39.core.network.NetworkHandler;
import top.r3944realms.lib39.core.network.toClient.SyncNBTCapDataEntityS2CPacket;
/**
* The interface Forge update.
*/
public interface IForgeUpdate extends IUpdate {
default void update() {
NetworkHandler.sendToAllPlayer(new SyncNBTCapDataEntityS2CPacket(getSyncData().entityId(), getSyncData().id, getSyncData().serializeNBT()));

View File

@ -14,6 +14,9 @@ import java.util.Optional;
*/
@SuppressWarnings("unused")
public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.TypedSyncEntry<? extends ISyncData<?>>> {
/**
* The Typed entries.
*/
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
@Override
@ -21,6 +24,11 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
return typedEntries;
}
/**
* The type Typed sync entry.
*
* @param <T> the type parameter
*/
protected static class TypedSyncEntry<T extends ISyncData<?>> extends SyncData2Manager.TypedSyncEntry<Capability<T>, T> {
/**
* Instantiates a new Typed sync entry.
@ -87,6 +95,14 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
}
}
/**
* Update capability in entry.
*
* @param <T> the type parameter
* @param id the id
* @param entry the entry
* @param newCapability the new capability
*/
protected <T extends ISyncData<?>> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry<?> entry, Capability<T> newCapability) {
updateDataProviderInEntry(id, entry, key -> newCapability != null ? key.getCapability(newCapability).resolve() : Optional.empty());
}

View File

@ -7,8 +7,12 @@ import top.r3944realms.lib39.example.core.event.ExCommonEventHandler;
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
import top.r3944realms.lib39.example.core.register.ForgeExLib39Items;
/**
* The type Forge lib 39 example.
*/
public class ForgeLib39Example {
private static boolean registered = false;
/**
* Instantiates a new Lib 39 example.
*/
@ -19,6 +23,10 @@ public class ForgeLib39Example {
registered = true;
}
}
/**
* Init.
*/
public void init() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ForgeExLib39Items.register(modEventBus);

View File

@ -12,7 +12,10 @@ import top.r3944realms.lib39.core.compat.IForgeCompat;
* The type Lib 39 compat.
*/
public class Lib39Compat implements IForgeCompat {
boolean initialized = false;
/**
* The Initialized.
*/
boolean initialized = false;
/**
* The constant INSTANCE.
*/

View File

@ -4,11 +4,14 @@ import net.minecraftforge.eventbus.api.IEventBus;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.compat.ForgeCompatManager;
/**
* The type Lib 39 compat manager.
*/
public class Lib39CompatManager extends ForgeCompatManager {
/**
* Instantiates a new Compat manager.
*
* @param path the path
* @param path the path
* @param modEventBus the mod event bus
* @param gameEventBus the game event bus
*/

View File

@ -13,8 +13,16 @@ import top.r3944realms.lib39.example.content.data.TestSyncData;
import top.r3944realms.lib39.example.core.network.ClientDataPacket;
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
/**
* The type Forge fabric item.
*/
public class ForgeFabricItem extends AbstractFabricItem {
/**
* Instantiates a new Forge fabric item.
*
* @param properties the properties
*/
public ForgeFabricItem(Properties properties) {
super(properties);
}
@ -29,6 +37,12 @@ public class ForgeFabricItem extends AbstractFabricItem {
ExNetworkHandler.INSTANCE.sendToServer(new ClientDataPacket(clientData, targetEntityId));
}
/**
* Gets static data.
*
* @param target the target
* @return the static data
*/
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
try {
AbstractedTestSyncData abstractData = target.getCapability(ExCapabilityHandler.TEST_CAP).resolve().orElse(null);
@ -41,6 +55,13 @@ public class ForgeFabricItem extends AbstractFabricItem {
return null;
}
/**
* Handle client data from packet.
*
* @param player the player
* @param clientData the client data
* @param targetEntityId the target entity id
*/
public static void handleClientDataFromPacket(@NotNull ServerPlayer player, AbstractedTestSyncData clientData, int targetEntityId) {
Entity target = player.level().getEntity(targetEntityId);

View File

@ -7,8 +7,16 @@ import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
import top.r3944realms.lib39.example.content.data.ExCapabilityHandler;
import top.r3944realms.lib39.example.content.data.TestSyncData;
/**
* The type Forge neo forge item.
*/
public class ForgeNeoForgeItem extends AbstractNeoForgeItem{
/**
* Instantiates a new Forge neo forge item.
*
* @param properties the properties
*/
public ForgeNeoForgeItem(Properties properties) {
super(properties);
}
@ -17,6 +25,13 @@ public class ForgeNeoForgeItem extends AbstractNeoForgeItem{
protected AbstractedTestSyncData getData(Entity entity) {
return getStaticData(entity);
}
/**
* Gets static data.
*
* @param target the target
* @return the static data
*/
@SuppressWarnings("JavaExistingMethodCanBeUsed")
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
try {

View File

@ -71,7 +71,11 @@ public class ExCommonEventHandler {
* The type Mod.
*/
public static class Mod extends ExCommonEventHandler {
/**
* The constant EVENT_BUS.
*/
public static final IEventBus EVENT_BUS = FMLJavaModLoadingContext.get().getModEventBus();
/**
* Gets compat manager.
*

View File

@ -8,7 +8,13 @@ import top.r3944realms.lib39.api.event.RegisterCommandHelpEvent;
import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.platform.services.IHelpCommandHook;
/**
* The enum Forge help command hook.
*/
public enum ForgeHelpCommandHook implements IHelpCommandHook {
/**
* Instance forge help command hook.
*/
INSTANCE;
@Override

View File

@ -8,6 +8,9 @@ import top.r3944realms.lib39.platform.services.IHelpCommandHook;
import top.r3944realms.lib39.platform.services.IPlatformHelper;
import top.r3944realms.lib39.platform.services.IUtilHelper;
/**
* The type Forge platform helper.
*/
public class ForgePlatformHelper implements IPlatformHelper {
@Override

View File

@ -4,7 +4,13 @@ import top.r3944realms.lib39.platform.services.IUtilHelper;
import top.r3944realms.lib39.util.ForgeBlockRegistryBuilder;
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
/**
* The enum Forge util helper.
*/
public enum ForgeUtilHelper implements IUtilHelper {
/**
* Instance forge util helper.
*/
INSTANCE;
@Override
public BlockRegistryBuilder getBlockRegistryBuilder() {

View File

@ -8,6 +8,9 @@ import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
import java.util.function.Supplier;
/**
* The type Forge block registry builder.
*/
public class ForgeBlockRegistryBuilder extends BlockRegistryBuilder {
@SafeVarargs
@Override