Changed Liquid to class, tried to keep it as similar to the enum as possible to avoid incompatibilities.
This commit is contained in:
@@ -53,8 +53,8 @@ public class BundleGen {
|
||||
for(Item item : Item.values()){
|
||||
write("item." + item.name() + ".name=" + item.name());
|
||||
}
|
||||
for(Liquid liquid : Liquid.values()){
|
||||
write("liquid." + liquid.name() + ".name=" + liquid.name());
|
||||
for(Liquid liquid : Liquid.getAllLiquids()){
|
||||
write("liquid." + liquid.name + ".name=" + liquid.name);
|
||||
}
|
||||
for(Block block : Block.getAllBlocks()){
|
||||
write("block." + block.name + ".name=" + block.formalName);
|
||||
|
||||
@@ -1,26 +1,41 @@
|
||||
package io.anuke.mindustry.resource;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public enum Liquid{
|
||||
water(Color.ROYAL),
|
||||
plasma(Color.CORAL),
|
||||
lava(Color.valueOf("ed5334")),
|
||||
oil(Color.valueOf("292929"));
|
||||
public class Liquid {
|
||||
|
||||
public static final Array<Liquid> liquids = new Array<>();
|
||||
|
||||
public static final Liquid water = new Liquid("water", Color.ROYAL);
|
||||
public static final Liquid plasma = new Liquid("plasma", Color.CORAL);
|
||||
public static final Liquid lava = new Liquid("lava", Color.valueOf("ed5334"));
|
||||
public static final Liquid oil = new Liquid("oil", Color.valueOf("292929"));
|
||||
|
||||
public final Color color;
|
||||
public final String name;
|
||||
public final int id;
|
||||
|
||||
private Liquid(Color color){
|
||||
public Liquid(String name, Color color) {
|
||||
this.name = name;
|
||||
this.color = new Color(color);
|
||||
|
||||
this.id = liquids.size;
|
||||
|
||||
Liquid.liquids.add(this);
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
return Bundles.get("liquid."+name() + ".name");
|
||||
public String localizedName(){
|
||||
return Bundles.get("liquid."+ this.name + ".name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return localized();
|
||||
return localizedName();
|
||||
}
|
||||
|
||||
public static Array<Liquid> getAllLiquids() {
|
||||
return Liquid.liquids;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +123,14 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
stream.writeByte(liquid == null ? -1 : liquid.ordinal());
|
||||
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||
stream.writeByte((byte)(liquidAmount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
byte ordinal = stream.readByte();
|
||||
liquid = ordinal == -1 ? null : Liquid.values()[ordinal];
|
||||
byte id = stream.readByte();
|
||||
liquid = id == -1 ? null : Liquid.liquids.get(id);
|
||||
liquidAmount = stream.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,15 +119,15 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(liquid == null ? -1 : liquid.ordinal());
|
||||
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||
stream.writeByte((byte)(liquidAmount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
super.read(stream);
|
||||
byte ordinal = stream.readByte();
|
||||
liquid = ordinal == -1 ? null : Liquid.values()[ordinal];
|
||||
byte id = stream.readByte();
|
||||
liquid = id == -1 ? null : Liquid.liquids.get(id);
|
||||
liquidAmount = stream.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user