-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Buffers (item and power) #455
base: dev/1.20.1
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review :)
src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java
Outdated
Show resolved
Hide resolved
src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java
Outdated
Show resolved
Hide resolved
src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java
Outdated
Show resolved
Hide resolved
src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java
Show resolved
Hide resolved
src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java
Outdated
Show resolved
Hide resolved
src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java
Outdated
Show resolved
Hide resolved
public static final String BUFFER_MAX_INPUT = "BufferMaxInput"; | ||
|
||
public static final String BUFFER_MAX_OUTPUT = "BufferMaxOutput"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Generic ENERGY_MAX_RECEIVE and ENERGY_MAX_EXTRACT instead.
|
||
builder.push("powerBuffer"); | ||
POWER_BUFFER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 100_000, 1, Integer.MAX_VALUE); | ||
POWER_BUFFER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 1_000, 1, Integer.MAX_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage/Consumption ?
inputDataSlot = new IntegerNetworkDataSlot(this::getMaxInput, input -> maxInput = input); | ||
outputDataSlot = new IntegerNetworkDataSlot(this::getMaxOutput, output -> maxOutput = output); | ||
addDataSlot(inputDataSlot); | ||
addDataSlot(outputDataSlot); | ||
|
||
inputTextDataSlot = new StringNetworkDataSlot(this::getMaxInputText, input -> inputTextValue = input); | ||
outputTextDataSlot = new StringNetworkDataSlot(this::getMaxOutputText, output -> outputTextValue = output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are both the value and string form synced separately ?
public void setMaxInputText(String maxInputText) { | ||
if (level != null && level.isClientSide) { | ||
clientUpdateSlot(inputTextDataSlot, maxInputText); | ||
} this.inputTextValue = maxInputText; | ||
} | ||
|
||
public void setMaxOutputText(String maxOutputText) { | ||
if (level != null && level.isClientSide) { | ||
clientUpdateSlot(outputTextDataSlot, maxOutputText); | ||
} this.outputTextValue = maxOutputText; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no point in syncing the text. It should be completely client sided. The server needs to know only the final Integer.
if (otherHandler.get().canExtract()) { | ||
dirs.add(side); | ||
} | ||
} else { | ||
if (otherHandler.get().canReceive()) { | ||
dirs.add(side); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this take care of neighbors being full or empty ?
int received = otherHandler.get().receiveEnergy(Math.min(energyPerSide, getExposedEnergyStorage().getEnergyStored()), false); | ||
// Consume that energy from our buffer. | ||
getExposedEnergyStorage().extractEnergy(received, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these be simulated first ?
public String formatEnergy(String value) { | ||
if (value.isEmpty()) { | ||
return ""; | ||
} | ||
|
||
int energy; | ||
value = value.replace(",", ""); | ||
|
||
try { | ||
energy = Integer.parseInt(value); | ||
energy = Math.min(energy, maxEnergy.get()); | ||
} catch(Exception e) { | ||
energy = 0; | ||
} | ||
|
||
try { | ||
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); | ||
decimalFormat.applyPattern("#,###"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look into EditTextBox#formatter
and FormattedSequence
. Is that something that should be used instead?
public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { | ||
if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused() && maxEnergy.get() != 0) { | ||
guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(getValue() +"/" + maxEnergy.get() +" µI/t"), mouseX, mouseY); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required anymore
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height) { | ||
super.mouseClicked(mouseX, mouseY, button); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this mouseClicked result can be ignored?
Will not be merged into dev/1.20.1 - needs rebasing on 20.4+ to for this :) (I know you're likely busy - I'm writing this for tracking purposes) |
Description
I've been absent for a long time now but I've been following your amazing bug fixing adventures...
During this time I worked on buffers (Item + Power) which allows the player to have a 3x3 item buffer and a power buffer that allows the player to control I/O energy rates from the block.
It implements an improved version of the energy textbox widget that I showed you on PR #364 so when this gets in the code base, I will close #364.
I'm not sure about everything in my code as usual so I will be taking your suggestions into consideration :) I've commented that in the code so you will understand what I'm talking about...
Closes #150 , #364
Checklist: