1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Bugged Generators from Addons will no longer destroy Energy Regulators

This commit is contained in:
TheBusyBiscuit 2020-04-25 02:16:21 +02:00
parent 0116d19f33
commit 45ed89c6f5
6 changed files with 39 additions and 40 deletions

View File

@ -2,7 +2,7 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of contents** **Table of contents**
- [Release Candidate 11 (24 Apr 2020)](#release-candidate-11-24-apr-2020) - [Release Candidate 11 (25 Apr 2020)](#release-candidate-11-25-apr-2020)
- [Release Candidate 10 (28 Mar 2020)](#release-candidate-10-28-mar-2020) - [Release Candidate 10 (28 Mar 2020)](#release-candidate-10-28-mar-2020)
- [Release Candidate 9 (07 Mar 2020)](#release-candidate-9-07-mar-2020) - [Release Candidate 9 (07 Mar 2020)](#release-candidate-9-07-mar-2020)
- [Release Candidate 8 (06 Mar 2020)](#release-candidate-8-06-mar-2020) - [Release Candidate 8 (06 Mar 2020)](#release-candidate-8-06-mar-2020)
@ -16,14 +16,14 @@
<!-- END doctoc generated TOC please keep comment here to allow auto update --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Release Candidate 11 (24 Apr 2020) ## Release Candidate 11 (25 Apr 2020)
#### Additions #### Additions
* Added GEOResourceGenerationEvent * Added GEOResourceGenerationEvent
* Added AncientAltarCraftEvent * Added AncientAltarCraftEvent
* Added SlimefunGuide-Options API * Added SlimefunGuide-Options API
* Added ItemSettings API * Added ItemSettings API
* Added experimental 1.13 backwards compatibility * Added 1.13 backwards compatibility
* Added "Magma Cream to Magma Blocks" recipe to the Electric Press * Added "Magma Cream to Magma Blocks" recipe to the Electric Press
* Added "Magma Blocks to Sulfate" recipe * Added "Magma Blocks to Sulfate" recipe
* You can now search for items from within the book variant of the Guide * You can now search for items from within the book variant of the Guide

View File

@ -216,7 +216,7 @@
<dependency> <dependency>
<groupId>com.github.thebusybiscuit</groupId> <groupId>com.github.thebusybiscuit</groupId>
<artifactId>CS-CoreLib2</artifactId> <artifactId>CS-CoreLib2</artifactId>
<version>0.15</version> <version>0.17</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -8,6 +8,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler; import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.api.ErrorReport;
import io.github.thebusybiscuit.slimefun4.api.network.Network; import io.github.thebusybiscuit.slimefun4.api.network.Network;
import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent; import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
@ -15,6 +16,7 @@ import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.GeneratorTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
@ -35,33 +37,13 @@ public class EnergyNet extends Network {
private static final int RANGE = 6; private static final int RANGE = 6;
public static EnergyNetComponentType getComponent(Block b) {
return getComponent(b.getLocation());
}
public static EnergyNetComponentType getComponent(String id) {
if (SlimefunPlugin.getRegistry().getEnergyGenerators().contains(id)) {
return EnergyNetComponentType.GENERATOR;
}
if (SlimefunPlugin.getRegistry().getEnergyCapacitors().contains(id)) {
return EnergyNetComponentType.CAPACITOR;
}
if (SlimefunPlugin.getRegistry().getEnergyConsumers().contains(id)) {
return EnergyNetComponentType.CONSUMER;
}
return EnergyNetComponentType.NONE;
}
public static EnergyNetComponentType getComponent(Location l) { public static EnergyNetComponentType getComponent(Location l) {
if (!BlockStorage.hasBlockInfo(l)) { String id = BlockStorage.checkID(l);
if (id == null) {
return EnergyNetComponentType.NONE; return EnergyNetComponentType.NONE;
} }
String id = BlockStorage.checkID(l);
if (SlimefunPlugin.getRegistry().getEnergyGenerators().contains(id)) { if (SlimefunPlugin.getRegistry().getEnergyGenerators().contains(id)) {
return EnergyNetComponentType.GENERATOR; return EnergyNetComponentType.GENERATOR;
} }
@ -195,7 +177,9 @@ public class EnergyNet extends Network {
available = 0; available = 0;
} }
} }
else ChargableBlock.setUnsafeCharge(battery, 0, true); else {
ChargableBlock.setUnsafeCharge(battery, 0, true);
}
} }
for (Location source : generators) { for (Location source : generators) {
@ -229,19 +213,32 @@ public class EnergyNet extends Network {
SlimefunItem item = BlockStorage.check(source); SlimefunItem item = BlockStorage.check(source);
Config config = BlockStorage.getLocationInfo(source); Config config = BlockStorage.getLocationInfo(source);
double energy = item.getEnergyTicker().generateEnergy(source, item, config); try {
GeneratorTicker generator = item.getEnergyTicker();
if (item.getEnergyTicker().explode(source)) { if (generator != null) {
exploded.add(source); double energy = generator.generateEnergy(source, item, config);
BlockStorage.clearBlockInfo(source);
Slimefun.runSync(() -> { if (generator.explode(source)) {
source.getBlock().setType(Material.LAVA); exploded.add(source);
source.getWorld().createExplosion(source, 0F, false); BlockStorage.clearBlockInfo(source);
});
Slimefun.runSync(() -> {
source.getBlock().setType(Material.LAVA);
source.getWorld().createExplosion(source, 0F, false);
});
}
else {
supply += energy;
}
}
else {
item.warn("This Item was marked as a 'GENERATOR' but has no 'GeneratorTicker' attached to it! This must be fixed.");
}
} }
else { catch (Throwable t) {
supply += energy; exploded.add(source);
new ErrorReport(t, source, item);
} }
SlimefunPlugin.getTicker().addBlockTimings(source, System.currentTimeMillis() - timestamp); SlimefunPlugin.getTicker().addBlockTimings(source, System.currentTimeMillis() - timestamp);

View File

@ -124,7 +124,7 @@ public class DebugFishListener implements Listener {
p.sendMessage(ChatColors.color("&dChargeable: " + disabledTooltip)); p.sendMessage(ChatColors.color("&dChargeable: " + disabledTooltip));
} }
p.sendMessage(ChatColors.color(" &dEnergyNet Type: &e" + EnergyNet.getComponent(b))); p.sendMessage(ChatColors.color(" &dEnergyNet Type: &e" + EnergyNet.getComponent(b.getLocation())));
p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b))); p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b)));
p.sendMessage(" "); p.sendMessage(" ");

View File

@ -132,8 +132,10 @@ public final class SlimefunUtils {
boolean sfItemHasMeta = sfitem.hasItemMeta(); boolean sfItemHasMeta = sfitem.hasItemMeta();
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
if (sfitem instanceof SlimefunItemStack) { if (sfitem instanceof SlimefunItemStack) {
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(itemMeta); Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(itemMeta);
if (id.isPresent()) { if (id.isPresent()) {
return id.get().equals(((SlimefunItemStack) sfitem).getItemID()); return id.get().equals(((SlimefunItemStack) sfitem).getItemID());
} }

View File

@ -710,7 +710,7 @@ public class SlimefunItem implements Placeable {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + " - '" + id + "' (" + addon.getName() + ')'; return getClass().getSimpleName() + " - '" + id + "' (" + addon.getName() + " v" + addon.getPluginVersion() + ')';
} }
@Override @Override