Read-only component fields / Removed get/set prefix

This commit is contained in:
Anuken
2020-02-04 12:14:09 -05:00
parent 1d0cfd4435
commit 36b9451e01
93 changed files with 637 additions and 587 deletions

View File

@ -8,7 +8,6 @@ import mindustry.content.*;
import mindustry.core.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.entities.type.*;
import mindustry.entities.type.base.*;
import mindustry.entities.units.*;
import mindustry.game.*;
@ -143,12 +142,12 @@ public class ApplicationTests{
void blockInventories(){
multiblock();
Tile tile = world.tile(4, 4);
tile.entity.getItems().add(Items.coal, 5);
tile.entity.getItems().add(Items.titanium, 50);
assertEquals(tile.entity.getItems().total(), 55);
tile.entity.getItems().remove(Items.phasefabric, 10);
tile.entity.getItems().remove(Items.titanium, 10);
assertEquals(tile.entity.getItems().total(), 45);
tile.entity.items().add(Items.coal, 5);
tile.entity.items().add(Items.titanium, 50);
assertEquals(tile.entity.items().total(), 55);
tile.entity.items().remove(Items.phasefabric, 10);
tile.entity.items().remove(Items.titanium, 10);
assertEquals(tile.entity.items().total(), 45);
}
@Test
@ -422,7 +421,7 @@ public class ApplicationTests{
Tile core = world.tile(5, 5);
core.set(Blocks.coreShard, Team.sharded);
for(Item item : content.items()){
core.entity.getItems().set(item, 3000);
core.entity.items().set(item, 3000);
}
assertEquals(core.entity, state.teams.get(Team.sharded).core());
@ -439,12 +438,12 @@ public class ApplicationTests{
assertEquals(capacity - 1, deposited);
tile.block().handleStack(item, capacity - 1, tile, unit);
assertEquals(tile.entity.getItems().get(item), capacity - 1);
assertEquals(tile.entity.items().get(item), capacity - 1);
int overflow = tile.block().acceptStack(item, 10, tile, unit);
assertEquals(1, overflow);
tile.block().handleStack(item, 1, tile, unit);
assertEquals(capacity, tile.entity.getItems().get(item));
assertEquals(capacity, tile.entity.items().get(item));
}
}

View File

@ -87,13 +87,13 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
createGenerator(inputType);
assertTrue(generator.acceptLiquid(tile, null, liquid, availableLiquidAmount), inputType + " | " + parameterDescription + ": Liquids which will be declined by the generator don't need to be tested - The code won't be called for those cases.");
entity.getLiquids().add(liquid, availableLiquidAmount);
entity.liquids().add(liquid, availableLiquidAmount);
entity.cons.update();
// Perform an update on the generator once - This should use up any resource up to the maximum liquid usage
generator.update(tile);
assertEquals(expectedRemainingLiquidAmount, entity.getLiquids().get(liquid), inputType + " | " + parameterDescription + ": Remaining liquid amount mismatch.");
assertEquals(expectedRemainingLiquidAmount, entity.liquids().get(liquid), inputType + " | " + parameterDescription + ": Remaining liquid amount mismatch.");
assertEquals(expectedEfficiency, entity.productionEfficiency, inputType + " | " + parameterDescription + ": Efficiency mismatch.");
}
@ -130,7 +130,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
assertTrue(generator.acceptItem(item, tile, null), inputType + " | " + parameterDescription + ": Items which will be declined by the generator don't need to be tested - The code won't be called for those cases.");
if(amount > 0){
entity.getItems().add(item, amount);
entity.items().add(item, amount);
}
entity.cons.update();
@ -138,7 +138,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
try{
generator.update(tile);
assertEquals(expectedRemainingItemAmount, entity.getItems().get(item), inputType + " | " + parameterDescription + ": Remaining item amount mismatch.");
assertEquals(expectedRemainingItemAmount, entity.items().get(item), inputType + " | " + parameterDescription + ": Remaining item amount mismatch.");
assertEquals(expectedEfficiency, entity.productionEfficiency, inputType + " | " + parameterDescription + ": Efficiency mismatch.");
}catch(NullPointerException e){
e.printStackTrace();
@ -162,7 +162,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
createGenerator(inputType);
// Burn a single coal and test for the duration
entity.getItems().add(Items.coal, 1);
entity.items().add(Items.coal, 1);
entity.cons.update();
generator.update(tile);

View File

@ -87,19 +87,19 @@ public class PowerTestFixture{
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
tile.entity = block.newEntity().init(tile, false);
tile.entity.getCons() = new ConsumeModule(tile.entity);
if(block.hasItems) tile.entity.getItems() = new ItemModule();
if(block.hasLiquids) tile.entity.getLiquids() = new LiquidModule();
tile.entity.cons() = new ConsumeModule(tile.entity);
if(block.hasItems) tile.entity.items() = new ItemModule();
if(block.hasLiquids) tile.entity.liquids() = new LiquidModule();
if(block.hasPower){
tile.entity.getPower() = new PowerModule();
tile.entity.getPower().graph = new PowerGraph(){
tile.entity.power() = new PowerModule();
tile.entity.power().graph = new PowerGraph(){
//assume there's always something consuming power
@Override
public float getUsageFraction(){
return 1f;
}
};
tile.entity.getPower().graph.add(tile);
tile.entity.power().graph.add(tile);
}
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound