- 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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+46
-94
@@ -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 party‐members 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();
|
||||
@@ -131,59 +107,35 @@ public class StaliniumPressBlockEntity extends BlockEntity implements MenuProvid
|
||||
be.resetProgress();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
return in.getItem() == ModItems.STALINIUM_NUGGET.get() && in.getCount() >= 9
|
||||
&& canInsertItemIntoOutputSlot(ModItems.STALINIUM_INGOT.get().getDefaultInstance());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user