mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-28 13:47:32 +07:00
Birth base conveyor class
This commit is contained in:
@ -1,9 +1,94 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
abstract public class BaseConveyor extends Block implements Autotiler{
|
||||
TextureRegion[][] regions = new TextureRegion[7][4];
|
||||
|
||||
public float speed = 0f;
|
||||
|
||||
abstract public class BaseConveyor extends Block{
|
||||
public BaseConveyor(String name){
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
layer = Layer.overlay;
|
||||
group = BlockGroup.transportation;
|
||||
hasItems = true;
|
||||
itemCapacity = 4;
|
||||
conveyorPlacement = true;
|
||||
idleSound = Sounds.conveyor;
|
||||
idleSoundVolume = 0.004f;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
BaseConveyorEntity entity = tile.ent();
|
||||
byte rotation = tile.rotation();
|
||||
|
||||
int frame = entity.clogHeat <= 0.5f ? (int)(((Time.time() * speed * 8f * entity.timeScale)) % 4) : 0;
|
||||
Draw.rect(regions[Mathf.clamp(entity.blendbits, 0, regions.length - 1)][Mathf.clamp(frame, 0, regions[0].length - 1)], tile.drawx(), tile.drawy(),
|
||||
tilesize * entity.blendsclx, tilesize * entity.blendscly, rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
int[] bits = getTiling(req, list);
|
||||
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[bits[0]][0];
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl * req.animScale, region.getHeight() * bits[2] * Draw.scl * req.animScale, req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile){
|
||||
super.onProximityUpdate(tile);
|
||||
|
||||
BaseConveyorEntity entity = tile.ent();
|
||||
int[] bits = buildBlending(tile, tile.rotation(), null, true);
|
||||
entity.blendbits = bits[0];
|
||||
entity.blendsclx = bits[1];
|
||||
entity.blendscly = bits[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.outputsItems() && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return new TextureRegion[]{Core.atlas.find(name + "-0-0")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIdleSound(Tile tile){
|
||||
BaseConveyorEntity entity = tile.ent();
|
||||
return entity.clogHeat <= 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccessible(){
|
||||
return true;
|
||||
}
|
||||
|
||||
static abstract class BaseConveyorEntity extends TileEntity{
|
||||
int blendbits;
|
||||
int blendsclx, blendscly;
|
||||
|
||||
float clogHeat = 0f;
|
||||
}
|
||||
}
|
||||
|
@ -14,18 +14,18 @@ import mindustry.entities.*;
|
||||
import mindustry.graphics.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.entities.type.*;
|
||||
|
||||
|
||||
import static mindustry.Vars.itemSize;
|
||||
|
||||
public class CraterConveyor extends ArmoredItemConveyor{
|
||||
public class CraterConveyor extends BaseConveyor{
|
||||
private TextureRegion start, end, crater;
|
||||
|
||||
|
||||
public CraterConveyor(String name){
|
||||
super(name);
|
||||
compressable = true;
|
||||
entityType = PlastaniumConveyorEntity::new;
|
||||
entityType = CraterConveyorEntity::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,7 +47,6 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
super.setStats();
|
||||
|
||||
stats.remove(BlockStat.itemCapacity);
|
||||
stats.remove(BlockStat.itemsMoved);
|
||||
|
||||
stats.add(BlockStat.maxUnits, 1, StatUnit.none);
|
||||
}
|
||||
@ -64,15 +63,15 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
PlastaniumConveyorEntity entity = tile.ent();
|
||||
CraterConveyorEntity entity = tile.ent();
|
||||
|
||||
if(entity.crater != null) entity.crater.draw(tile);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){ // tick away the cooldown
|
||||
PlastaniumConveyorEntity entity = tile.ent();
|
||||
public void update(Tile tile){
|
||||
CraterConveyorEntity entity = tile.ent();
|
||||
|
||||
if(entity.crater == null){
|
||||
if(entity.items.total() > 0){
|
||||
@ -96,7 +95,7 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
|
||||
if(entity.crater.dst(tile) < 0.1f){
|
||||
if(destination.block() instanceof CraterConveyor){
|
||||
PlastaniumConveyorEntity e = destination.ent();
|
||||
CraterConveyorEntity e = destination.ent();
|
||||
|
||||
if(e.crater == null){
|
||||
e.crater = entity.crater;
|
||||
@ -117,7 +116,7 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
}
|
||||
}
|
||||
|
||||
public class PlastaniumConveyorEntity extends ItemConveyorEntity{
|
||||
public class CraterConveyorEntity extends BaseConveyorEntity{
|
||||
Crater crater;
|
||||
}
|
||||
|
||||
@ -162,8 +161,8 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){ // summon craters into existence to be loaded
|
||||
PlastaniumConveyorEntity entity = tile.ent();
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
CraterConveyorEntity entity = tile.ent();
|
||||
|
||||
if(!Track.start.check.get(tile) && !source.block().compressable) return false;
|
||||
if(entity.items.total() > 0 && !entity.items.has(item)) return false;
|
||||
@ -172,35 +171,6 @@ public class CraterConveyor extends ArmoredItemConveyor{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.entity.items.add(item, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){
|
||||
return Math.min(getMaximumAccepted(tile, item) - tile.entity.items.get(item), amount);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||
tile.entity.noSleep();
|
||||
tile.entity.items.add(item, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeStack(Tile tile, Item item, int amount){
|
||||
if(tile.entity == null || tile.entity.items == null) return 0;
|
||||
amount = Math.min(amount, tile.entity.items.get(item));
|
||||
tile.entity.noSleep();
|
||||
tile.entity.items.remove(item, amount);
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){ // only connect to compressable blocks
|
||||
return super.blendsArmored(tile, rotation, otherx, othery, otherrot, otherblock) && otherblock.compressable;
|
||||
|
@ -1,22 +1,20 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ui.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -30,24 +28,10 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
private static ItemPos pos2 = new ItemPos();
|
||||
private final Vec2 tr1 = new Vec2();
|
||||
private final Vec2 tr2 = new Vec2();
|
||||
protected TextureRegion[][] regions = new TextureRegion[7][4];
|
||||
|
||||
public float speed = 0f;
|
||||
|
||||
protected ItemConveyor(String name){
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
layer = Layer.overlay;
|
||||
group = BlockGroup.transportation;
|
||||
hasItems = true;
|
||||
itemCapacity = 4;
|
||||
conveyorPlacement = true;
|
||||
entityType = ItemConveyorEntity::new;
|
||||
|
||||
idleSound = Sounds.conveyor;
|
||||
idleSoundVolume = 0.004f;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
private static int compareItems(long a, long b){
|
||||
@ -73,53 +57,6 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
ItemConveyorEntity entity = tile.ent();
|
||||
byte rotation = tile.rotation();
|
||||
|
||||
int frame = entity.clogHeat <= 0.5f ? (int)(((Time.time() * speed * 8f * entity.timeScale)) % 4) : 0;
|
||||
Draw.rect(regions[Mathf.clamp(entity.blendbits, 0, regions.length - 1)][Mathf.clamp(frame, 0, regions[0].length - 1)], tile.drawx(), tile.drawy(),
|
||||
tilesize * entity.blendsclx, tilesize * entity.blendscly, rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIdleSound(Tile tile){
|
||||
ItemConveyorEntity entity = tile.ent();
|
||||
return entity.clogHeat <= 0.5f ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(Tile tile){
|
||||
super.onProximityUpdate(tile);
|
||||
|
||||
ItemConveyorEntity entity = tile.ent();
|
||||
int[] bits = buildBlending(tile, tile.rotation(), null, true);
|
||||
entity.blendbits = bits[0];
|
||||
entity.blendsclx = bits[1];
|
||||
entity.blendscly = bits[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestRegion(BuildRequest req, Eachable<BuildRequest> list){
|
||||
int[] bits = getTiling(req, list);
|
||||
|
||||
if(bits == null) return;
|
||||
|
||||
TextureRegion region = regions[bits[0]][0];
|
||||
Draw.rect(region, req.drawx(), req.drawy(), region.getWidth() * bits[1] * Draw.scl * req.animScale, region.getHeight() * bits[2] * Draw.scl * req.animScale, req.rotation * 90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blends(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
return otherblock.outputsItems() && lookingAt(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return new TextureRegion[]{Core.atlas.find(name + "-0-0")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
ItemConveyorEntity entity = tile.ent();
|
||||
@ -183,7 +120,7 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
Tile next = tile.getNearby(tile.rotation());
|
||||
if(next != null) next = next.link();
|
||||
|
||||
float nextMax = next != null && next.block() instanceof ItemConveyor && !next.block().compressable && next.block().acceptItem(null, next, tile) ? 1f - Math.max(itemSpace - next.<ItemConveyorEntity>ent().minitem, 0) : 1f;
|
||||
float nextMax = next != null && next.block() instanceof ItemConveyor && next.block().acceptItem(null, next, tile) ? 1f - Math.max(itemSpace - next.<ItemConveyorEntity>ent().minitem, 0) : 1f;
|
||||
int minremove = Integer.MAX_VALUE;
|
||||
|
||||
for(int i = entity.convey.size - 1; i >= 0; i--){
|
||||
@ -210,7 +147,7 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
pos.y = Mathf.clamp(pos.y, 0, nextMax);
|
||||
|
||||
if(pos.y >= 0.9999f && offloadDir(tile, pos.item)){
|
||||
if(next != null && next.block() instanceof ItemConveyor && !next.block().compressable){
|
||||
if(next != null && next.block() instanceof ItemConveyor){
|
||||
ItemConveyorEntity othere = next.ent();
|
||||
|
||||
ItemPos ni = pos2.set(othere.convey.get(othere.lastInserted), ItemPos.updateShorts);
|
||||
@ -246,11 +183,6 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
if(minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccessible(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getReplacement(BuildRequest req, Array<BuildRequest> requests){
|
||||
Boolf<Point2> cont = p -> requests.contains(o -> o.x == req.x + p.x && o.y == req.y + p.y && o.rotation == req.rotation && (req.block instanceof ItemConveyor || req.block instanceof Junction));
|
||||
@ -343,17 +275,12 @@ public class ItemConveyor extends BaseConveyor implements Autotiler{
|
||||
entity.lastInserted = (byte)(entity.convey.size - 1);
|
||||
}
|
||||
|
||||
public static class ItemConveyorEntity extends TileEntity{
|
||||
public static class ItemConveyorEntity extends BaseConveyorEntity{
|
||||
|
||||
LongArray convey = new LongArray();
|
||||
byte lastInserted;
|
||||
float minitem = 1;
|
||||
|
||||
int blendbits;
|
||||
int blendsclx, blendscly;
|
||||
|
||||
float clogHeat = 0f;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
|
Reference in New Issue
Block a user