PedestalBlockEntity sync fix
This commit is contained in:
parent
de6100f9be
commit
14a6803c88
4 changed files with 24 additions and 22 deletions
|
@ -283,10 +283,8 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
|
||||||
public boolean isPlaceable(BlockState state) {
|
public boolean isPlaceable(BlockState state) {
|
||||||
if (!state.isOf(this)) return false;
|
if (!state.isOf(this)) return false;
|
||||||
PedestalState currentState = state.get(STATE);
|
PedestalState currentState = state.get(STATE);
|
||||||
return currentState != PedestalState.BOTTOM &&
|
return currentState == PedestalState.DEFAULT ||
|
||||||
currentState != PedestalState.COLUMN &&
|
currentState == PedestalState.PEDESTAL_TOP;
|
||||||
currentState != PedestalState.PILLAR &&
|
|
||||||
currentState != PedestalState.COLUMN_TOP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.betterend.blocks.entities;
|
package ru.betterend.blocks.entities;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
@ -13,7 +14,7 @@ import ru.betterend.blocks.basis.PedestalBlock;
|
||||||
import ru.betterend.registry.EndBlockEntities;
|
import ru.betterend.registry.EndBlockEntities;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable {
|
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable, BlockEntityClientSerializable {
|
||||||
private ItemStack activeItem = ItemStack.EMPTY;
|
private ItemStack activeItem = ItemStack.EMPTY;
|
||||||
|
|
||||||
private final int maxAge = 314;
|
private final int maxAge = 314;
|
||||||
|
@ -102,23 +103,10 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockEntityUpdateS2CPacket toUpdatePacket() {
|
|
||||||
return new BlockEntityUpdateS2CPacket(pos, 32, toInitialChunkDataTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundTag toInitialChunkDataTag() {
|
|
||||||
return toTag(new CompoundTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromTag(BlockState state, CompoundTag tag) {
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
super.fromTag(state, tag);
|
super.fromTag(state, tag);
|
||||||
if (tag.contains("active_item")) {
|
fromClientTag(tag);
|
||||||
CompoundTag itemTag = tag.getCompound("active_item");
|
|
||||||
activeItem = ItemStack.fromTag(itemTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,4 +125,17 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromClientTag(CompoundTag tag) {
|
||||||
|
if (tag.contains("active_item")) {
|
||||||
|
CompoundTag itemTag = tag.getCompound("active_item");
|
||||||
|
activeItem = ItemStack.fromTag(itemTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag toClientTag(CompoundTag tag) {
|
||||||
|
return toTag(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,13 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
|
||||||
VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||||
|
|
||||||
World world = blockEntity.getWorld();
|
World world = blockEntity.getWorld();
|
||||||
if (blockEntity.isEmpty() || world == null) return;
|
if (world == null || blockEntity.isEmpty()) return;
|
||||||
|
|
||||||
BlockState state = world.getBlockState(blockEntity.getPos());
|
BlockState state = world.getBlockState(blockEntity.getPos());
|
||||||
if (!(state.getBlock() instanceof PedestalBlock)) return;
|
if (!(state.getBlock() instanceof PedestalBlock)) return;
|
||||||
|
|
||||||
ItemStack activeItem = blockEntity.getStack(0);
|
ItemStack activeItem = blockEntity.getStack(0);
|
||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
MinecraftClient minecraft = MinecraftClient.getInstance();
|
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||||
BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, world, null);
|
BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, world, null);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ru.betterend.mixin.client;
|
package ru.betterend.mixin.client;
|
||||||
|
|
||||||
|
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -27,8 +29,8 @@ public class ClientPlayNetworkHandlerMixin
|
||||||
|
|
||||||
@Inject(method = "onSignEditorOpen", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "onSignEditorOpen", at = @At(value = "HEAD"), cancellable = true)
|
||||||
public void be_openSignEditor(SignEditorOpenS2CPacket packet, CallbackInfo info) {
|
public void be_openSignEditor(SignEditorOpenS2CPacket packet, CallbackInfo info) {
|
||||||
NetworkThreadUtils.forceMainThread(packet, (ClientPlayNetworkHandler) (Object) this, (ThreadExecutor<?>) client);
|
NetworkThreadUtils.forceMainThread(packet, ClientPlayNetworkHandler.class.cast(this), client);
|
||||||
BlockEntity blockEntity = this.world.getBlockEntity(packet.getPos());
|
BlockEntity blockEntity = world.getBlockEntity(packet.getPos());
|
||||||
if (blockEntity instanceof ESignBlockEntity) {
|
if (blockEntity instanceof ESignBlockEntity) {
|
||||||
ESignBlockEntity sign = (ESignBlockEntity) blockEntity;
|
ESignBlockEntity sign = (ESignBlockEntity) blockEntity;
|
||||||
client.openScreen(new BlockSignEditScreen(sign));
|
client.openScreen(new BlockSignEditScreen(sign));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue