This commit is contained in:
Anuken
2020-04-25 17:34:35 -04:00
parent 30d8737f67
commit ceee1d36e6
11 changed files with 38 additions and 41 deletions

View File

@@ -509,42 +509,39 @@ public class Block extends UnlockableContent{
}
protected void initEntity(){
//attempt to find the first declared class and use it as the entity type
try{
Class<?> current = getClass();
if(current.isAnonymousClass()){
current = current.getSuperclass();
}
while(entityType == null && Block.class.isAssignableFrom(current)){
//first class that is subclass of Tilec
Class<?> type = Structs.find(current.getDeclaredClasses(), t -> Tilec.class.isAssignableFrom(t) && !t.isInterface());
if(type != null){
//these are inner classes, so they have an implicit parameter generated
Constructor<? extends Tilec> cons = (Constructor<? extends Tilec>)type.getDeclaredConstructor(type.getDeclaringClass());
entityType = () -> {
try{
return cons.newInstance(this);
}catch(Exception e){
throw new RuntimeException(e);
}
};
}
//scan through every superclass looking for it
current = current.getSuperclass();
}
}catch(Throwable ignored){
}
if(entityType == null){
//attempt to find the first declared class and use it as the entity type
try{
Class<?> current = getClass();
if(current.isAnonymousClass()){
current = current.getSuperclass();
}
while(entityType == null && Block.class.isAssignableFrom(current)){
//first class that is subclass of Tilec
Class<?> type = Structs.find(current.getDeclaredClasses(), t -> Tilec.class.isAssignableFrom(t) && !t.isInterface());
if(type != null){
//these are inner classes, so they have an implicit parameter generated
Constructor<? extends Tilec> cons = (Constructor<? extends Tilec>)type.getDeclaredConstructor(type.getDeclaringClass());
entityType = () -> {
try{
return cons.newInstance(this);
}catch(Exception e){
throw new RuntimeException(e);
}
};
}
//scan through every superclass looking for it
current = current.getSuperclass();
}
}catch(Throwable ignored){
}
if(entityType == null){
//assign default value
entityType = TileEntity::create;
}
//assign default value
entityType = TileEntity::create;
}
}

View File

@@ -16,7 +16,6 @@ import mindustry.world.blocks.payloads.*;
import static mindustry.Vars.*;
//TODO rename
public class PayloadConveyor extends Block{
public float moveTime = 70f;
public TextureRegion topRegion, edgeRegion;
@@ -103,6 +102,7 @@ public class PayloadConveyor extends Block{
//trigger update forward
next.updateTile();
//TODO add self to queue of next conveyor, then check if this conveyor was selected next frame - selection happens deterministically
if(next.acceptPayload(this, item)){
//move forward.
next.handlePayload(this, item);
@@ -110,7 +110,7 @@ public class PayloadConveyor extends Block{
}
}else if(!blocked){
//dump item forward
float trnext = size * tilesize / 2f, cx = Geometry.d4(rotation()).x, cy = Geometry.d4(rotation()).y, rot = rotation() * 90;
float trnext = size * tilesize / 2f, cx = Geometry.d4(rotation()).x, cy = Geometry.d4(rotation()).y;
if(item.dump(x + cx * trnext, y + cy * trnext, rotation() * 90)){
item = null;