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);
}
}
}
@@ -28,6 +28,14 @@ public class ModBlockStateProvider extends BlockStateProvider {
.build());
simpleBlockItem(ModBlocks.STALINIUM_PRESS.get(), pressModel);
ModelFile cacheModel = models()
.getBuilder("stalinium_cache")
.parent(new ModelFile.UncheckedModelFile(modLoc("block/stalinium_cache")));
getVariantBuilder(ModBlocks.STALINIUM_CACHE.get())
.forAllStates(state -> ConfiguredModel.builder()
.modelFile(cacheModel)
.build());
simpleBlockItem(ModBlocks.STALINIUM_CACHE.get(), cacheModel);
}
@@ -53,6 +53,15 @@ public class ModRecipeProvider extends RecipeProvider implements IConditionBuild
.define('S', Items.NETHER_STAR)
.unlockedBy("has_nugget", has(ModItems.STALINIUM_NUGGET)).save(recipeOutput);
ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.STALINIUM_CACHE.get())
.pattern("ISI")
.pattern("SES")
.pattern("SIS")
.define('I', Items.IRON_BLOCK)
.define('E', Items.ENDER_CHEST)
.define('S', ModItems.STALINIUM_INGOT.get())
.unlockedBy("has_nugget", has(ModItems.STALINIUM_NUGGET)).save(recipeOutput);
ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.STALINIUM_SMITHING_TEMPLATE.get(), 4)
.pattern("NNN")
.pattern("NIN")