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()){
|
for(Item item : Item.values()){
|
||||||
write("item." + item.name() + ".name=" + item.name());
|
write("item." + item.name() + ".name=" + item.name());
|
||||||
}
|
}
|
||||||
for(Liquid liquid : Liquid.values()){
|
for(Liquid liquid : Liquid.getAllLiquids()){
|
||||||
write("liquid." + liquid.name() + ".name=" + liquid.name());
|
write("liquid." + liquid.name + ".name=" + liquid.name);
|
||||||
}
|
}
|
||||||
for(Block block : Block.getAllBlocks()){
|
for(Block block : Block.getAllBlocks()){
|
||||||
write("block." + block.name + ".name=" + block.formalName);
|
write("block." + block.name + ".name=" + block.formalName);
|
||||||
|
|||||||
@@ -1,26 +1,41 @@
|
|||||||
package io.anuke.mindustry.resource;
|
package io.anuke.mindustry.resource;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
|
|
||||||
public enum Liquid{
|
public class Liquid {
|
||||||
water(Color.ROYAL),
|
|
||||||
plasma(Color.CORAL),
|
public static final Array<Liquid> liquids = new Array<>();
|
||||||
lava(Color.valueOf("ed5334")),
|
|
||||||
oil(Color.valueOf("292929"));
|
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 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.color = new Color(color);
|
||||||
|
|
||||||
|
this.id = liquids.size;
|
||||||
|
|
||||||
|
Liquid.liquids.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String localized(){
|
public String localizedName(){
|
||||||
return Bundles.get("liquid."+name() + ".name");
|
return Bundles.get("liquid."+ this.name + ".name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
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
|
@Override
|
||||||
public void write(DataOutputStream stream) throws IOException{
|
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));
|
stream.writeByte((byte)(liquidAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInputStream stream) throws IOException{
|
public void read(DataInputStream stream) throws IOException{
|
||||||
byte ordinal = stream.readByte();
|
byte id = stream.readByte();
|
||||||
liquid = ordinal == -1 ? null : Liquid.values()[ordinal];
|
liquid = id == -1 ? null : Liquid.liquids.get(id);
|
||||||
liquidAmount = stream.readByte();
|
liquidAmount = stream.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,15 +119,15 @@ public class LiquidPowerGenerator extends Generator implements LiquidAcceptor{
|
|||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream stream) throws IOException{
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
super.write(stream);
|
super.write(stream);
|
||||||
stream.writeByte(liquid == null ? -1 : liquid.ordinal());
|
stream.writeByte(liquid == null ? -1 : liquid.id);
|
||||||
stream.writeByte((byte)(liquidAmount));
|
stream.writeByte((byte)(liquidAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInputStream stream) throws IOException{
|
public void read(DataInputStream stream) throws IOException{
|
||||||
super.read(stream);
|
super.read(stream);
|
||||||
byte ordinal = stream.readByte();
|
byte id = stream.readByte();
|
||||||
liquid = ordinal == -1 ? null : Liquid.values()[ordinal];
|
liquid = id == -1 ? null : Liquid.liquids.get(id);
|
||||||
liquidAmount = stream.readByte();
|
liquidAmount = stream.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user