Fix build + crash

This commit is contained in:
modmuss50 2023-03-18 12:47:35 +00:00
parent b1eb120d0e
commit 34784f94d9
2 changed files with 27 additions and 17 deletions

View file

@ -43,6 +43,7 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.fluid.FluidValue; import reborncore.common.fluid.FluidValue;
@ -73,7 +74,8 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
public static final int MAX_RANGE = 50; public static final int MAX_RANGE = 50;
public static final int MAX_DEPTH = 50; public static final int MAX_DEPTH = 50;
private Iterator<BlockPos> finder; private Iterator<BlockPos> finder;
protected final @NotNull Tank tank; @Nullable
private Tank tank;
private boolean exhausted; private boolean exhausted;
private BlockPos pumpedTargetBlockPos; private BlockPos pumpedTargetBlockPos;
private long timeToPump; private long timeToPump;
@ -83,7 +85,6 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
public PumpBlockEntity(BlockPos pos, BlockState state) { public PumpBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.PUMP, pos, state, "Pump", TechRebornConfig.pumpMaxInput, TechRebornConfig.pumpMaxEnergy, TRContent.Machine.PUMP.block, 0); super(TRBlockEntities.PUMP, pos, state, "Pump", TechRebornConfig.pumpMaxInput, TechRebornConfig.pumpMaxEnergy, TRContent.Machine.PUMP.block, 0);
this.inventory = new RebornInventory<>(1, "PumpBlockEntity", 64, this); this.inventory = new RebornInventory<>(1, "PumpBlockEntity", 64, this);
this.tank = new Tank("PumpBlockEntity", TANK_CAPACITY, this);
this.exhausted = false; this.exhausted = false;
this.range = DEFAULT_RANGE; this.range = DEFAULT_RANGE;
this.depth = DEFAULT_DEPTH; this.depth = DEFAULT_DEPTH;
@ -135,10 +136,19 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
} }
@Override @Override
public @NotNull Tank getTank() { @NotNull
public Tank getTank() {
if (this.tank == null) {
this.tank = createTank();
}
return tank; return tank;
} }
private Tank createTank() {
return new Tank("PumpBlockEntity", TANK_CAPACITY, this);
}
@Override @Override
public ItemStack getToolDrop(PlayerEntity p0) { public ItemStack getToolDrop(PlayerEntity p0) {
return TRContent.Machine.PUMP.getStack(); return TRContent.Machine.PUMP.getStack();
@ -147,7 +157,7 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
@Override @Override
public void readNbt(final NbtCompound tagCompound) { public void readNbt(final NbtCompound tagCompound) {
super.readNbt(tagCompound); super.readNbt(tagCompound);
tank.read(tagCompound); getTank().read(tagCompound);
this.range = tagCompound.getInt("range"); this.range = tagCompound.getInt("range");
this.depth = tagCompound.getInt("depth"); this.depth = tagCompound.getInt("depth");
finder = null; finder = null;
@ -156,7 +166,7 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
@Override @Override
public void writeNbt(final NbtCompound tagCompound) { public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound); super.writeNbt(tagCompound);
tank.write(tagCompound); getTank().write(tagCompound);
tagCompound.putInt("range", range); tagCompound.putInt("range", range);
tagCompound.putInt("depth", depth); tagCompound.putInt("depth", depth);
} }
@ -166,7 +176,7 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
return new ScreenHandlerBuilder("pump") return new ScreenHandlerBuilder("pump")
.player(player.getInventory()).inventory().hotbar().addInventory().blockEntity(this) .player(player.getInventory()).inventory().hotbar().addInventory().blockEntity(this)
.energySlot(0, 8, 72) .energySlot(0, 8, 72)
.sync(tank) .sync(getTank())
.syncEnergyValue() .syncEnergyValue()
.sync(this::getDepth, this::setDepth) .sync(this::getDepth, this::setDepth)
.sync(this::getRange, this::setRange) .sync(this::getRange, this::setRange)
@ -211,20 +221,20 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
return; return;
} }
//cannot fit fluid into the tank? //cannot fit fluid into the tank?
if (!tank.canFit(fluid, FluidValue.BUCKET)) { if (!getTank().canFit(fluid, FluidValue.BUCKET)) {
//don't drop target, retry it again later //don't drop target, retry it again later
timeToPump = world.getTime() + (long) (TechRebornConfig.pumpTicksToComplete * (1 - getSpeedMultiplier())); timeToPump = world.getTime() + (long) (TechRebornConfig.pumpTicksToComplete * (1 - getSpeedMultiplier()));
return; return;
} }
//fill tank //fill tank
if (tank.getFluidInstance().isEmpty()) { if (getTank().getFluidInstance().isEmpty()) {
tank.setFluidInstance(new FluidInstance(fluid, FluidValue.BUCKET)); getTank().setFluidInstance(new FluidInstance(fluid, FluidValue.BUCKET));
} else { } else {
tank.getFluidInstance().addAmount(FluidValue.BUCKET); getTank().getFluidInstance().addAmount(FluidValue.BUCKET);
} }
//play sound //play sound
if (!isMuffled()) { if (!isMuffled()) {
world.playSound(null, this.pos, tank.getFluid().getBucketFillSound().orElse(SoundEvents.ITEM_BUCKET_FILL), SoundCategory.BLOCKS, 1.0f, 1.0f); world.playSound(null, this.pos, getTank().getFluid().getBucketFillSound().orElse(SoundEvents.ITEM_BUCKET_FILL), SoundCategory.BLOCKS, 1.0f, 1.0f);
} }
//consume energy //consume energy
this.useEnergy((long) (TechRebornConfig.pumpEnergyToCollect * getPowerMultiplier())); this.useEnergy((long) (TechRebornConfig.pumpEnergyToCollect * getPowerMultiplier()));
@ -240,7 +250,7 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
world.setBlockState(pumpedTargetBlockPos, replacementBlock.getDefaultState()); world.setBlockState(pumpedTargetBlockPos, replacementBlock.getDefaultState());
pumpedTargetBlockPos = null; pumpedTargetBlockPos = null;
} }
} else if (!tank.isFull()) { } else if (!getTank().isFull()) {
//find next target //find next target
findNextToPump(world); findNextToPump(world);
if (pumpedTargetBlockPos != null) { if (pumpedTargetBlockPos != null) {
@ -263,7 +273,7 @@ public class PumpBlockEntity extends GenericMachineBlockEntity implements BuiltS
BlockState blockState = world.getBlockState(blockPos); BlockState blockState = world.getBlockState(blockPos);
Fluid fluid = getFluid(blockState); Fluid fluid = getFluid(blockState);
if (fluid != Fluids.EMPTY && (fluid == tank.getFluid() || tank.getFluid() == Fluids.EMPTY)) { if (fluid != Fluids.EMPTY && (fluid == getTank().getFluid() || getTank().getFluid() == Fluids.EMPTY)) {
//if any found - start pumping //if any found - start pumping
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true)); world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
pumpedTargetBlockPos = blockPos; pumpedTargetBlockPos = blockPos;

View file

@ -36,12 +36,12 @@ import net.minecraft.item.SkullItem;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Pair;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import oshi.util.tuples.Pair;
import reborncore.api.IListInfoProvider; import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider; import reborncore.api.blockentity.InventoryProvider;
@ -208,14 +208,14 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
DefaultedList<ItemStack> optionalShulkerStack = ItemUtils.getBlockEntityStacks(inputStack); DefaultedList<ItemStack> optionalShulkerStack = ItemUtils.getBlockEntityStacks(inputStack);
if (isLocked() && ItemUtils.canExtractFromCachedShulker(optionalShulkerStack, lockedItemStack) > 0 ) { if (isLocked() && ItemUtils.canExtractFromCachedShulker(optionalShulkerStack, lockedItemStack) > 0 ) {
Pair<Integer, ItemStack> pair = ItemUtils.extractFromShulker(inputStack, optionalShulkerStack, lockedItemStack, reminder); Pair<Integer, ItemStack> pair = ItemUtils.extractFromShulker(inputStack, optionalShulkerStack, lockedItemStack, reminder);
if (pair.getA() != 0) { if (pair.getLeft() != 0) {
int amount = pair.getA(); int amount = pair.getLeft();
if (storeItemStack.isEmpty()) { if (storeItemStack.isEmpty()) {
storeItemStack = lockedItemStack.copy(); storeItemStack = lockedItemStack.copy();
amount = amount -1; amount = amount -1;
} }
addStoredItemCount(amount); addStoredItemCount(amount);
inputStack.setNbt(pair.getB().getNbt()); inputStack.setNbt(pair.getRight().getNbt());
inventory.setHashChanged(); inventory.setHashChanged();
} }
return inputStack; return inputStack;