Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TFC.API.Crafting;
- import java.util.HashMap;
- import java.util.List;
- import TFC.API.Metal;
- public class AlloyComponentMetal {
- public AlloyComponentMetal(Metal metaltype, float units){
- this.metaltype=metaltype;
- this.units=units;
- this.subcomponents=null;
- }
- public AlloyComponentMetal(Metal metaltype, float units,HashMap<Metal,AlloyComponentMetal> subcomponents){
- this.metaltype=metaltype;
- this.units=units;
- this.subcomponents=subcomponents;
- }
- Metal metaltype;
- float units;
- HashMap<Metal,AlloyComponentMetal> subcomponents;
- public boolean hasSubcomponent(Metal metaltype){
- if (this.subcomponents == null){return false;}
- return this.subcomponents.containsKey(metaltype);
- }
- public boolean canCombine(AlloyComponentMetal other){
- if(this.metaltype != other.metaltype){return false;}
- if(this.subcomponents != null && other.subcomponents != null){
- java.util.Iterator<Metal> sub=this.subcomponents.keySet().iterator();
- while(sub.hasNext()){
- Metal type=sub.next();
- if(!(other.subcomponents.containsKey(type))){
- //same alloy, different subcomponents, cannot combine
- return false;
- }
- AlloyComponentMetal subA,subB;
- subA=this.subcomponents.get(type);
- subB=other.subcomponents.get(type);
- if(!subA.canCombine(subB)){
- return false;
- }
- }
- }
- return true;
- }
- public AlloyComponentMetal combine(AlloyComponentMetal other){
- if(this.canCombine(other)){
- AlloyComponentMetal combined=new AlloyComponentMetal(this.metaltype,this.units+other.units);
- if(this.subcomponents != null && other.subcomponents != null){
- java.util.Iterator<Metal> sub=this.subcomponents.keySet().iterator();
- while(sub.hasNext()){
- Metal type=sub.next();
- if(!(other.subcomponents.containsKey(type))){
- //same alloy, different subcomponents, cannot combine
- return null;
- }
- AlloyComponentMetal subA,subB;
- subA=this.subcomponents.get(type);
- subB=other.subcomponents.get(type);
- this.subcomponents.put(type, subA.combine(subB));
- }
- } else if(!(this.subcomponents == null && other.subcomponents == null )){
- //mismatched subcomponents
- return null;
- }
- return combined;
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement