Revert "Rewrite to use new RebornCore Power API. Texture fixes."
This reverts commit b292fdd352
.
# Conflicts:
# src/main/java/techreborn/client/gui/GuiImplosionCompressor.java
# src/main/java/techreborn/client/gui/GuiIndustrialGrinder.java
# src/main/java/techreborn/client/gui/GuiIndustrialSawmill.java
# src/main/java/techreborn/client/gui/GuiVacuumFreezer.java
# src/main/java/techreborn/tiles/TileAlloyFurnace.java
# src/main/java/techreborn/tiles/TileAlloySmelter.java
# src/main/java/techreborn/tiles/TileAssemblingMachine.java
# src/main/java/techreborn/tiles/TileImplosionCompressor.java
# src/main/java/techreborn/tiles/TileIndustrialSawmill.java
# src/main/java/techreborn/tiles/TileVacuumFreezer.java
# src/main/java/techreborn/tiles/multiblock/TileBlastFurnace.java
# src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java
# src/main/java/techreborn/tiles/teir1/TileCompressor.java
# src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java
# src/main/java/techreborn/tiles/teir1/TileExtractor.java
# src/main/java/techreborn/tiles/teir1/TileGrinder.java
# src/main/java/techreborn/tiles/teir1/TileRecycler.java
This commit is contained in:
parent
9b882e75ce
commit
cdae866b2d
87 changed files with 3721 additions and 1277 deletions
|
@ -15,29 +15,37 @@ import java.util.HashMap;
|
|||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class IDSUManager {
|
||||
public class IDSUManager
|
||||
{
|
||||
|
||||
public static final String savename = "idsu.json";
|
||||
public static IDSUManager INSTANCE;
|
||||
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<>();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldSave(WorldEvent.Save event) {
|
||||
public void worldSave(WorldEvent.Save event)
|
||||
{
|
||||
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.getWorld())) {
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
|
||||
{
|
||||
if (worldData.containsKey(event.getWorld()))
|
||||
{
|
||||
worldData.get(event.getWorld()).save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldLoad(WorldEvent.Load event) {
|
||||
public void worldLoad(WorldEvent.Load event)
|
||||
{
|
||||
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.getWorld())) {
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
|
||||
{
|
||||
if (worldData.containsKey(event.getWorld()))
|
||||
{
|
||||
worldData.get(event.getWorld()).load();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(event.getWorld());
|
||||
worldData.put(event.getWorld(), worldSaveData);
|
||||
worldSaveData.load();
|
||||
|
@ -46,10 +54,13 @@ public class IDSUManager {
|
|||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void worldClosed(WorldEvent.Unload event) {
|
||||
public void worldClosed(WorldEvent.Unload event)
|
||||
{
|
||||
if (event.getWorld() != null && event.getWorld().getSaveHandler() != null
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.getWorld())) {
|
||||
&& event.getWorld().getSaveHandler().getWorldDirectory() != null)
|
||||
{
|
||||
if (worldData.containsKey(event.getWorld()))
|
||||
{
|
||||
worldData.get(event.getWorld()).save();
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +68,13 @@ public class IDSUManager {
|
|||
worldData.clear();
|
||||
}
|
||||
|
||||
public IDSUValueSaveData getSaveDataForWorld(World world, String channel) {
|
||||
if (worldData.containsKey(world)) {
|
||||
public IDSUValueSaveData getSaveDataForWorld(World world, String channel)
|
||||
{
|
||||
if (worldData.containsKey(world))
|
||||
{
|
||||
return worldData.get(world).getSaves(channel);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world, worldSaveData);
|
||||
worldSaveData.load();
|
||||
|
@ -68,10 +82,13 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
|
||||
if (worldData.containsKey(world)) {
|
||||
public IDSUWorldSaveData getWorldDataFormWorld(World world)
|
||||
{
|
||||
if (worldData.containsKey(world))
|
||||
{
|
||||
return worldData.get(world);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world, worldSaveData);
|
||||
worldSaveData.load();
|
||||
|
@ -79,25 +96,31 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void loadFromString(String json, World world) {
|
||||
if (json.equals("EMPTY")) {
|
||||
public void loadFromString(String json, World world)
|
||||
{
|
||||
if (json.equals("EMPTY"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
IDSUWorldSaveData worldSaveData;
|
||||
if (worldData.containsKey(world)) {
|
||||
if (worldData.containsKey(world))
|
||||
{
|
||||
worldSaveData = worldData.get(world);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world, worldSaveData);
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() {
|
||||
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>()
|
||||
{
|
||||
}.getType();
|
||||
worldSaveData.idsuValues.clear();
|
||||
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
|
||||
}
|
||||
|
||||
public class IDSUWorldSaveData {
|
||||
public class IDSUWorldSaveData
|
||||
{
|
||||
|
||||
public TreeMap<String, IDSUValueSaveData> idsuValues = new TreeMap<>();
|
||||
|
||||
|
@ -109,90 +132,114 @@ public class IDSUManager {
|
|||
|
||||
File file;
|
||||
|
||||
public IDSUWorldSaveData(World world) {
|
||||
public IDSUWorldSaveData(World world)
|
||||
{
|
||||
this.world = world;
|
||||
this.saveHandler = world.getSaveHandler();
|
||||
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
|
||||
file = new File(folder, savename);
|
||||
}
|
||||
|
||||
public IDSUValueSaveData getSaves(String udid) {
|
||||
if (udid == null) {
|
||||
public IDSUValueSaveData getSaves(String udid)
|
||||
{
|
||||
if (udid == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (idsuValues.containsKey(udid)) {
|
||||
if (idsuValues.containsKey(udid))
|
||||
{
|
||||
return idsuValues.get(udid);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
IDSUValueSaveData data = new IDSUValueSaveData();
|
||||
idsuValues.put(udid, data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (!file.exists()) {
|
||||
public void load()
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>() {
|
||||
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>()
|
||||
{
|
||||
}.getType();
|
||||
idsuValues.clear();
|
||||
idsuValues = gson.fromJson(reader, typeOfHashMap);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (idsuValues.isEmpty()) {
|
||||
public void save()
|
||||
{
|
||||
if (idsuValues.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!file.exists()) {
|
||||
if (!folder.exists()) {
|
||||
if (!file.exists())
|
||||
{
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdirs();
|
||||
}
|
||||
try {
|
||||
try
|
||||
{
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json = gson.toJson(idsuValues);
|
||||
try {
|
||||
try
|
||||
{
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class IDSUValueSaveData {
|
||||
public class IDSUValueSaveData
|
||||
{
|
||||
|
||||
public double storedPower = 0;
|
||||
|
||||
public IDSUValueSaveData(double storedPower) {
|
||||
public IDSUValueSaveData(double storedPower)
|
||||
{
|
||||
this.storedPower = storedPower;
|
||||
}
|
||||
|
||||
public IDSUValueSaveData() {
|
||||
public IDSUValueSaveData()
|
||||
{
|
||||
}
|
||||
|
||||
public double getStoredPower() {
|
||||
public double getStoredPower()
|
||||
{
|
||||
return storedPower;
|
||||
}
|
||||
|
||||
public void setStoredPower(double storedPower) {
|
||||
public void setStoredPower(double storedPower)
|
||||
{
|
||||
this.storedPower = storedPower;
|
||||
}
|
||||
|
||||
public void addEnergy(double storedPower) {
|
||||
public void addEnergy(double storedPower)
|
||||
{
|
||||
this.storedPower += storedPower;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package techreborn.tiles.idsu;
|
||||
|
||||
import reborncore.common.IWrenchable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.common.IWrenchable;
|
||||
import reborncore.common.tile.TilePowerAcceptorProducer;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.power.EnergyUtils;
|
||||
|
||||
public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
|
||||
public class TileIDSU extends TilePowerAcceptor implements IWrenchable
|
||||
{
|
||||
|
||||
public String ownerUdid;
|
||||
public int tier;
|
||||
|
@ -23,67 +23,111 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
|
|||
private double euChange;
|
||||
private int ticks;
|
||||
|
||||
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
||||
public TileIDSU(int tier1, int output1, int maxStorage1)
|
||||
{
|
||||
super(tier1);
|
||||
this.tier = tier1;
|
||||
this.output = output1;
|
||||
this.maxStorage = maxStorage1;
|
||||
}
|
||||
|
||||
public TileIDSU() {
|
||||
public TileIDSU()
|
||||
{
|
||||
this(5, 2048, 100000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy() {
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
||||
public double getEnergy()
|
||||
{
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy) {
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
||||
public void setEnergy(double energy)
|
||||
{
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxPower() {
|
||||
public void readFromNBTWithoutCoords(NBTTagCompound tag)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxPower()
|
||||
{
|
||||
return 1000000000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPowerTier getTier() {
|
||||
return EnumPowerTier.INSANE;
|
||||
public boolean canAcceptEnergy(EnumFacing direction)
|
||||
{
|
||||
return getFacingEnum() != direction;
|
||||
}
|
||||
|
||||
public float getChargeLevel() {
|
||||
@Override
|
||||
public boolean canProvideEnergy(EnumFacing direction)
|
||||
{
|
||||
return getFacingEnum() == direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxInput()
|
||||
{
|
||||
return maxStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumPowerTier getTier()
|
||||
{
|
||||
return EnumPowerTier.EXTREME;
|
||||
}
|
||||
|
||||
public float getChargeLevel()
|
||||
{
|
||||
float ret = (float) this.getEnergy() / (float) this.maxStorage;
|
||||
if (ret > 1.0F) {
|
||||
if (ret > 1.0F)
|
||||
{
|
||||
ret = 1.0F;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound)
|
||||
{
|
||||
super.readFromNBT(nbttagcompound);
|
||||
this.ownerUdid = nbttagcompound.getString("ownerUdid");
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound)
|
||||
{
|
||||
super.writeToNBT(nbttagcompound);
|
||||
if (ownerUdid == null || StringUtils.isEmpty(ownerUdid)) {
|
||||
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid))
|
||||
{
|
||||
return nbttagcompound;
|
||||
}
|
||||
nbttagcompound.setString("ownerUdid", this.ownerUdid);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
super.update();
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
|
||||
euChange = -1;
|
||||
|
@ -101,55 +145,38 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
|
|||
|
||||
if (!worldObj.isRemote && getEnergy() > 0) {
|
||||
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
||||
for(EnumFacing facing : EnumFacing.VALUES) {
|
||||
double disposed = emitEnergy(facing, maxOutput);
|
||||
if(disposed != 0) {
|
||||
maxOutput -= disposed;
|
||||
useEnergy(disposed);
|
||||
if (maxOutput == 0) return;
|
||||
}
|
||||
}
|
||||
useEnergy(EnergyUtils.dispatchEnergyToNeighbours(worldObj, getPos(), this, maxOutput));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO move to RebornCore
|
||||
public double emitEnergy(EnumFacing enumFacing, double amount) {
|
||||
BlockPos pos = getPos().offset(enumFacing);
|
||||
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
|
||||
worldObj, enumFacing.getOpposite(), pos);
|
||||
if(receiver != null) {
|
||||
return receiver.receiveEnergy(amount, false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1) {
|
||||
@Override public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
@Override public EnumFacing getFacing()
|
||||
{
|
||||
return getFacingEnum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wrenchCanRemove(EntityPlayer p0) {
|
||||
@Override public boolean wrenchCanRemove(EntityPlayer p0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWrenchDropRate() {
|
||||
@Override public float getWrenchDropRate()
|
||||
{
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
||||
{
|
||||
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
|
||||
writeToNBT(tileEntity);
|
||||
|
@ -158,32 +185,40 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
|
|||
return dropStack;
|
||||
}
|
||||
|
||||
public double getEuChange() {
|
||||
if (euChange == -1) {
|
||||
public double getEuChange()
|
||||
{
|
||||
if (euChange == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (euChange / ticks);
|
||||
}
|
||||
|
||||
public void handleGuiInputFromClient(int id) {
|
||||
if (id == 0) {
|
||||
public void handleGuiInputFromClient(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
output += 256;
|
||||
}
|
||||
if (id == 1) {
|
||||
if (id == 1)
|
||||
{
|
||||
output += 64;
|
||||
}
|
||||
if (id == 2) {
|
||||
if (id == 2)
|
||||
{
|
||||
output -= 64;
|
||||
}
|
||||
if (id == 3) {
|
||||
if (id == 3)
|
||||
{
|
||||
output -= 256;
|
||||
}
|
||||
if (output > 4096) {
|
||||
if (output > 4096)
|
||||
{
|
||||
output = 4096;
|
||||
}
|
||||
if (output <= -1) {
|
||||
if (output <= -1)
|
||||
{
|
||||
output = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue