Conduit autotiling / Added Block.onProximityUpdate()

This commit is contained in:
Anuken 2018-07-10 10:14:10 -04:00
parent d31fbf3b6f
commit 66b9cdf64c
29 changed files with 379 additions and 199 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

View File

Before

Width:  |  Height:  |  Size: 267 B

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View File

@ -151,7 +151,10 @@ public class TileEntity extends BaseEntity implements TargetTrait {
for (GridPoint2 point : nearby) {
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
//remove this tile from all nearby tile's proximities
if(other != null) other = other.target();
if(other != null){
other = other.target();
other.block().onProximityUpdate(other);
}
if(other != null && other.entity != null){
other.entity.proximity.removeValue(tile, true);
}
@ -165,7 +168,12 @@ public class TileEntity extends BaseEntity implements TargetTrait {
GridPoint2[] nearby = Edges.getEdges(tile.block().size);
for (GridPoint2 point : nearby) {
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other != null) other = other.target();
if(other != null){
other.block().onProximityUpdate(other);
other = other.target();
}
if(other != null && other.entity != null){
tmpTiles.add(other);
@ -180,6 +188,8 @@ public class TileEntity extends BaseEntity implements TargetTrait {
for(Tile tile : tmpTiles){
proximity.add(tile);
}
tile.block().onProximityUpdate(tile);
}
public Array<Tile> proximity(){

View File

@ -64,6 +64,8 @@ public abstract class BaseBlock {
}
public void onProximityUpdate(Tile tile){}
public void handleItem(Item item, Tile tile, Tile source){
tile.entity.items.add(item, 1);
}

View File

@ -16,6 +16,9 @@ import java.io.IOException;
public class Conduit extends LiquidBlock {
protected final int timerFlow = timers++;
protected TextureRegion[] topRegions = new TextureRegion[7];
protected TextureRegion[] botRegions = new TextureRegion[7];
public Conduit(String name) {
super(name);
rotate = true;
@ -27,24 +30,59 @@ public class Conduit extends LiquidBlock {
super.load();
liquidRegion = Draw.region("conduit-liquid");
for (int i = 0; i < topRegions.length; i++) {
topRegions[i] = Draw.region(name + "-top-" + i);
botRegions[i] = Draw.region("conduit-bottom-" + i);
}
}
public void onProximityUpdate(Tile tile){
ConduitEntity entity = tile.entity();
entity.blendbits = 0;
if(blends(tile, 0)){
if(blends(tile, 2) && blends(tile, 1) && blends(tile, 3)) {
entity.blendbits = 3;
}else if(blends(tile, 1) && blends(tile, 3)) {
entity.blendbits = 6;
}else if(blends(tile, 1) && blends(tile, 2)) {
entity.blendbits = 2;
}else if(blends(tile, 3) && blends(tile, 2)) {
entity.blendbits = 4;
}else if(blends(tile, 1)) {
entity.blendbits = 5;
}else if(blends(tile, 3)) {
entity.blendbits = 1;
}
}else if(blends(tile, 1)) {
entity.blendbits = 5;
}else if(blends(tile, 3)) {
entity.blendbits = 1;
}
}
private boolean blends(Tile tile, int direction){
Tile other = tile.getNearby(Mathf.mod(tile.getRotation() - direction, 4));
if(other == null || !(other.block().hasLiquids)) return false;
return (tile.getNearby(tile.getRotation()) == other)
|| (!other.block().rotate || other.getNearby(other.getRotation()) == tile);
}
@Override
public void draw(Tile tile){
ConduitEntity entity = tile.entity();
LiquidModule mod = tile.entity.liquids;
int rotation = tile.getRotation() * 90;
int rotation = rotate ? tile.getRotation() * 90 : 0;
Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
Draw.colorl(0.34f);
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
Draw.color(mod.current().color);
Draw.alpha(entity.smoothLiquid);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
Draw.color();
Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
Draw.rect(topRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
}
@Override
@ -62,7 +100,10 @@ public class Conduit extends LiquidBlock {
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name() + "-bottom"), Draw.region(name() + "-top")};
if(icon == null){
icon = new TextureRegion[]{Draw.region("conduit-bottom"), Draw.region(name + "-top-0")};
}
return icon;
}
@Override
@ -78,6 +119,7 @@ public class Conduit extends LiquidBlock {
public static class ConduitEntity extends TileEntity {
public float smoothLiquid;
public byte blendbits;
@Override
public void write(DataOutputStream stream) throws IOException {