Conduit autotiling / Added Block.onProximityUpdate()
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-0.png
Normal file
After Width: | Height: | Size: 213 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-1.png
Normal file
After Width: | Height: | Size: 225 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-2.png
Normal file
After Width: | Height: | Size: 216 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-3.png
Normal file
After Width: | Height: | Size: 224 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-4.png
Normal file
After Width: | Height: | Size: 224 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-5.png
Normal file
After Width: | Height: | Size: 225 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-bottom-6.png
Normal file
After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 217 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-0.png
Normal file
After Width: | Height: | Size: 209 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-1.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-2.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-3.png
Normal file
After Width: | Height: | Size: 262 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-4.png
Normal file
After Width: | Height: | Size: 251 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-5.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
core/assets-raw/sprites/blocks/liquid/conduit-top-6.png
Normal file
After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 267 B After Width: | Height: | Size: 267 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-1.png
Normal file
After Width: | Height: | Size: 287 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-2.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-3.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-4.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-5.png
Normal file
After Width: | Height: | Size: 289 B |
BIN
core/assets-raw/sprites/blocks/liquid/pulse-conduit-top-6.png
Normal file
After Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 132 KiB After Width: | Height: | Size: 133 KiB |
@ -151,7 +151,10 @@ public class TileEntity extends BaseEntity implements TargetTrait {
|
|||||||
for (GridPoint2 point : nearby) {
|
for (GridPoint2 point : nearby) {
|
||||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||||
//remove this tile from all nearby tile's proximities
|
//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){
|
if(other != null && other.entity != null){
|
||||||
other.entity.proximity.removeValue(tile, true);
|
other.entity.proximity.removeValue(tile, true);
|
||||||
}
|
}
|
||||||
@ -165,7 +168,12 @@ public class TileEntity extends BaseEntity implements TargetTrait {
|
|||||||
GridPoint2[] nearby = Edges.getEdges(tile.block().size);
|
GridPoint2[] nearby = Edges.getEdges(tile.block().size);
|
||||||
for (GridPoint2 point : nearby) {
|
for (GridPoint2 point : nearby) {
|
||||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
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){
|
if(other != null && other.entity != null){
|
||||||
tmpTiles.add(other);
|
tmpTiles.add(other);
|
||||||
|
|
||||||
@ -180,6 +188,8 @@ public class TileEntity extends BaseEntity implements TargetTrait {
|
|||||||
for(Tile tile : tmpTiles){
|
for(Tile tile : tmpTiles){
|
||||||
proximity.add(tile);
|
proximity.add(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tile.block().onProximityUpdate(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<Tile> proximity(){
|
public Array<Tile> proximity(){
|
||||||
|
@ -64,6 +64,8 @@ public abstract class BaseBlock {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onProximityUpdate(Tile tile){}
|
||||||
|
|
||||||
public void handleItem(Item item, Tile tile, Tile source){
|
public void handleItem(Item item, Tile tile, Tile source){
|
||||||
tile.entity.items.add(item, 1);
|
tile.entity.items.add(item, 1);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ import java.io.IOException;
|
|||||||
public class Conduit extends LiquidBlock {
|
public class Conduit extends LiquidBlock {
|
||||||
protected final int timerFlow = timers++;
|
protected final int timerFlow = timers++;
|
||||||
|
|
||||||
|
protected TextureRegion[] topRegions = new TextureRegion[7];
|
||||||
|
protected TextureRegion[] botRegions = new TextureRegion[7];
|
||||||
|
|
||||||
public Conduit(String name) {
|
public Conduit(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
rotate = true;
|
rotate = true;
|
||||||
@ -27,24 +30,59 @@ public class Conduit extends LiquidBlock {
|
|||||||
super.load();
|
super.load();
|
||||||
|
|
||||||
liquidRegion = Draw.region("conduit-liquid");
|
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
|
@Override
|
||||||
public void draw(Tile tile){
|
public void draw(Tile tile){
|
||||||
ConduitEntity entity = tile.entity();
|
ConduitEntity entity = tile.entity();
|
||||||
LiquidModule mod = tile.entity.liquids;
|
LiquidModule mod = tile.entity.liquids;
|
||||||
|
int rotation = tile.getRotation() * 90;
|
||||||
|
|
||||||
int rotation = rotate ? tile.getRotation() * 90 : 0;
|
Draw.colorl(0.34f);
|
||||||
|
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
|
||||||
Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
|
|
||||||
|
|
||||||
Draw.color(mod.current().color);
|
Draw.color(mod.current().color);
|
||||||
Draw.alpha(entity.smoothLiquid);
|
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.color();
|
||||||
|
|
||||||
Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
|
Draw.rect(topRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,7 +100,10 @@ public class Conduit extends LiquidBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureRegion[] getIcon(){
|
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
|
@Override
|
||||||
@ -78,6 +119,7 @@ public class Conduit extends LiquidBlock {
|
|||||||
|
|
||||||
public static class ConduitEntity extends TileEntity {
|
public static class ConduitEntity extends TileEntity {
|
||||||
public float smoothLiquid;
|
public float smoothLiquid;
|
||||||
|
public byte blendbits;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream stream) throws IOException {
|
public void write(DataOutputStream stream) throws IOException {
|
||||||
|