c l e a n u p
This commit is contained in:
@@ -15,7 +15,7 @@ public class ConsumeModule extends BlockModule{
|
||||
|
||||
public void update(){
|
||||
//everything is valid here
|
||||
if(entity.tile.isEnemyCheat()){
|
||||
if(entity.tile().isEnemyCheat()){
|
||||
valid = optionalValid = true;
|
||||
return;
|
||||
}
|
||||
@@ -23,9 +23,9 @@ public class ConsumeModule extends BlockModule{
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
optionalValid = true;
|
||||
boolean docons = entity.block.shouldConsume(entity.tile) && entity.block.productionValid(entity.tile);
|
||||
boolean docons = entity.block().shouldConsume(entity.tile()) && entity.block().productionValid(entity.tile());
|
||||
|
||||
for(Consume cons : entity.block.consumes.all()){
|
||||
for(Consume cons : entity.block().consumes.all()){
|
||||
if(cons.isOptional()) continue;
|
||||
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
@@ -35,7 +35,7 @@ public class ConsumeModule extends BlockModule{
|
||||
valid &= cons.valid(entity);
|
||||
}
|
||||
|
||||
for(Consume cons : entity.block.consumes.optionals()){
|
||||
for(Consume cons : entity.block().consumes.optionals()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
@@ -45,13 +45,13 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.block.consumes.all()){
|
||||
for(Consume cons : entity.block().consumes.all()){
|
||||
cons.trigger(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean valid(){
|
||||
return valid && entity.block.shouldConsume(entity.tile);
|
||||
return valid && entity.block().shouldConsume(entity.tile());
|
||||
}
|
||||
|
||||
public boolean optionalValid(){
|
||||
|
||||
@@ -12,6 +12,9 @@ public class ItemModule extends BlockModule{
|
||||
private int[] items = new int[content.items().size];
|
||||
private int total;
|
||||
|
||||
// Make the take() loop persistent so it does not return the same item twice in a row unless there is nothing else to return.
|
||||
protected int takeRotation;
|
||||
|
||||
public void forEach(ItemConsumer cons){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
@@ -68,10 +71,13 @@ public class ItemModule extends BlockModule{
|
||||
|
||||
public Item take(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
items[i]--;
|
||||
total--;
|
||||
return content.item(i);
|
||||
int index = (i + takeRotation);
|
||||
if(index >= items.length) index -= items.length; //conditional instead of mod
|
||||
if(items[index] > 0){
|
||||
items[index] --;
|
||||
total --;
|
||||
takeRotation = index + 1;
|
||||
return content.item(index % items.length);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user