Skip to content

Commit

Permalink
more fixes!
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Mar 30, 2024
1 parent 6fb3dad commit 67a2a13
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ private SideConfiguratorButton makeSideConfButton(final SideConfigurator<?> side
private void setupSideConfiguratorButton(SideConfigurator<?> sc, SideConfiguratorButton button) {
RelativeFace relativeFace = button.relativeFace;
SideConfigurator.ConnectionEntry<?> c = sc.getEntry(relativeFace);
if (c != null && c.getTexture() != null) {
button.setTexture(c.getTexture());
if (c != null && c.texture() != null) {
button.setTexture(c.texture());
} else {
button.setRenderedIcon(Textures.GUI_X_BUTTON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ private int getPosIdx(ItemStack stack) {

@Override
protected void renderBg(GuiGraphics graphics, float partialTicks, int x, int y) {
renderBackground(graphics, x, y, partialTicks);
int xStart = (width - imageWidth) / 2;
int yStart = (height - imageHeight) / 2;
graphics.blit(Textures.GUI_INVENTORY_SEARCHER, xStart, yStart, 0, 0, imageWidth, imageHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ protected boolean shouldDrawBackground() {

@Override
protected void renderBg(GuiGraphics graphics, float partialTicks, int x, int y) {
renderBackground(graphics, x, y, partialTicks);
graphics.blit(getGuiTexture(), leftPos, topPos, 0, 0, imageWidth, imageHeight, 320, 256);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected ResourceLocation getGuiTexture() {
public void init() {
super.init();

addRenderableWidget(entityFilter = new WidgetTextField(font, leftPos + 80, topPos + 63, 70, font.lineHeight));
addRenderableWidget(entityFilter = new WidgetTextField(font, leftPos + 80, topPos + 62, 70, font.lineHeight + 3));
entityFilter.setMaxLength(256);
setFocused(entityFilter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package me.desht.pneumaticcraft.client.gui.widget;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.datafixers.util.Either;
import me.desht.pneumaticcraft.common.network.NetworkHandler;
import me.desht.pneumaticcraft.common.network.PacketGuiButton;
import me.desht.pneumaticcraft.common.util.PneumaticCraftUtils;
Expand All @@ -34,7 +35,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate;
Expand Down Expand Up @@ -160,14 +160,8 @@ public WidgetButtonExtended setIconSpacing(int spacing) {
return this;
}

public WidgetButtonExtended setTexture(Object texture) {
if (texture instanceof ItemStack) {
setRenderStacks((ItemStack) texture);
} else if (texture instanceof ResourceLocation) {
setRenderedIcon((ResourceLocation) texture);
} else {
throw new IllegalArgumentException("texture must be an ItemStack or ResourceLocation!");
}
public WidgetButtonExtended setTexture(Either<ItemStack,ResourceLocation> texture) {
texture.ifLeft(this::setRenderStacks).ifRight(this::setRenderedIcon);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;

Expand Down Expand Up @@ -115,10 +116,14 @@ protected void renderExtras(ElevatorBaseBlockEntity te, float partialTicks, Pose
float uMax = te.fakeFloorTextureUV[2];
float vMax = te.fakeFloorTextureUV[3];
Matrix4f posMat = matrixStack.last().pose();
builder.vertex(posMat,0, 0, 1).color(1f, 1f, 1f, 1f).uv(uMin, vMax).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,1, 0, 1).color(1f, 1f, 1f, 1f).uv(uMax, vMax).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,1, 0, 0).color(1f, 1f, 1f, 1f).uv(uMax, vMin).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,0, 0, 0).color(1f, 1f, 1f, 1f).uv(uMin, vMin).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,0, 0, 1).color(te.fakeFloorTextureTint)
.uv(uMin, vMax).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,1, 0, 1).color(te.fakeFloorTextureTint)
.uv(uMax, vMax).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,1, 0, 0).color(te.fakeFloorTextureTint)
.uv(uMax, vMin).uv2(te.lightAbove).endVertex();
builder.vertex(posMat,0, 0, 0).color(te.fakeFloorTextureTint)
.uv(uMin, vMin).uv2(te.lightAbove).endVertex();
matrixStack.popPose();
}
}
Expand All @@ -144,4 +149,9 @@ public boolean shouldRender(ElevatorBaseBlockEntity pBlockEntity, Vec3 pCameraPo
return Vec3.atCenterOf(pBlockEntity.getBlockPos()).multiply(1.0D, 0.0D, 1.0D)
.closerThan(pCameraPos.multiply(1.0D, 0.0D, 1.0D), this.getViewDistance());
}

@Override
public AABB getRenderBoundingBox(ElevatorBaseBlockEntity blockEntity) {
return super.getRenderBoundingBox(blockEntity).inflate(blockEntity.extension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public void onBlockRotated() {
if (!nonNullLevel().isClientSide) {
PneumaticRegistry.getInstance().getMiscHelpers().forceClientShapeRecalculation(level, worldPosition);
}

invalidateCapabilities();
}

void rerenderTileEntity() {
Expand Down Expand Up @@ -283,8 +285,8 @@ public void writeToPacket(CompoundTag tag) {

/**
* Encoded into the description packet. Also included in saved data read by {@link AbstractPneumaticCraftBlockEntity#load(CompoundTag)}.
*
* Prefer to use @DescSynced where possible - use this either for complex fields not handled by @DescSynced,
* <p>
* Prefer to use {@code @DescSynced} where possible - use this either for complex fields not handled by {@code @DescSynced},
* or for non-ticking tile entities.
*
* @param tag NBT tag
Expand All @@ -310,7 +312,7 @@ public void saveAdditional(CompoundTag tag) {
IHeatExchangerLogic logic = he.getHeatExchanger();
if (logic != null) tag.put(NBTKeys.NBT_HEAT_EXCHANGER, logic.serializeNBT());
}
if (this instanceof IRedstoneControl rc) {
if (this instanceof IRedstoneControl<?> rc) {
rc.getRedstoneController().serialize(tag);
}
if (this instanceof ISerializableTanks st) {
Expand Down Expand Up @@ -421,7 +423,7 @@ public void onNeighborBlockUpdate(BlockPos fromPos) {
if (this instanceof IHeatExchangingTE he) {
he.initializeHullHeatExchangers(level, worldPosition);
}
if (this instanceof IRedstoneControl rc) {
if (this instanceof IRedstoneControl<?> rc) {
rc.getRedstoneController().updateRedstonePower();
}
neighbourCache.purge();
Expand All @@ -438,14 +440,17 @@ void processFluidItem(int inputSlot, int outputSlot) {
IOHelper.getInventoryForBlock(this).ifPresent(itemHandler -> {
ItemStack inputStack = itemHandler.getStackInSlot(inputSlot);
ItemStack outputStack = itemHandler.getStackInSlot(outputSlot);
if (inputStack.getCount() != 1) return;

FluidUtil.getFluidHandler(inputStack).ifPresent(fluidHandlerItem -> {
FluidStack itemContents = fluidHandlerItem.drain(1000, IFluidHandler.FluidAction.SIMULATE);
FluidStack itemContents = fluidHandlerItem.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.SIMULATE);

IOHelper.getFluidHandlerForBlock(this).ifPresent(fluidHandler -> {
if (!itemContents.isEmpty() && (outputStack.isEmpty() || ItemHandlerHelper.canItemStacksStack(inputStack.getItem().getCraftingRemainingItem(inputStack), outputStack))) {
// input item contains fluid: drain from input item into tank, move to output if empty
// there must be only a single filled container in the input slot!
if (inputStack.getCount() != 1) {
return;
}
FluidStack transferred = FluidUtil.tryFluidTransfer(fluidHandler, fluidHandlerItem, itemContents.getAmount(), true);
if (transferred.getAmount() == itemContents.getAmount()) {
// all transferred; move empty container to output if possible
Expand All @@ -462,12 +467,16 @@ void processFluidItem(int inputSlot, int outputSlot) {
}
} else if (itemHandler.getStackInSlot(outputSlot).isEmpty()) {
// input item is empty: drain from tank to item, move to output
FluidStack transferred = FluidUtil.tryFluidTransfer(fluidHandlerItem, fluidHandler, Integer.MAX_VALUE, true);
if (!transferred.isEmpty()) {
itemHandler.extractItem(inputSlot, 1, false);
ItemStack filledContainerStack = fluidHandlerItem.getContainer();
itemHandler.insertItem(outputSlot, filledContainerStack, false);
}
// we allow multiple empty containers in the input slot
ItemStack workStack = ItemHandlerHelper.copyStackWithSize(inputStack, 1);
IOHelper.getFluidHandlerForItem(workStack).ifPresent(workHandler -> {
FluidStack transferred = FluidUtil.tryFluidTransfer(workHandler, fluidHandler, Integer.MAX_VALUE, true);
if (!transferred.isEmpty()) {
itemHandler.extractItem(inputSlot, 1, false);
ItemStack filledContainerStack = workHandler.getContainer();
itemHandler.insertItem(outputSlot, filledContainerStack, false);
}
});
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import me.desht.pneumaticcraft.mixin.accessors.ServerPlayerAccess;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class AirCannonBlockEntity extends AbstractAirHandlingBlockEntity
implements IMinWorkingPressure, IRedstoneControl<AirCannonBlockEntity>, IGUIButtonSensitive, MenuProvider {

private static final String FP_NAME = "[Air Cannon]";
private static final UUID FP_UUID = UUID.nameUUIDFromBytes(FP_NAME.getBytes());
private static final GameProfile FAKE_PROFILE = UUIDUtil.createOfflineProfile(FP_NAME);

private static final List<RedstoneMode<AirCannonBlockEntity>> REDSTONE_MODES = ImmutableList.of(
new ReceivingRedstoneMode<>("airCannon.highSignalAndAngle", Textures.GUI_HIGH_SIGNAL_ANGLE,
Expand Down Expand Up @@ -651,13 +652,18 @@ private Entity getPayloadEntity() {

private FakePlayer getFakePlayer() {
if (fakePlayer == null) {
fakePlayer = FakePlayerFactory.get((ServerLevel) getLevel(), new GameProfile(FP_UUID, FP_NAME));
fakePlayer = FakePlayerFactory.get((ServerLevel) getLevel(), FAKE_PROFILE);
fakePlayer.setPos(getBlockPos().getX() + 0.5, getBlockPos().getY() + 0.5, getBlockPos().getZ() + 0.5);
}
return fakePlayer;
}

@Override
public void setRemoved() {
super.setRemoved();

fakePlayer = null; // fake player holds a reference to the level; this is called when the level is unloaded
}

private Entity getCloseEntityIfUpgraded() {
int entityUpgrades = Math.min(5, getUpgrades(ModUpgrades.ENTITY_TRACKER.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import me.desht.pneumaticcraft.api.pressure.PressureTier;
import me.desht.pneumaticcraft.client.ColorHandlers;
import me.desht.pneumaticcraft.client.sound.MovingSounds;
import me.desht.pneumaticcraft.client.util.ClientUtils;
import me.desht.pneumaticcraft.common.block.ElevatorBaseBlock;
import me.desht.pneumaticcraft.common.config.ConfigHelper;
import me.desht.pneumaticcraft.common.event.MiscEventHandler;
import me.desht.pneumaticcraft.common.inventory.ElevatorMenu;
import me.desht.pneumaticcraft.common.network.*;
import me.desht.pneumaticcraft.common.network.PacketPlayMovingSound.MovingSoundFocus;
Expand Down Expand Up @@ -106,14 +108,15 @@ public class ElevatorBaseBlockEntity extends AbstractAirHandlingBlockEntity impl
private List<ElevatorBaseBlockEntity> multiElevators;
public int[] floorHeights = new int[0]; // list of every floor of Elevator Callers.
private Int2ObjectMap<String> floorNames = new Int2ObjectOpenHashMap<>();
private int redstoneInputLevel; // current redstone input level
private int redstoneInputLevel = -1; // current redstone input level (-1 = re-check)
private BlockState camoState;
private BlockState prevCamoState;
public int ticksRunning; // ticks since elevator started moving (0 = stopped)
private final IntList floorList = new IntArrayList();
private final List<BlockPos> callerList = new ArrayList<>();
private long lastFloorUpdate = 0L;
public float[] fakeFloorTextureUV;
public int fakeFloorTextureTint;
public int lightAbove;

public ElevatorBaseBlockEntity(BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -143,10 +146,14 @@ public void tickCommonPre() {
}
speedMultiplier = syncedSpeedMult = getSpeedMultiplierFromUpgrades();
chargingUpgrades = getUpgrades(ModUpgrades.CHARGING.get()); // sync'd to client to adjust elevator speed as appropriate
MiscEventHandler.needsTPSSync(getLevel());
} else {
speedMultiplier = (float) (syncedSpeedMult * PacketServerTickTime.tickTimeMultiplier);
if (prevCamoState != camoState) {
fakeFloorTextureUV = ClientUtils.getTextureUV(camoState, Direction.UP);
fakeFloorTextureTint = camoState.getBlock() instanceof ColorHandlers.ITintableBlock t ?
0xFF000000 | t.getTintColor(camoState, level, getBlockPos(), 0) :
0xFFFFFFFF;
prevCamoState = camoState;
}
if ((nonNullLevel().getGameTime() & 0xf) == 0) {
Expand Down Expand Up @@ -222,10 +229,10 @@ private void handleRedstoneControl() {
double oldTargetExtension = targetExtension;
float maxExtension = getMaxElevatorHeight();

int redstoneInput = redstoneInputLevel;
int redstoneInput = getRedstoneInputLevel();
if (multiElevators != null) {
for (ElevatorBaseBlockEntity base : multiElevators) {
redstoneInput = Math.max(redstoneInputLevel, base.redstoneInputLevel);
redstoneInput = Math.max(redstoneInput, base.getRedstoneInputLevel());
}
}

Expand Down Expand Up @@ -266,6 +273,13 @@ private boolean isControlledByRedstone() {
return getRedstoneController().getCurrentMode() == RS_REDSTONE_MODE;
}

private int getRedstoneInputLevel() {
if (redstoneInputLevel < 0) {
updateRedstoneInputLevel();
}
return redstoneInputLevel;
}

private void updateRedstoneInputLevel() {
if (multiElevators == null) return;

Expand Down Expand Up @@ -405,15 +419,8 @@ public void onNeighborBlockUpdate(BlockPos fromPos) {
* elevator, and inform all elevators below us of that fact.
*/
private void updateConnections() {
if (nonNullLevel().getBlockState(getBlockPos().relative(Direction.UP)).getBlock() != ModBlocks.ELEVATOR_BASE.get()) {
if (nonNullLevel().getBlockState(getBlockPos().above()).getBlock() != ModBlocks.ELEVATOR_BASE.get()) {
coreElevator = this;
// int i = -1;
// TileEntity te = getWorld().getTileEntity(getPos().offset(Direction.DOWN));
// while (te instanceof ElevatorBaseBlockEntity) {
// ((ElevatorBaseBlockEntity) te).coreElevator = this;
// i--;
// te = getWorld().getTileEntity(getPos().add(0, i, 0));
// }
} else {
coreElevator = null; // force recalc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class FluxCompressorBlockEntity extends AbstractAirHandlingBlockEntity
implements IRedstoneControl<FluxCompressorBlockEntity>, MenuProvider, IHeatExchangingTE {
private static final int BASE_FE_PRODUCTION = 40;
private final PneumaticEnergyStorage energy = new PneumaticEnergyStorage(100000);
// private final LazyOptional<IEnergyStorage> energyCap = LazyOptional.of(() -> energy);

@GuiSynced
private int rfPerTick;
Expand All @@ -57,7 +56,6 @@ public class FluxCompressorBlockEntity extends AbstractAirHandlingBlockEntity
private final RedstoneController<FluxCompressorBlockEntity> rsController = new RedstoneController<>(this);
@GuiSynced
private final IHeatExchangerLogic heatExchanger = PneumaticRegistry.getInstance().getHeatRegistry().makeHeatExchangerLogic();
// private final LazyOptional<IHeatExchangerLogic> heatCap = LazyOptional.of(() -> heatExchanger);

public FluxCompressorBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntityTypes.FLUX_COMPRESSOR.get(), pos, state, PressureTier.TIER_TWO, PneumaticValues.VOLUME_FLUX_COMPRESSOR, 4);
Expand All @@ -76,8 +74,8 @@ public boolean hasEnergyCapability() {
}

@Override
public IEnergyStorage getEnergyHandler(@org.jetbrains.annotations.Nullable Direction dir) {
return energy;
public IEnergyStorage getEnergyHandler(@Nullable Direction dir) {
return dir == getRotation() ? null : energy;
}

public int getHeatEfficiency(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;

/**
* Represents an block entity whose sides can be reconfigured, i.e. connected to different capability handlers,
* Represents a block entity whose sides can be reconfigured, i.e. connected to different capability handlers,
* typically controlled by GUI side tabs. ISideConfigurable block entity GUI's will automatically get a side tab for
* each side configurator they have. Each side configurator handles one capability (items, fluids, energy...)
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void handleGUIButtonPress(String tag, boolean shiftHeld, ServerPlayer pla
}

@Override
public IItemHandler getItemHandler(@org.jetbrains.annotations.Nullable Direction dir) {
public IItemHandler getItemHandler(@Nullable Direction dir) {
return null;
}

Expand All @@ -148,6 +148,11 @@ public int getInfoEnergyStored() {
return energy.getEnergyStored();
}

@Override
public boolean hasEnergyCapability() {
return true;
}

@Override
public IEnergyStorage getEnergyHandler(@Nullable Direction dir) {
return dir == getRotation() || dir == null ? energy : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import me.desht.pneumaticcraft.common.util.StringFilterEntitySelector;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class SentryTurretBlockEntity extends AbstractTickingBlockEntity implemen
IRedstoneControl<SentryTurretBlockEntity>, IGUITextFieldSensitive, MenuProvider {
private static final int INVENTORY_SIZE = 4;
public static final String NBT_ENTITY_FILTER = "entityFilter";
private static final String FAKE_NAME = "Sentry Turret";
private static final GameProfile FAKE_PROFILE = UUIDUtil.createOfflineProfile(FAKE_NAME);

private final ItemStackHandler inventory = new TurretItemStackHandler(this);

Expand Down Expand Up @@ -194,7 +197,7 @@ public Minigun getMinigun() {
}

private Player getFakePlayer() {
return FakePlayerFactory.get((ServerLevel) getLevel(), new GameProfile(null, "Sentry Turret"));
return FakePlayerFactory.get((ServerLevel) getLevel(), FAKE_PROFILE);
}

@Override
Expand Down
Loading

0 comments on commit 67a2a13

Please sign in to comment.