This repository has been archived by the owner on Jan 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fulfill #239 + fully block stuff ability
- Loading branch information
Showing
4 changed files
with
123 additions
and
70 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/net/minecraftforge/cauldron/configuration/ArraySetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.minecraftforge.cauldron.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
|
||
public abstract class ArraySetting<T> extends Setting<String>{ | ||
public ArraySetting(String path, String def, String description) { | ||
super(path, def, description); | ||
initArr(def); | ||
} | ||
|
||
protected HashSet<T> value_set; | ||
protected ArrayList<T> value_array; | ||
|
||
public boolean contains(T t) | ||
{ | ||
return value_set.contains(t); | ||
} | ||
|
||
public T get(int i) | ||
{ | ||
if(i < 0 || i > value_array.size() - 1) return null; | ||
|
||
return value_array.get(i); | ||
|
||
} | ||
|
||
public abstract void initArr(String array); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 28 additions & 27 deletions
55
src/main/java/net/minecraftforge/cauldron/configuration/IntArraySetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,50 @@ | ||
package net.minecraftforge.cauldron.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
|
||
public class IntArraySetting extends Setting<Integer[]> { | ||
private Integer[] value; | ||
public class IntArraySetting extends ArraySetting<Integer> { | ||
private String value; | ||
private ConfigBase config; | ||
|
||
public IntArraySetting(ConfigBase config, String path, Integer[] def, String description) | ||
public IntArraySetting(ConfigBase config, String path, String def, String description) | ||
{ | ||
super(path, def, description); | ||
this.value = def; | ||
|
||
this.config = config; | ||
} | ||
|
||
@Override | ||
public Integer[] getValue() | ||
public String getValue() | ||
{ | ||
return value; | ||
} | ||
|
||
@Override | ||
public void setValue(String value) | ||
{ | ||
String[] vals = value.split(","); | ||
ArrayList<Integer> minty = new ArrayList<Integer>(vals.length); | ||
for(int i = 0; i < vals.length; i++) | ||
{ | ||
try | ||
{ | ||
minty.add(Integer.parseInt(vals[i])); | ||
} | ||
catch(Exception e) | ||
{ | ||
|
||
} | ||
catch(Error eeek) | ||
{ | ||
|
||
} | ||
} | ||
this.value = new Integer[minty.size()]; | ||
for(int i = 0; i < this.value.length; i++) | ||
{ | ||
this.value[i] = minty.get(i); | ||
} | ||
config.set(path, this.value); | ||
|
||
config.set(path, this.value = value); | ||
} | ||
|
||
@Override | ||
public void initArr(String array) { | ||
String[] potential_values = array.split(","); | ||
this.value_array = new ArrayList<Integer>(potential_values.length); | ||
this.value_set = new HashSet<Integer>(potential_values.length); | ||
for(String potval : potential_values) | ||
{ | ||
try | ||
{ | ||
this.value_array.add(Integer.parseInt(potval)); | ||
} | ||
catch ( Throwable t) | ||
{ | ||
System.out.println("[Thermos] Failed to add an option from config file"); | ||
t.printStackTrace(); | ||
} | ||
} | ||
this.value_set.addAll(value_array); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/minecraftforge/cauldron/configuration/StringArraySetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.minecraftforge.cauldron.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
|
||
public class StringArraySetting extends ArraySetting<String> { | ||
private String value; | ||
private ConfigBase config; | ||
|
||
public StringArraySetting(ConfigBase config, String path, String def, | ||
String description) { | ||
super(path, def, description); | ||
this.value = def; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void setValue(String value) { | ||
|
||
config.set(path, this.value = value); | ||
} | ||
|
||
@Override | ||
public void initArr(String values) | ||
{ | ||
String[] vals = values.split(","); | ||
|
||
value_array = new ArrayList<String>(vals.length); | ||
value_set = new HashSet<String>(vals.length); | ||
for(String val : vals) | ||
{ | ||
value_array.add(val); | ||
} | ||
value_set.addAll(value_array); | ||
} | ||
} |