feat: sync with blockentity update packet
This commit is contained in:
parent
9188fcaef1
commit
ebc9f61f9b
2 changed files with 32 additions and 1 deletions
|
@ -116,6 +116,7 @@ public class FloralWorkbench extends BaseEntityBlock
|
||||||
Containers.dropItemStack(level, pos.getX(),
|
Containers.dropItemStack(level, pos.getX(),
|
||||||
pos.getY() + 1.0f, pos.getZ(), crown);
|
pos.getY() + 1.0f, pos.getZ(), crown);
|
||||||
blockentity.setChanged();
|
blockentity.setChanged();
|
||||||
|
level.sendBlockUpdated(pos, state, state, 3);
|
||||||
return InteractionResult.SUCCESS_SERVER;
|
return InteractionResult.SUCCESS_SERVER;
|
||||||
}
|
}
|
||||||
else if (stack.is(CnFRegistries.Items.FLOWER_CROWN.get()) &&
|
else if (stack.is(CnFRegistries.Items.FLOWER_CROWN.get()) &&
|
||||||
|
@ -124,6 +125,7 @@ public class FloralWorkbench extends BaseEntityBlock
|
||||||
handler.insertItem(0, stack.copy(), false);
|
handler.insertItem(0, stack.copy(), false);
|
||||||
stack.consume(1, player);
|
stack.consume(1, player);
|
||||||
blockentity.setChanged();
|
blockentity.setChanged();
|
||||||
|
level.sendBlockUpdated(pos, state, state, 3);
|
||||||
return InteractionResult.CONSUME;
|
return InteractionResult.CONSUME;
|
||||||
} else {
|
} else {
|
||||||
return InteractionResult.FAIL;
|
return InteractionResult.FAIL;
|
||||||
|
@ -131,7 +133,7 @@ public class FloralWorkbench extends BaseEntityBlock
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return hasCrown ^ emptyHand ? InteractionResult.SUCCESS :
|
return !hasCrown ^ emptyHand ? InteractionResult.SUCCESS :
|
||||||
InteractionResult.FAIL;
|
InteractionResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,16 @@ import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class FloralWorkbenchBlockEntity extends BlockEntity
|
public class FloralWorkbenchBlockEntity extends BlockEntity
|
||||||
{
|
{
|
||||||
|
@ -39,6 +44,30 @@ public class FloralWorkbenchBlockEntity extends BlockEntity
|
||||||
.ifPresent(tag -> itemHandler.deserializeNBT(levelRegistry, tag));
|
.ifPresent(tag -> itemHandler.deserializeNBT(levelRegistry, tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag getUpdateTag(HolderLookup.Provider registries)
|
||||||
|
{
|
||||||
|
CompoundTag tag = super.getUpdateTag(registries);
|
||||||
|
tag.put("Inventory", itemHandler.serializeNBT(registries));
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleUpdateTag(CompoundTag nbt,
|
||||||
|
HolderLookup.Provider lookupProvider)
|
||||||
|
{
|
||||||
|
super.handleUpdateTag(nbt, lookupProvider);
|
||||||
|
nbt.getCompound("Inventory")
|
||||||
|
.ifPresent(tag -> itemHandler.deserializeNBT(lookupProvider, tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Packet<ClientGamePacketListener> getUpdatePacket()
|
||||||
|
{
|
||||||
|
return ClientboundBlockEntityDataPacket.create(this);
|
||||||
|
}
|
||||||
|
|
||||||
public RandomSource getRandomSource()
|
public RandomSource getRandomSource()
|
||||||
{
|
{
|
||||||
return this.randomSource;
|
return this.randomSource;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue