This commit is contained in:
Anuken
2020-09-12 12:47:18 -04:00
parent 197b67f8c1
commit fa9611e28c
14 changed files with 64 additions and 45 deletions

View File

@@ -196,7 +196,7 @@ public class Block extends UnlockableContent{
/** Whether this block has instant transfer.*/
public boolean instantTransfer = false;
protected Prov<Building> entityType = null; //initialized later
public Prov<Building> buildType = null; //initialized later
public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>();
protected TextureRegion[] generatedIcons;
@@ -217,7 +217,7 @@ public class Block extends UnlockableContent{
public Block(String name){
super(name);
initEntity();
initBuilding();
}
public void drawBase(Tile tile){
@@ -499,8 +499,8 @@ public class Block extends UnlockableContent{
return destructible || update;
}
public final Building newEntity(){
return entityType.get();
public final Building newBuilding(){
return buildType.get();
}
public Rect bounds(int x, int y, Rect rect){
@@ -576,7 +576,7 @@ public class Block extends UnlockableContent{
Arrays.sort(requirements, Structs.comparingInt(i -> i.item.id));
}
protected void initEntity(){
protected void initBuilding(){
//attempt to find the first declared class and use it as the entity type
try{
Class<?> current = getClass();
@@ -585,13 +585,13 @@ public class Block extends UnlockableContent{
current = current.getSuperclass();
}
while(entityType == null && Block.class.isAssignableFrom(current)){
while(buildType == null && Block.class.isAssignableFrom(current)){
//first class that is subclass of Building
Class<?> type = Structs.find(current.getDeclaredClasses(), t -> Building.class.isAssignableFrom(t) && !t.isInterface());
if(type != null){
//these are inner classes, so they have an implicit parameter generated
Constructor<? extends Building> cons = (Constructor<? extends Building>)type.getDeclaredConstructor(type.getDeclaringClass());
entityType = () -> {
buildType = () -> {
try{
return cons.newInstance(this);
}catch(Exception e){
@@ -607,9 +607,9 @@ public class Block extends UnlockableContent{
}catch(Throwable ignored){
}
if(entityType == null){
if(buildType == null){
//assign default value
entityType = Building::create;
buildType = Building::create;
}
}

View File

@@ -45,7 +45,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
this.block = wall;
//update entity and create it if needed
changeEntity(Team.derelict, wall::newEntity, 0);
changeEntity(Team.derelict, wall::newBuilding, 0);
changed();
}
@@ -174,7 +174,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
}
public void setBlock(@NonNull Block type, Team team, int rotation){
setBlock(type, team, rotation, type::newEntity);
setBlock(type, team, rotation, type::newBuilding);
}
public void setBlock(@NonNull Block type, Team team, int rotation, Prov<Building> entityprov){

View File

@@ -103,9 +103,8 @@ public class Floor extends Block{
super.init();
if(wall == Blocks.air){
wall = content.block(name + "Rocks");
if(wall == null) wall = content.block(name + "rocks");
if(wall == null) wall = content.block(name.replace("darksand", "dune") + "rocks");
wall = content.block(name + "-wall");
if(wall == null) wall = content.block(name.replace("darksand", "dune") + "-wall");
}
//keep default value if not found...

View File

@@ -14,7 +14,7 @@ public class BlockPayload implements Payload{
public Building entity;
public BlockPayload(Block block, Team team){
this.entity = block.newEntity().create(block, team);
this.entity = block.newBuilding().create(block, team);
}
public BlockPayload(Building entity){