Skip to content

Commit

Permalink
Spread out item inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Nov 2, 2024
1 parent 9284225 commit bce4f97
Showing 1 changed file with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ModularTurret(String name){

acceptsPayload = true;
outputsPayload = false;
hasItems = true; //To allow stack acceptance
hasLiquids = true;
hasPower = true;
outputsLiquid = false;
Expand Down Expand Up @@ -173,6 +174,7 @@ public boolean canBreak(Tile tile){
public class ModularTurretBuild extends PayloadBlockBuild<BuildPayload> implements ControlBlock{
public Seq<TurretModuleBuild> modules = new Seq<>();
public BlockUnitc unit = (BlockUnitc)UnitTypes.block.create(team);
public int itemTarget;
protected int selNum;

@Override
Expand Down Expand Up @@ -464,10 +466,11 @@ public boolean acceptItem(Building source, Item item){

@Override
public int acceptStack(Item item, int amount, Teamc source){
TurretModuleBuild mount = modules.find(m -> m.build().acceptStack(item, amount, this) > 0);

if(mount == null) return 0;
return mount.build().acceptStack(item, amount, this);
int[] total = {0};
modules.each(m -> {
total[0] += m.build().acceptStack(item, amount, this);
});
return Math.min(total[0], amount);
}

@Override
Expand All @@ -486,21 +489,42 @@ public boolean acceptPayload(Building source, Payload payload){

@Override
public void handleItem(Building source, Item item){
TurretModuleBuild mount = modules.find(m -> m.build().acceptItem(this, item));
TurretModuleBuild mount = handleItemTarget(source, item);
mount.build().handleItem(this, item);
}

public TurretModuleBuild handleItemTarget(Building source, Item item){
if(itemTarget >= modules.size) itemTarget = 0;

if(modules.get(itemTarget).build().acceptItem(source, item)){
itemTarget++;
if(itemTarget == modules.size) itemTarget = 0;
return modules.get(itemTarget);
}else{
for(int i = 0; i < modules.size; i++){
itemTarget++;
if(itemTarget == modules.size) itemTarget = 0;
TurretModuleBuild m = modules.get(itemTarget);
if(m.build().acceptItem(source, item)){
return m;
}
}
return null; //Shouldn't be possible.
}
}

@Override
public int removeStack(Item item, int amount){
//Cannot remove items
//Cannot remove items, nothing to remove
return 0;
}

@Override
public void handleStack(Item item, int amount, Teamc source){
TurretModuleBuild mount = modules.find(m -> m.build().acceptStack(item, amount, this) > 0);

if(mount != null) mount.build().handleStack(item, amount, this);
Log.info("HUZZAH");
for(int i = 0; i < amount; i++){
handleItem(this, item);
}
}

@Override
Expand Down

0 comments on commit bce4f97

Please sign in to comment.