Added shared party inventory management to Stalinium Cache block. Implemented new model, block state, and crafting recipe. Improved null handling in party inventory logic.

This commit is contained in:
IM23a-spirgif
2025-06-10 18:39:46 +02:00
parent 7da7dddafa
commit 034a8fe942
5 changed files with 27 additions and 14 deletions
@@ -47,9 +47,9 @@ public class ModBlocks {
public static final DeferredBlock<Block> STALINIUM_PRESS = registerBlock("stalinium_press",
() -> new StaliniumPressBlock(BlockBehaviour.Properties.of()));
public static final DeferredBlock<StaliniumCacheBlock> STALINIUM_CACHE = registerBlock(
public static final DeferredBlock<Block> STALINIUM_CACHE = registerBlock(
"stalinium_cache",
() -> new StaliniumCacheBlock(Block.Properties.of()));
() -> new StaliniumCacheBlock(BlockBehaviour.Properties.of()));
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
@@ -22,7 +22,6 @@ import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
public class StaliniumCacheBlock extends BaseEntityBlock {
// 1) supply a real codec so the block actually constructs from your registry
public static final MapCodec<StaliniumCacheBlock> CODEC =
simpleCodec(StaliniumCacheBlock::new);
@@ -29,27 +29,24 @@ import java.util.concurrent.ConcurrentHashMap;
public class StaliniumCacheBlockEntity extends BlockEntity {
private static final int SIZE = 27;
// each party → shared 27slot inventory
private static final Map<UUID, SimpleContainer> PARTY_INVENTORIES = new ConcurrentHashMap<>();
public StaliniumCacheBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.STALINIUM_CACHE_BE.get(), pos, state);
}
/**
* Grab (or create) the shared SimpleContainer for this player's party
*/
public static SimpleContainer getPartyInventory(Player who) {
public static SimpleContainer getPartyInventory(@Nullable Player who) {
if (who == null) {
UUID defaultKey = UUID.randomUUID();
return PARTY_INVENTORIES.computeIfAbsent(defaultKey, __ -> new SimpleContainer(SIZE));
}
Optional<ComradeHandler.Party> opt = ComradeHandler.findPartyOf(who.getUUID());
UUID key = opt.map(p -> p.leader).orElse(who.getUUID());
return PARTY_INVENTORIES.computeIfAbsent(key, __ -> new SimpleContainer(SIZE));
}
/** Drop everything, using that same shared container */
public void drops() {
SimpleContainer inv = getPartyInventory((ServerPlayer) null);
// actually, we don't know "who" here—just drop all slots
SimpleContainer inv = getPartyInventory(null);
SimpleContainer tmp = new SimpleContainer(SIZE);
for (int i = 0; i < SIZE; i++) {
tmp.setItem(i, inv.getItem(i));
@@ -67,4 +64,4 @@ public class StaliniumCacheBlockEntity extends BlockEntity {
public Packet<ClientGamePacketListener> getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
}
}