- Removed Redstone and Lava Bucket requirement in stalinium press.

- Fixed Stalinium Press Logic
- Made Stalinium Press work faster when more players are nearby.
- Fixed JEI recipe.
This commit is contained in:
IM23a-spirgif
2025-06-09 16:02:55 +02:00
parent 286ef332f4
commit 21578edd49
6 changed files with 83 additions and 157 deletions
@@ -76,6 +76,6 @@ public class StaliniumPressBlock extends BaseEntityBlock {
}
return createTickerHelper(blockEntityType, net.krituximon.stalinium.block.entity.ModBlockEntities.STALINIUM_PRESS_BE.get(),
(level1, blockPos, blockState, blockEntity) -> blockEntity.tick(level1, blockPos, blockState));
(level1, blockPos, blockState, blockEntity) -> blockEntity.tick(level1, blockPos, blockState, blockEntity));
}
}
@@ -2,9 +2,6 @@ package net.krituximon.stalinium.block.entity;
import net.krituximon.stalinium.event.ComradeHandler;
import net.krituximon.stalinium.item.ModItems;
import net.krituximon.stalinium.recipe.StaliniumPressRecipe;
import net.krituximon.stalinium.recipe.StaliniumPressRecipeInput;
import net.krituximon.stalinium.recipe.ModRecipes;
import net.krituximon.stalinium.screen.custom.StaliniumPressMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
@@ -20,8 +17,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@@ -32,97 +27,78 @@ import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvider {
public static final int INPUT_SLOT = 0;
public static final int REDSTONE_FUEL_SLOT = 1;
public static final int LAVA_FUEL_SLOT = 2;
public static final int OUTPUT_SLOT = 3;
public static final int INPUT_SLOT = 0;
public static final int OUTPUT_SLOT = 1;
private int progress = 0;
private int maxProgress = 600; // base
private int maxProgress = 600;
public final ItemStackHandler itemHandler = new ItemStackHandler(4) {
public final ItemStackHandler itemHandler = new ItemStackHandler(2) {
@Override
protected void onContentsChanged(int slot) {
setChanged();
if (!level.isClientSide()) {
if (!level.isClientSide) {
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
}
}
};
protected final ContainerData data = new ContainerData() {
@Override
public int get(int index) {
return index == 0 ? progress : (index == 1 ? maxProgress : 0);
}
@Override
public void set(int index, int value) {
if (index == 0) progress = value;
if (index == 1) maxProgress = value;
}
@Override
public int getCount() {
return 2;
}
@Override public int get(int index) { return index == 0 ? progress : (index == 1 ? maxProgress : 0); }
@Override public void set(int index,int v){ if(index==0) progress=v; if(index==1) maxProgress=v; }
@Override public int getCount() { return 2; }
};
public StaliniumPressBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.STALINIUM_PRESS_BE.get(), pos, state);
}
@Override
public Component getDisplayName() {
@Override public Component getDisplayName() {
return Component.translatable("block.stalinium.stalinium_press");
}
@Nullable
@Override
public AbstractContainerMenu createMenu(int id, net.minecraft.world.entity.player.Inventory inv, Player player) {
public AbstractContainerMenu createMenu(int id,
net.minecraft.world.entity.player.Inventory inv,
Player p) {
return new StaliniumPressMenu(id, inv, this, data);
}
@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
tag.put("inventory", itemHandler.serializeNBT(registries));
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider regs) {
tag.put("inventory", itemHandler.serializeNBT(regs));
tag.putInt("progress", progress);
tag.putInt("maxProgress", maxProgress);
super.saveAdditional(tag, registries);
super.saveAdditional(tag, regs);
}
@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
itemHandler.deserializeNBT(registries, tag.getCompound("inventory"));
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider regs) {
super.loadAdditional(tag, regs);
itemHandler.deserializeNBT(regs, tag.getCompound("inventory"));
progress = tag.getInt("progress");
maxProgress = tag.getInt("maxProgress");
}
@Override
public Packet<ClientGamePacketListener> getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
@Override
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
return saveWithoutMetadata(registries);
public CompoundTag getUpdateTag(HolderLookup.Provider regs) {
return saveWithoutMetadata(regs);
}
public static void tick(Level level, BlockPos pos, BlockState state, StaliniumPressBlockEntity be) {
if (be.hasRecipe()) {
// count nearby partymembers within 10 blocks
AABB box = new AABB(pos).inflate(10);
int nearbyComrades = 0;
for (Player p : level.getEntitiesOfClass(Player.class, box, _ignored -> true)) {
if (ComradeHandler.findPartyOf(p.getUUID()).isPresent()) {
nearbyComrades++;
}
}
// base + bonus per comrade
int speed = 1 + nearbyComrades;
for (int i = 0; i < speed; i++) {
be.progress++;
int bonus = 0;
AABB search = new AABB(pos).inflate(10);
for (Player p : level.getEntitiesOfClass(Player.class, search, _ignore->true)) {
if (ComradeHandler.findPartyOf(p.getUUID()).isPresent()) bonus++;
}
be.progress += 1 + bonus;
be.setChanged(level, pos, state);
if (be.progress >= be.maxProgress) {
be.craftItem();
be.resetProgress();
@@ -133,57 +109,33 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
}
private boolean hasRecipe() {
// require ≥9 nuggets
ItemStack in = itemHandler.getStackInSlot(INPUT_SLOT);
if (in.getItem() != ModItems.STALINIUM_NUGGET.get() || in.getCount() < 9) {
return false;
}
Optional<RecipeHolder<StaliniumPressRecipe>> o = getCurrentRecipe();
if (o.isEmpty()) return false;
ItemStack out = o.get().value().output();
return canInsertItemIntoOutputSlot(out) &&
canInsertAmountIntoOutputSlot(out.getCount());
}
private Optional<RecipeHolder<StaliniumPressRecipe>> getCurrentRecipe() {
return level.getRecipeManager()
.getRecipeFor(ModRecipes.STALINIUM_PRESS_TYPE.get(),
new StaliniumPressRecipeInput(
itemHandler.getStackInSlot(REDSTONE_FUEL_SLOT),
itemHandler.getStackInSlot(INPUT_SLOT),
itemHandler.getStackInSlot(LAVA_FUEL_SLOT)
),
level);
return in.getItem() == ModItems.STALINIUM_NUGGET.get() && in.getCount() >= 9
&& canInsertItemIntoOutputSlot(ModItems.STALINIUM_INGOT.get().getDefaultInstance());
}
private void craftItem() {
Optional<RecipeHolder<StaliniumPressRecipe>> o = getCurrentRecipe();
if (o.isEmpty()) return;
itemHandler.extractItem(INPUT_SLOT, 9, false);
itemHandler.extractItem(REDSTONE_FUEL_SLOT, 1, false);
itemHandler.extractItem(LAVA_FUEL_SLOT, 1, false);
itemHandler.setStackInSlot(LAVA_FUEL_SLOT, new ItemStack(Items.BUCKET));
ItemStack out = o.get().value().output();
ItemStack current = itemHandler.getStackInSlot(OUTPUT_SLOT);
itemHandler.setStackInSlot(
OUTPUT_SLOT,
new ItemStack(out.getItem(), current.getCount() + 1)
);
ItemStack out = itemHandler.getStackInSlot(OUTPUT_SLOT);
if (out.isEmpty()) {
itemHandler.setStackInSlot(OUTPUT_SLOT, new ItemStack(ModItems.STALINIUM_INGOT.get()));
} else {
out.grow(1);
}
}
private void resetProgress() {
this.progress = 0;
this.maxProgress = 600;
}
private boolean canInsertItemIntoOutputSlot(ItemStack out) {
ItemStack current = itemHandler.getStackInSlot(OUTPUT_SLOT);
return current.isEmpty() || current.getItem() == out.getItem();
private boolean canInsertItemIntoOutputSlot(ItemStack output) {
ItemStack cur = itemHandler.getStackInSlot(OUTPUT_SLOT);
return cur.isEmpty() || cur.getItem() == output.getItem();
}
private boolean canInsertAmountIntoOutputSlot(int count) {
ItemStack current = itemHandler.getStackInSlot(OUTPUT_SLOT);
int max = current.isEmpty() ? 64 : current.getMaxStackSize();
return max >= current.getCount() + count;
public void drops() {
SimpleContainer inv = new SimpleContainer(itemHandler.getSlots());
for (int i = 0; i < itemHandler.getSlots(); i++) {
inv.setItem(i, itemHandler.getStackInSlot(i));
}
Containers.dropContents(level, worldPosition, inv);
}
}
@@ -35,21 +35,20 @@ public class JEIStaliniumPlugin implements IModPlugin {
@Override
public void registerRecipes(IRecipeRegistration registration) {
RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
List<StaliniumPressRecipe> staliniumPressRecipes = recipeManager
.getAllRecipesFor(ModRecipes.STALINIUM_PRESS_TYPE.get()).stream().map(RecipeHolder::value).toList();
registration.addRecipes(StaliniumPressRecipeCategory.STALINIUM_PRESS_RECIPE_RECIPE_TYPE, staliniumPressRecipes);
registration.addRecipes(StaliniumPressRecipeCategory.TYPE, staliniumPressRecipes);
}
@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addRecipeClickArea(StaliniumPressScreen.class, 74, 30, 22, 20,
StaliniumPressRecipeCategory.STALINIUM_PRESS_RECIPE_RECIPE_TYPE);
StaliniumPressRecipeCategory.TYPE);
}
@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(new ItemStack(ModBlocks.STALINIUM_PRESS.get().asItem()),
StaliniumPressRecipeCategory.STALINIUM_PRESS_RECIPE_RECIPE_TYPE);
StaliniumPressRecipeCategory.TYPE);
}
}
@@ -2,8 +2,8 @@ package net.krituximon.stalinium.compat;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
@@ -12,43 +12,40 @@ import mezz.jei.api.recipe.category.IRecipeCategory;
import net.krituximon.stalinium.Stalinium;
import net.krituximon.stalinium.block.ModBlocks;
import net.krituximon.stalinium.recipe.StaliniumPressRecipe;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.Nullable;
public class StaliniumPressRecipeCategory implements IRecipeCategory<StaliniumPressRecipe> {
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(Stalinium.MODID, "stalinium_chamber");
public static final ResourceLocation UID = ResourceLocation.fromNamespaceAndPath(Stalinium.MODID, "stalinium_press");
public static final ResourceLocation TEXTURE =
ResourceLocation.fromNamespaceAndPath(Stalinium.MODID, "textures/gui/stalinium_press_gui.png");
public static final RecipeType<StaliniumPressRecipe> STALINIUM_PRESS_RECIPE_RECIPE_TYPE =
public static final RecipeType<StaliniumPressRecipe> TYPE =
new RecipeType<>(UID, StaliniumPressRecipe.class);
private final IDrawable background;
private final IDrawable icon;
/* --------------------------------------------------------------------- */
/* GUI layout constants */
/* --------------------------------------------------------------------- */
private static final int[][] INPUT_SLOT_POSITIONS = {
{54, 34},
{54, 14},
{54, 54}
};
private static final int INPUT_X = 54;
private static final int INPUT_Y = 34;
private static final int OUTPUT_X = 104;
private static final int OUTPUT_Y = 34;
public StaliniumPressRecipeCategory(IGuiHelper helper) {
this.background = helper.createDrawable(TEXTURE, 0, 0, 176, 85);
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.STALINIUM_PRESS));
this.icon = helper.createDrawableIngredient(
VanillaTypes.ITEM_STACK,
new ItemStack(ModBlocks.STALINIUM_PRESS)
);
}
@Override
public RecipeType<StaliniumPressRecipe> getRecipeType() {
return STALINIUM_PRESS_RECIPE_RECIPE_TYPE;
return TYPE;
}
@Override
@@ -57,7 +54,8 @@ public class StaliniumPressRecipeCategory implements IRecipeCategory<StaliniumPr
}
@Override
public @Nullable IDrawable getIcon() {
@Nullable
public IDrawable getIcon() {
return icon;
}
@@ -70,28 +68,23 @@ public class StaliniumPressRecipeCategory implements IRecipeCategory<StaliniumPr
public void setRecipe(IRecipeLayoutBuilder builder,
StaliniumPressRecipe recipe,
IFocusGroup focuses) {
var ingredients = recipe.getIngredients();
builder
.addSlot(RecipeIngredientRole.INPUT,
INPUT_SLOT_POSITIONS[0][0],
INPUT_SLOT_POSITIONS[0][1])
.addIngredients(ingredients.get(1));
builder
.addSlot(RecipeIngredientRole.INPUT,
INPUT_SLOT_POSITIONS[1][0],
INPUT_SLOT_POSITIONS[1][1])
.addIngredients(ingredients.get(0));
builder
.addSlot(RecipeIngredientRole.INPUT,
INPUT_SLOT_POSITIONS[2][0],
INPUT_SLOT_POSITIONS[2][1])
.addIngredients(ingredients.get(2));
var output = recipe.getResultItem(
net.minecraft.client.Minecraft.getInstance()
.level
.registryAccess());
IRecipeSlotBuilder inputslot = builder
.addSlot(RecipeIngredientRole.INPUT, INPUT_X, INPUT_Y);
Ingredient nuggetIng = recipe.getIngredients().get(1);
for (ItemStack stack : nuggetIng.getItems()) {
ItemStack copy = stack.copy();
copy.setCount(9);
inputslot.addItemStack(copy);
}
builder
.addSlot(RecipeIngredientRole.OUTPUT, OUTPUT_X, OUTPUT_Y)
.addItemStack(output);
.addItemStack(
recipe.getResultItem(
Minecraft.getInstance()
.level
.registryAccess()
)
);
}
}
@@ -4,13 +4,11 @@ import net.krituximon.stalinium.block.ModBlocks;
import net.krituximon.stalinium.block.entity.StaliniumPressBlockEntity;
import net.krituximon.stalinium.screen.ModMenuTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.neoforged.neoforge.items.SlotItemHandler;
import static net.krituximon.stalinium.block.entity.StaliniumPressBlockEntity.*;
@@ -29,16 +27,8 @@ public class StaliniumPressMenu extends AbstractContainerMenu {
this.blockEntity = be;
this.data = data;
this.level = inv.player.level();
// INPUT
this.addSlot(new SlotItemHandler(be.itemHandler, INPUT_SLOT, 54, 34));
// REDSTONE FUEL
this.addSlot(new SlotItemHandler(be.itemHandler, REDSTONE_FUEL_SLOT,54, 14));
// LAVA FUEL
this.addSlot(new SlotItemHandler(be.itemHandler, LAVA_FUEL_SLOT, 54, 54));
// OUTPUT
this.addSlot(new SlotItemHandler(be.itemHandler, OUTPUT_SLOT, 104, 34));
addPlayerInventory(inv);
addPlayerHotbar(inv);
addDataSlots(data);
@@ -55,14 +45,6 @@ public class StaliniumPressMenu extends AbstractContainerMenu {
return maxProgress != 0 && progress != 0 ? progress * arrowPixelSize / maxProgress : 0;
}
// CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
// must assign a slot number to each of the slots used by the GUI.
// For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
// Each time we add a Slot to the container, it automatically increases the slotIndex, which means
// 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8)
// 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
// 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8)
private static final int HOTBAR_SLOT_COUNT = 9;
private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
@@ -71,8 +53,8 @@ public class StaliniumPressMenu extends AbstractContainerMenu {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
// THIS YOU HAVE TO DEFINE!
private static final int TE_INVENTORY_SLOT_COUNT = 2; // must be the number of slots you have!
@Override
public ItemStack quickMoveStack(Player playerIn, int pIndex) {
Slot sourceSlot = slots.get(pIndex);
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB