diff --git a/src/main/java/ru/betterend/blocks/EndPedestal.java b/src/main/java/ru/betterend/blocks/EndPedestal.java index 2478b1b1..b0106f95 100644 --- a/src/main/java/ru/betterend/blocks/EndPedestal.java +++ b/src/main/java/ru/betterend/blocks/EndPedestal.java @@ -1,12 +1,12 @@ package ru.betterend.blocks; +import com.google.common.collect.Maps; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.PedestalBlock; -import java.util.HashMap; import java.util.Map; public class EndPedestal extends PedestalBlock { @@ -19,16 +19,12 @@ public class EndPedestal extends PedestalBlock { protected Map createTexturesMap() { ResourceLocation blockId = Registry.BLOCK.getKey(parent); String name = blockId.getPath(); - return new HashMap() { - private static final long serialVersionUID = 1L; - - { - put("%mod%", BetterEnd.MOD_ID); - put("%top%", name + "_polished"); - put("%base%", name + "_polished"); - put("%pillar%", name + "_pillar_side"); - put("%bottom%", name + "_polished"); - } - }; + Map textures = Maps.newHashMap(); + textures.put("%mod%", BetterEnd.MOD_ID); + textures.put("%top%", name + "_polished"); + textures.put("%base%", name + "_polished"); + textures.put("%pillar%", name + "_pillar_side"); + textures.put("%bottom%", name + "_polished"); + return textures; } } diff --git a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java index 784377f5..1b9720ef 100644 --- a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java @@ -1,6 +1,7 @@ package ru.betterend.blocks.basis; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -23,8 +24,6 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; @@ -45,17 +44,14 @@ import ru.betterend.blocks.InfusionPedestal; import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.PedestalBlockEntity; import ru.betterend.client.models.Patterns; -import ru.betterend.registry.EndBlocks; import ru.betterend.rituals.InfusionRitual; import java.awt.Point; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.ToIntFunction; -@SuppressWarnings({"deprecation"}) public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { public final static EnumProperty STATE = EndBlockProperties.PEDESTAL_STATE; public static final BooleanProperty HAS_ITEM = EndBlockProperties.HAS_ITEM; @@ -68,37 +64,18 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { private static final VoxelShape SHAPE_COLUMN_TOP; private static final VoxelShape SHAPE_BOTTOM; - /** - * Register new Pedestal block with Better End mod id. - * - * @param name pedestal name - * @param source source block - * @return new Pedestal block with Better End id. - */ - public static Block registerPedestal(String name, Block source) { - return EndBlocks.registerBlock(name, new PedestalBlock(source)); - } - - /** - * Register new Pedestal block with specified mod id. - * - * @param id pedestal id - * @param source source block - * @return new Pedestal block with specified id. - */ - public static Block registerPedestal(ResourceLocation id, Block source) { - return EndBlocks.registerBlock(id, new PedestalBlock(source)); - } - protected final Block parent; protected float height = 1.0F; public PedestalBlock(Block parent) { super(FabricBlockSettings.copyOf(parent).luminance(getLuminance(parent.defaultBlockState()))); - this.registerDefaultState(stateDefinition.any() - .setValue(STATE, PedestalState.DEFAULT) - .setValue(HAS_ITEM, false) - .setValue(HAS_LIGHT, false)); + this.registerDefaultState( + stateDefinition + .any() + .setValue(STATE, PedestalState.DEFAULT) + .setValue(HAS_ITEM, false) + .setValue(HAS_LIGHT, false) + ); this.parent = parent; } @@ -118,28 +95,29 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { } @Override - @Deprecated - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if (world.isClientSide || !state.is(this)) return InteractionResult.CONSUME; - if (!isPlaceable(state)) { + @SuppressWarnings("deprecation") + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (!state.is(this) || !isPlaceable(state)) { return InteractionResult.PASS; } - BlockEntity blockEntity = world.getBlockEntity(pos); + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof PedestalBlockEntity) { PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; if (pedestal.isEmpty()) { ItemStack itemStack = player.getItemInHand(hand); if (itemStack.isEmpty()) return InteractionResult.CONSUME; pedestal.setItem(0, itemStack); - checkRitual(world, pos); - return InteractionResult.SUCCESS; + level.blockEntityChanged(pos); + checkRitual(level, pos); + return InteractionResult.SUCCESS;//InteractionResult.sidedSuccess(level.isClientSide()); } else { ItemStack itemStack = pedestal.getItem(0); if (player.addItem(itemStack)) { pedestal.removeItemNoUpdate(0); - checkRitual(world, pos); - return InteractionResult.SUCCESS; + level.blockEntityChanged(pos); + checkRitual(level, pos); + return InteractionResult.SUCCESS;//InteractionResult.sidedSuccess(level.isClientSide()); } return InteractionResult.FAIL; } @@ -207,7 +185,7 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { } @Override - @Deprecated + @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom); if (!updated.is(this)) return updated; @@ -344,7 +322,7 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { } @Override - @Deprecated + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { if (state.is(this)) { switch (state.getValue(STATE)) { @@ -386,13 +364,13 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { } @Override - @Deprecated + @SuppressWarnings("deprecation") public boolean hasAnalogOutputSignal(BlockState state) { return state.getBlock() instanceof PedestalBlock; } @Override - @Deprecated + @SuppressWarnings("deprecation") public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { return state.getValue(HAS_ITEM) ? 15 : 0; } @@ -446,17 +424,13 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { protected Map createTexturesMap() { ResourceLocation blockId = Registry.BLOCK.getKey(parent); String name = blockId.getPath(); - return new HashMap() { - private static final long serialVersionUID = 1L; - - { - put("%mod%", blockId.getNamespace()); - put("%top%", name + "_top"); - put("%base%", name + "_base"); - put("%pillar%", name + "_pillar"); - put("%bottom%", name + "_bottom"); - } - }; + Map textures = Maps.newHashMap(); + textures.put("%mod%", blockId.getNamespace()); + textures.put("%top%", name + "_top"); + textures.put("%base%", name + "_base"); + textures.put("%pillar%", name + "_pillar"); + textures.put("%bottom%", name + "_bottom"); + return textures; } static { @@ -478,9 +452,9 @@ public class PedestalBlock extends BaseBlockNotFull implements EntityBlock { SHAPE_BOTTOM = Shapes.or(basin, SHAPE_PILLAR); } - @Override + /*@Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { return level.isClientSide() ? PedestalBlockEntity::tick : null; - } + }*/ } diff --git a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java index 8d678176..47420b67 100644 --- a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java @@ -62,7 +62,7 @@ public class InfusionPedestalEntity extends PedestalBlockEntity { if (blockEntity.hasRitual()) { blockEntity.linkedRitual.tick(); } - PedestalBlockEntity.tick(level, blockPos, blockState, blockEntity); + //PedestalBlockEntity.tick(level, blockPos, blockState, blockEntity); } } } diff --git a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java index 4a581bcf..06c3ff73 100644 --- a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java @@ -1,12 +1,13 @@ package ru.betterend.blocks.entities; //import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; + import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -18,8 +19,8 @@ import ru.betterend.registry.EndItems; public class PedestalBlockEntity extends BlockEntity implements Container/*, BlockEntityClientSerializable*/ { private ItemStack activeItem = ItemStack.EMPTY; - private final int maxAge = 314; - private int age; + //private final int maxAge = 314; + //private int age; public PedestalBlockEntity(BlockPos blockPos, BlockState blockState) { this(EndBlockEntities.PEDESTAL, blockPos, blockState); @@ -29,13 +30,13 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo super(blockEntityType, blockPos, blockState); } - public int getAge() { + /*public int getAge() { return age; - } + }*/ - public int getMaxAge() { + /*public int getMaxAge() { return maxAge; - } + }*/ @Override public int getContainerSize() { @@ -99,7 +100,6 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo super.setChanged(); } - @Override public boolean stillValid(Player player) { return true; @@ -111,22 +111,12 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo fromTag(tag); } - /*@Override - public CompoundTag save(CompoundTag tag) { - tag.put("active_item", activeItem.save(new CompoundTag())); - return super.save(tag); - } - @Override - public void fromClientTag(CompoundTag tag) { + protected void saveAdditional(CompoundTag tag) { + super.saveAdditional(tag); fromTag(tag); } - @Override - public CompoundTag toClientTag(CompoundTag tag) { - return save(tag); - }*/ - protected void fromTag(CompoundTag tag) { if (tag.contains("active_item")) { CompoundTag itemTag = tag.getCompound("active_item"); @@ -134,16 +124,26 @@ public class PedestalBlockEntity extends BlockEntity implements Container/*, Blo } } - public static void tick(Level level, BlockPos blockPos, BlockState blockState, T uncastedEntity) { + /*public static void tick(Level level, BlockPos blockPos, BlockState blockState, T uncastedEntity) { clientTick(level, blockPos, blockState, (PedestalBlockEntity) uncastedEntity); - } + }*/ - private static void clientTick(Level tickLevel, BlockPos tickPos, BlockState tickState, PedestalBlockEntity blockEntity) { + /*private static void clientTick(Level tickLevel, BlockPos tickPos, BlockState tickState, PedestalBlockEntity blockEntity) { if (!blockEntity.isEmpty()) { blockEntity.age++; if (blockEntity.age > blockEntity.maxAge) { blockEntity.age = 0; } } + }*/ + + @Override + public ClientboundBlockEntityDataPacket getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + + @Override + public CompoundTag getUpdateTag() { + return this.saveWithoutMetadata(); } } diff --git a/src/main/java/ru/betterend/client/render/PedestalItemRenderer.java b/src/main/java/ru/betterend/client/render/PedestalItemRenderer.java index 4edb08c8..9b19e613 100644 --- a/src/main/java/ru/betterend/client/render/PedestalItemRenderer.java +++ b/src/main/java/ru/betterend/client/render/PedestalItemRenderer.java @@ -24,7 +24,6 @@ import ru.betterend.registry.EndItems; @Environment(EnvType.CLIENT) public class PedestalItemRenderer implements BlockEntityRenderer { - public PedestalItemRenderer(BlockEntityRendererProvider.Context ctx) { super(); } @@ -41,7 +40,6 @@ public class PedestalItemRenderer implements Bloc matrices.pushPose(); Minecraft minecraft = Minecraft.getInstance(); - //TODO: check i=0 BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null, 0); Vector3f translate = model.getTransforms().ground.translation; PedestalBlock pedestal = (PedestalBlock) state.getBlock(); @@ -52,28 +50,17 @@ public class PedestalItemRenderer implements Bloc else { matrices.scale(1.25F, 1.25F, 1.25F); } - int age = blockEntity.getAge(); + int age = (int) (minecraft.level.getGameTime() % 314); if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) { float[] colors = EternalCrystalRenderer.colors(age); int y = blockEntity.getBlockPos().getY(); - BeamRenderer.renderLightBeam( - matrices, - vertexConsumers, - age, - tickDelta, - -y, - 1024 - y, - colors, - 0.25F, - 0.13F, - 0.16F - ); - float altitude = Mth.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F; + BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, 0.16F); + float altitude = Mth.sin((age + tickDelta) / 10.0F) * 0.1F + 0.1F; matrices.translate(0.0D, altitude, 0.0D); } if (activeItem.getItem() == Items.END_CRYSTAL) { - EndCrystalRenderer.render(age, blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light); + EndCrystalRenderer.render(age, 314, tickDelta, matrices, vertexConsumers, light); } else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) { EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light); @@ -81,16 +68,7 @@ public class PedestalItemRenderer implements Bloc else { float rotation = (age + tickDelta) / 25.0F + 6.0F; matrices.mulPose(Vector3f.YP.rotation(rotation)); - minecraft.getItemRenderer() - .render(activeItem, - ItemTransforms.TransformType.GROUND, - false, - matrices, - vertexConsumers, - light, - overlay, - model - ); + minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model); } matrices.popPose(); }