-
Notifications
You must be signed in to change notification settings - Fork 556
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
Implement Multimeter Functionality on Generators #3300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ | |||||||
* It must be implemented on any Generator or {@link Reactor}. | ||||||||
* | ||||||||
* @author TheBusyBiscuit | ||||||||
* @author md5sha256 | ||||||||
* | ||||||||
* @see EnergyNet | ||||||||
* @see EnergyNetComponent | ||||||||
|
@@ -48,6 +49,19 @@ default EnergyNetComponentType getEnergyComponentType() { | |||||||
*/ | ||||||||
int getGeneratedOutput(@Nonnull Location l, @Nonnull Config data); | ||||||||
|
||||||||
/** | ||||||||
* The method return how much this {@link EnergyNetProvider} is expected to provide to the {@link EnergyNet} | ||||||||
* and is not to be confused with {@link #getGeneratedOutput(Location, Config)}. This method will not | ||||||||
* consume any fuel or modify the provider in any way. | ||||||||
* @param l | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line
Suggested change
|
||||||||
* The {@link Location} of this {@link EnergyNetProvider} | ||||||||
* @param data | ||||||||
* The stored block data | ||||||||
* | ||||||||
* @return The expected generated output energy of this {@link EnergyNetProvider}. | ||||||||
*/ | ||||||||
int peekGeneratedOutput(@Nonnull Location l, @Nonnull Config data); | ||||||||
|
||||||||
/** | ||||||||
* This method returns whether the given {@link Location} is going to explode on the | ||||||||
* next tick. | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import belongs with the others |
||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; | ||
import me.mrCookieSlime.Slimefun.api.BlockStorage; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
@@ -23,6 +27,7 @@ | |
* The {@link Multimeter} is used to measure charge and capacity of any {@link EnergyNetComponent}. | ||
* | ||
* @author TheBusyBiscuit | ||
* @author md5sha256 | ||
* | ||
* @see EnergyNet | ||
* @see EnergyNetComponent | ||
|
@@ -55,7 +60,15 @@ public ItemUseHandler getItemHandler() { | |
|
||
Player p = e.getPlayer(); | ||
p.sendMessage(""); | ||
Slimefun.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity)); | ||
|
||
if (component instanceof EnergyNetProvider) { | ||
EnergyNetProvider provider = (EnergyNetProvider) component; | ||
Config data = BlockStorage.getLocationInfo(l); | ||
String generating = NumberUtils.getCompactDouble(provider.peekGeneratedOutput(l, data)) + " J/t"; | ||
Slimefun.getLocalization().sendMessages(p, "messages.multimeter-generating", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity).replace("%generating%", generating)); | ||
} else { | ||
Slimefun.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity)); | ||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer moving multimeter out of messages now that it has multiple messages. |
||
} | ||
p.sendMessage(""); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators; | ||||||
|
||||||
import javax.annotation.Nonnull; | ||||||
import javax.annotation.ParametersAreNonnullByDefault; | ||||||
|
||||||
import org.bukkit.Location; | ||||||
|
@@ -26,6 +27,7 @@ | |||||
* {@link #getNightEnergy()}. | ||||||
* | ||||||
* @author TheBusyBiscuit | ||||||
* @author md5sha256 | ||||||
* | ||||||
* @see EnergyNet | ||||||
* @see EnergyNetProvider | ||||||
|
@@ -96,6 +98,12 @@ public int getGeneratedOutput(Location l, Config data) { | |||||
} | ||||||
} | ||||||
|
||||||
@Override | ||||||
public int peekGeneratedOutput(@Nonnull Location l, @Nonnull Config data) { | ||||||
// Solar panels will not change when generating energy | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return getGeneratedOutput(l, data); | ||||||
} | ||||||
|
||||||
/** | ||||||
* This method returns whether a given {@link World} has daytime. | ||||||
* It will also return false if a thunderstorm is active in this world. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
* @author John000708 | ||
* @author AlexLander123 | ||
* @author TheBusyBiscuit | ||
* @author md5sha256 | ||
* | ||
* @see AGenerator | ||
* @see NuclearReactor | ||
|
@@ -299,6 +300,43 @@ public int getGeneratedOutput(Location l, Config data) { | |
} | ||
} | ||
|
||
@Override | ||
public int peekGeneratedOutput(@Nonnull Location l, @Nonnull Config data) { | ||
BlockMenu inv = BlockStorage.getInventory(l); | ||
BlockMenu accessPort = getAccessPort(l); | ||
FuelOperation operation = processor.getOperation(l); | ||
|
||
if (operation != null) { | ||
return peekGenerateEnergy(l, data, inv, accessPort, operation); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
private int peekGenerateEnergy(@Nonnull Location l, @Nonnull Config data, @Nonnull BlockMenu inv, @Nullable BlockMenu accessPort, FuelOperation operation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we extract some of the dupe code here? There's no reason to do a bunch of this in both peekGenerateEnergy and generateEnergy |
||
int produced = getEnergyProduction(); | ||
String energyData = data.getString("energy-charge"); | ||
int charge = 0; | ||
|
||
if (energyData != null) { | ||
charge = Integer.parseInt(energyData); | ||
} | ||
|
||
int space = getCapacity() - charge; | ||
|
||
if (space >= produced || getReactorMode(l) != ReactorMode.GENERATOR) { | ||
if (needsCooling() && !hasEnoughCoolant(l, inv, accessPort, operation)) { | ||
return 0; | ||
} | ||
} | ||
|
||
if (space >= produced) { | ||
return getEnergyProduction(); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
private int generateEnergy(@Nonnull Location l, @Nonnull Config data, @Nonnull BlockMenu inv, @Nullable BlockMenu accessPort, @Nonnull FuelOperation operation) { | ||
int produced = getEnergyProduction(); | ||
String energyData = data.getString("energy-charge"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,28 @@ public int getGeneratedOutput(Location l, Config data) { | |
} | ||
} | ||
|
||
@Override | ||
public int peekGeneratedOutput(@Nonnull Location l, @Nonnull Config data) { | ||
FuelOperation operation = processor.getOperation(l); | ||
if (operation != null) { | ||
if (!operation.isFinished()) { | ||
if (isChargeable()) { | ||
int charge = getCharge(l, data); | ||
if (getCapacity() - charge >= getEnergyProduction()) { | ||
return getEnergyProduction(); | ||
} | ||
return 0; | ||
} else { | ||
return getEnergyProduction(); | ||
} | ||
} else { | ||
return 0; | ||
} | ||
} else { | ||
return 0; | ||
} | ||
} | ||
Comment on lines
+205
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is overly long. Can we clean this up a bit? |
||
|
||
private boolean isBucket(@Nullable ItemStack item) { | ||
if (item == null) { | ||
return 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.
English here can be improved.