Refractor away overhead
This commit is contained in:
@@ -894,7 +894,7 @@ public class Blocks implements ContentList{
|
|||||||
plastaniumConveyor = new CraterConveyor("plastanium-conveyor"){{
|
plastaniumConveyor = new CraterConveyor("plastanium-conveyor"){{
|
||||||
requirements(Category.distribution, ItemStack.with(Items.plastanium, 1, Items.silicon, 1, Items.graphite, 1));
|
requirements(Category.distribution, ItemStack.with(Items.plastanium, 1, Items.silicon, 1, Items.graphite, 1));
|
||||||
itemCapacity = 8;
|
itemCapacity = 8;
|
||||||
speed = 0.075f;
|
speed = 0.04f;
|
||||||
health = 75;
|
health = 75;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|||||||
@@ -63,23 +63,31 @@ public class CraterConveyor extends BaseConveyor{
|
|||||||
public void drawLayer(Tile tile){
|
public void drawLayer(Tile tile){
|
||||||
CraterConveyorEntity entity = tile.ent();
|
CraterConveyorEntity entity = tile.ent();
|
||||||
|
|
||||||
if(entity.crater == null) return;
|
if(!entity.crater) return;
|
||||||
|
|
||||||
|
Tile from = world.tile(entity.link);
|
||||||
|
Tmp.v1.set(from.getX(), from.getY());
|
||||||
|
Tmp.v2.set(tile.drawx(), tile.drawy());
|
||||||
|
Tmp.v1.interpolate(Tmp.v2, 1f - entity.reload, Interpolation.linear);
|
||||||
|
|
||||||
|
// rotating smoothly
|
||||||
|
float a = from.rotation() * 90;
|
||||||
|
float b = tile.rotation() * 90;
|
||||||
|
if(from.rotation() == 3 && tile.rotation() == 0) a = -1 * 90;
|
||||||
|
if(from.rotation() == 0 && tile.rotation() == 3) a = 4 * 90;
|
||||||
|
float rotation = Mathf.lerp(a, b, Interpolation.linear.apply(1f - entity.reload));
|
||||||
|
|
||||||
// draw crater
|
// draw crater
|
||||||
Draw.rect(crater, entity.crater.x, entity.crater.y, entity.crater.rotation);
|
Draw.rect(crater, Tmp.v1.x, Tmp.v1.y, rotation - 90);
|
||||||
|
|
||||||
// find dominant(/only) item
|
if(entity.dominant() == null) return;
|
||||||
if(entity.crater.item == null){
|
|
||||||
entity.crater.item = tile.entity.items.take();
|
|
||||||
tile.entity.items.add(entity.crater.item, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw resource
|
// draw resource
|
||||||
float size = itemSize / 1.5f;
|
float size = itemSize / 1.5f;
|
||||||
Draw.rect(entity.crater.item.icon(Cicon.medium), entity.crater.x, entity.crater.y, size, size, 0);
|
Draw.rect(entity.dominant().icon(Cicon.medium), Tmp.v1.x, Tmp.v1.y, size, size, 0);
|
||||||
|
|
||||||
// draw amount
|
// draw amount
|
||||||
Fonts.outline.draw(tile.entity.items.total() + "", entity.crater.x, entity.crater.y - 1,
|
Fonts.outline.draw(tile.entity.items.total() + "", Tmp.v1.x, Tmp.v1.y - 1,
|
||||||
Pal.accent, 0.25f * 0.5f / Scl.scl(1f), false, Align.center);
|
Pal.accent, 0.25f * 0.5f / Scl.scl(1f), false, Align.center);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,28 +100,25 @@ public class CraterConveyor extends BaseConveyor{
|
|||||||
if(entity.lastFrameUpdated == Core.graphics.getFrameId()) return;
|
if(entity.lastFrameUpdated == Core.graphics.getFrameId()) return;
|
||||||
entity.lastFrameUpdated = Core.graphics.getFrameId();
|
entity.lastFrameUpdated = Core.graphics.getFrameId();
|
||||||
|
|
||||||
if(entity.cooldown > 0) entity.cooldown--;
|
entity.reload = Mathf.clamp(entity.reload - speed, 0f, 1f);
|
||||||
|
|
||||||
// ensure a crater exists below this block
|
// ensure a crater exists below this block
|
||||||
if(entity.crater == null){
|
if(!entity.crater){
|
||||||
// poof in crater
|
// poof in crater
|
||||||
if(entity.items.total() <= 0 || entity.cooldown > 0) return;
|
if(entity.items.total() <= 0 || entity.reload > 0) return;
|
||||||
entity.crater = new Crater(tile);
|
|
||||||
Effects.effect(Fx.plasticburn, tile.drawx(), tile.drawy());
|
Effects.effect(Fx.plasticburn, tile.drawx(), tile.drawy());
|
||||||
|
entity.crater = true;
|
||||||
|
entity.link = tile.back().pos();
|
||||||
}else{
|
}else{
|
||||||
// poof out crater
|
// poof out crater
|
||||||
if(entity.items.total() == 0){
|
if(entity.items.total() == 0){
|
||||||
Effects.effect(Fx.plasticburn, tile.drawx(), tile.drawy());
|
Effects.effect(Fx.plasticburn, tile.drawx(), tile.drawy());
|
||||||
entity.crater = null;
|
entity.crater = false;
|
||||||
|
entity.link = Pos.invalid;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle crater movement
|
|
||||||
entity.crater.x = Mathf.lerpDelta(entity.crater.x, tile.drawx(), speed);
|
|
||||||
entity.crater.y = Mathf.lerpDelta(entity.crater.y, tile.drawy(), speed);
|
|
||||||
entity.crater.rotation = Mathf.slerpDelta(entity.crater.rotation, entity.crater.face, speed * 2);
|
|
||||||
|
|
||||||
if(shouldLaunch(tile)){
|
if(shouldLaunch(tile)){
|
||||||
Tile destination = tile.front();
|
Tile destination = tile.front();
|
||||||
|
|
||||||
@@ -121,30 +126,32 @@ public class CraterConveyor extends BaseConveyor{
|
|||||||
destination.block().update(destination);
|
destination.block().update(destination);
|
||||||
|
|
||||||
// when near the center of the target tile...
|
// when near the center of the target tile...
|
||||||
if(entity.crater.dst(tile) < 1.25f){
|
if(entity.reload < 0.25f){
|
||||||
entity.crater.face = tile.rotation() * 90 - 90; // ...set the new direction it should face
|
|
||||||
if(!(destination.block() instanceof CraterConveyor)){ // ...and if its not a crater conveyor, start unloading (everything)
|
if(!(destination.block() instanceof CraterConveyor)){ // ...and if its not a crater conveyor, start unloading (everything)
|
||||||
while(entity.items.total() > 0 && entity.crater.item != null && offloadDir(tile, entity.crater.item)) entity.items.remove(entity.crater.item, 1);
|
while(entity.items.total() > 0 && entity.dominant() != null && offloadDir(tile, entity.dominant())) entity.items.remove(entity.dominant(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when basically exactly on the center:
|
// when basically exactly on the center:
|
||||||
if(entity.crater.dst(tile) < 0.1f){
|
if(entity.reload == 0){
|
||||||
if(destination.block() instanceof CraterConveyor){
|
if(destination.block() instanceof CraterConveyor){
|
||||||
CraterConveyorEntity e = destination.ent();
|
CraterConveyorEntity e = destination.ent();
|
||||||
|
|
||||||
// check if next crater conveyor is not occupied
|
// check if next crater conveyor is not occupied
|
||||||
if(e.crater == null){
|
if(e.items.total() == 0){
|
||||||
// transfer ownership of crater
|
// transfer ownership of crater
|
||||||
e.crater = entity.crater;
|
e.crater = true;
|
||||||
entity.crater = null;
|
entity.crater = false;
|
||||||
|
|
||||||
// prevent this tile from spawning a new crater to avoid collisions
|
// prevent this tile from spawning a new crater to avoid collisions
|
||||||
entity.cooldown = 10;
|
entity.reload = 1;
|
||||||
|
|
||||||
// transfer inventory of conveyor
|
// transfer inventory of conveyor
|
||||||
e.items.addAll(entity.items);
|
e.items.addAll(entity.items);
|
||||||
entity.items.clear();
|
entity.items.clear();
|
||||||
|
|
||||||
|
e.reload = 1;
|
||||||
|
e.link = tile.pos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,66 +160,34 @@ public class CraterConveyor extends BaseConveyor{
|
|||||||
|
|
||||||
class CraterConveyorEntity extends BaseConveyorEntity{
|
class CraterConveyorEntity extends BaseConveyorEntity{
|
||||||
float lastFrameUpdated = -1;
|
float lastFrameUpdated = -1;
|
||||||
Crater crater;
|
|
||||||
|
|
||||||
int cooldown;
|
int link = Pos.invalid;
|
||||||
|
float reload;
|
||||||
|
boolean crater;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
super.write(stream);
|
super.write(stream);
|
||||||
|
|
||||||
stream.writeBoolean(crater != null);
|
stream.writeInt(link);
|
||||||
if(crater != null) crater.write(stream);
|
stream.writeFloat(reload);
|
||||||
|
stream.writeBoolean(crater);
|
||||||
stream.writeInt(cooldown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(DataInput stream, byte revision) throws IOException{
|
||||||
super.read(stream, revision);
|
super.read(stream, revision);
|
||||||
|
|
||||||
if(stream.readBoolean()) crater = new Crater(stream);
|
link = stream.readInt();
|
||||||
|
reload = stream.readFloat();
|
||||||
cooldown = stream.readInt();
|
crater = stream.readBoolean();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class Crater implements Position{
|
|
||||||
float rotation;
|
|
||||||
float face;
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
Item item;
|
|
||||||
|
|
||||||
Crater(Tile tile){
|
|
||||||
x = tile.drawx();
|
|
||||||
y = tile.drawy();
|
|
||||||
rotation = tile.rotation() * 90 - 90;
|
|
||||||
face = rotation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Crater(DataInput stream) throws IOException{
|
public Item dominant(){
|
||||||
rotation = stream.readFloat();
|
if(tile.entity.items.total() == 0) return null;
|
||||||
face = stream.readFloat();
|
Item item = tile.entity.items.take();
|
||||||
x = stream.readFloat();
|
tile.entity.items.add(item, 1);
|
||||||
y = stream.readFloat();
|
return item;
|
||||||
}
|
|
||||||
|
|
||||||
public void write(DataOutput stream) throws IOException{
|
|
||||||
stream.writeFloat(rotation);
|
|
||||||
stream.writeFloat(face);
|
|
||||||
stream.writeFloat(x);
|
|
||||||
stream.writeFloat(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getX(){
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getY(){
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +214,7 @@ public class CraterConveyor extends BaseConveyor{
|
|||||||
if(!isStart(tile)) return true;
|
if(!isStart(tile)) return true;
|
||||||
|
|
||||||
// its considered full
|
// its considered full
|
||||||
if(entity.items.total() >= getMaximumAccepted(tile, entity.crater.item)) return true;
|
if(entity.items.total() >= getMaximumAccepted(tile, entity.dominant())) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user