Advertisement
GenuineSounds

IMetal

Feb 26th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. package com.genuineflix.metal.api;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.nbt.NBTTagCompound;
  8.  
  9. public interface IMetal extends SaveableData, LoadableData<IMetal> {
  10.  
  11.     public String getName();
  12.  
  13.     public String getDisplayName();
  14.  
  15.     public Block getOre();
  16.  
  17.     public Block getBlock();
  18.  
  19.     public Item getIngot();
  20.  
  21.     public Item getNugget();
  22.  
  23.     public Item getDust();
  24.  
  25.     public Generation getGeneration();
  26.  
  27.     public List<Compound> getCompounds();
  28.  
  29.     public void setGeneration(Generation generation);
  30.  
  31.     public void setCompounds(Compound... components);
  32.  
  33.     public boolean isComposite();
  34.  
  35.     public static class Generation implements SaveableData, LoadableData<Generation> {
  36.  
  37.         public float rarity;
  38.         public float depth;
  39.         public int nodes;
  40.         public int size;
  41.         public float spread;
  42.         public float hardness;
  43.         public float resistance;
  44.         private boolean generate;
  45.  
  46.         public Generation() {}
  47.  
  48.         public Generation(final float rarity, final float depth, final int nodes, final int size, final float spread, final float hardness, final float resistance) {
  49.             this(rarity, depth, nodes, size, spread, hardness, resistance, false);
  50.         }
  51.  
  52.         public Generation(final float rarity, final float depth, final int nodes, final int size, final float spread, final float hardness, final float resistance, final boolean generate) {
  53.             this.rarity = rarity;
  54.             this.depth = depth;
  55.             this.nodes = nodes;
  56.             this.size = size;
  57.             this.spread = spread;
  58.             this.hardness = hardness;
  59.             this.resistance = resistance;
  60.             this.generate = generate;
  61.         }
  62.  
  63.         public boolean canGenerate() {
  64.             return generate;
  65.         }
  66.  
  67.         public void setGenerate(final boolean generate) {
  68.             this.generate = generate;
  69.         }
  70.  
  71.         @Override
  72.         public NBTTagCompound save(final NBTTagCompound compound) {
  73.             compound.setFloat("rarity", rarity);
  74.             compound.setFloat("depth", depth);
  75.             compound.setInteger("nodes", nodes);
  76.             compound.setInteger("size", size);
  77.             compound.setFloat("spread", spread);
  78.             compound.setFloat("hardness", hardness);
  79.             compound.setFloat("resistance", resistance);
  80.             compound.setBoolean("generate", generate);
  81.             return compound;
  82.         }
  83.  
  84.         @Override
  85.         public Generation load(final NBTTagCompound compound) {
  86.             rarity = compound.getFloat("rarity");
  87.             depth = compound.getFloat("depth");
  88.             nodes = compound.getInteger("nodes");
  89.             size = compound.getInteger("size");
  90.             spread = compound.getFloat("spread");
  91.             hardness = compound.getFloat("hardness");
  92.             resistance = compound.getFloat("resistance");
  93.             generate = compound.hasKey("generate") && compound.getBoolean("generate");
  94.             return this;
  95.         }
  96.     }
  97.  
  98.     public static class Compound implements SaveableData, LoadableData<Compound> {
  99.  
  100.         public IMetal metal;
  101.         public int factor;
  102.  
  103.         public Compound() {}
  104.  
  105.         public Compound(final IMetal metal) {
  106.             this(metal, 1);
  107.         }
  108.  
  109.         public Compound(final IMetal metal, final int factor) {
  110.             this.metal = metal;
  111.             this.factor = factor;
  112.         }
  113.  
  114.         @Override
  115.         public boolean equals(final Object obj) {
  116.             if (super.equals(obj))
  117.                 return true;
  118.             return obj instanceof Compound && metal.equals(((Compound) obj).metal);
  119.         }
  120.  
  121.         @Override
  122.         public NBTTagCompound save(final NBTTagCompound compound) {
  123.             compound.setString("class", metal.getClass().getName());
  124.             compound.setTag("metal", metal.save(new NBTTagCompound()));
  125.             compound.setInteger("factor", factor);
  126.             return compound;
  127.         }
  128.  
  129.         @SuppressWarnings("unchecked")
  130.         @Override
  131.         public Compound load(final NBTTagCompound compound) {
  132.             try {
  133.                 metal = ((Class<IMetal>) ClassLoader.getSystemClassLoader().loadClass(compound.getString("class"))).newInstance().load(compound.getCompoundTag("metal"));
  134.                 factor = compound.getInteger("factor");
  135.                 return this;
  136.             }
  137.             catch (final Exception e) {}
  138.             return null;
  139.         }
  140.     }
  141. }
  142.  
  143. interface LoadableData<T> {
  144.  
  145.     public T load(NBTTagCompound compound);
  146. }
  147.  
  148. interface SaveableData {
  149.  
  150.     public NBTTagCompound save(NBTTagCompound compound);
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement