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:
@@ -47,9 +47,9 @@ public class ModBlocks {
|
|||||||
public static final DeferredBlock<Block> STALINIUM_PRESS = registerBlock("stalinium_press",
|
public static final DeferredBlock<Block> STALINIUM_PRESS = registerBlock("stalinium_press",
|
||||||
() -> new StaliniumPressBlock(BlockBehaviour.Properties.of()));
|
() -> new StaliniumPressBlock(BlockBehaviour.Properties.of()));
|
||||||
|
|
||||||
public static final DeferredBlock<StaliniumCacheBlock> STALINIUM_CACHE = registerBlock(
|
public static final DeferredBlock<Block> STALINIUM_CACHE = registerBlock(
|
||||||
"stalinium_cache",
|
"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) {
|
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
|
||||||
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
|
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import net.minecraft.world.phys.BlockHitResult;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class StaliniumCacheBlock extends BaseEntityBlock {
|
public class StaliniumCacheBlock extends BaseEntityBlock {
|
||||||
// 1) supply a real codec so the block actually constructs from your registry
|
|
||||||
public static final MapCodec<StaliniumCacheBlock> CODEC =
|
public static final MapCodec<StaliniumCacheBlock> CODEC =
|
||||||
simpleCodec(StaliniumCacheBlock::new);
|
simpleCodec(StaliniumCacheBlock::new);
|
||||||
|
|
||||||
|
|||||||
@@ -29,27 +29,24 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public class StaliniumCacheBlockEntity extends BlockEntity {
|
public class StaliniumCacheBlockEntity extends BlockEntity {
|
||||||
private static final int SIZE = 27;
|
private static final int SIZE = 27;
|
||||||
|
|
||||||
// each party → shared 27‐slot inventory
|
|
||||||
private static final Map<UUID, SimpleContainer> PARTY_INVENTORIES = new ConcurrentHashMap<>();
|
private static final Map<UUID, SimpleContainer> PARTY_INVENTORIES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public StaliniumCacheBlockEntity(BlockPos pos, BlockState state) {
|
public StaliniumCacheBlockEntity(BlockPos pos, BlockState state) {
|
||||||
super(ModBlockEntities.STALINIUM_CACHE_BE.get(), pos, state);
|
super(ModBlockEntities.STALINIUM_CACHE_BE.get(), pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static SimpleContainer getPartyInventory(@Nullable Player who) {
|
||||||
* Grab (or create) the shared SimpleContainer for this player's party
|
if (who == null) {
|
||||||
*/
|
UUID defaultKey = UUID.randomUUID();
|
||||||
public static SimpleContainer getPartyInventory(Player who) {
|
return PARTY_INVENTORIES.computeIfAbsent(defaultKey, __ -> new SimpleContainer(SIZE));
|
||||||
|
}
|
||||||
Optional<ComradeHandler.Party> opt = ComradeHandler.findPartyOf(who.getUUID());
|
Optional<ComradeHandler.Party> opt = ComradeHandler.findPartyOf(who.getUUID());
|
||||||
UUID key = opt.map(p -> p.leader).orElse(who.getUUID());
|
UUID key = opt.map(p -> p.leader).orElse(who.getUUID());
|
||||||
return PARTY_INVENTORIES.computeIfAbsent(key, __ -> new SimpleContainer(SIZE));
|
return PARTY_INVENTORIES.computeIfAbsent(key, __ -> new SimpleContainer(SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Drop everything, using that same shared container */
|
|
||||||
public void drops() {
|
public void drops() {
|
||||||
SimpleContainer inv = getPartyInventory((ServerPlayer) null);
|
SimpleContainer inv = getPartyInventory(null);
|
||||||
// actually, we don't know "who" here—just drop all slots
|
|
||||||
SimpleContainer tmp = new SimpleContainer(SIZE);
|
SimpleContainer tmp = new SimpleContainer(SIZE);
|
||||||
for (int i = 0; i < SIZE; i++) {
|
for (int i = 0; i < SIZE; i++) {
|
||||||
tmp.setItem(i, inv.getItem(i));
|
tmp.setItem(i, inv.getItem(i));
|
||||||
@@ -67,4 +64,4 @@ public class StaliniumCacheBlockEntity extends BlockEntity {
|
|||||||
public Packet<ClientGamePacketListener> getUpdatePacket() {
|
public Packet<ClientGamePacketListener> getUpdatePacket() {
|
||||||
return ClientboundBlockEntityDataPacket.create(this);
|
return ClientboundBlockEntityDataPacket.create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,14 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
|||||||
.build());
|
.build());
|
||||||
simpleBlockItem(ModBlocks.STALINIUM_PRESS.get(), pressModel);
|
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)
|
.define('S', Items.NETHER_STAR)
|
||||||
.unlockedBy("has_nugget", has(ModItems.STALINIUM_NUGGET)).save(recipeOutput);
|
.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)
|
ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.STALINIUM_SMITHING_TEMPLATE.get(), 4)
|
||||||
.pattern("NNN")
|
.pattern("NNN")
|
||||||
.pattern("NIN")
|
.pattern("NIN")
|
||||||
|
|||||||
Reference in New Issue
Block a user