Incomplete production meta system
This commit is contained in:
@@ -284,7 +284,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
Block previous = tile.block();
|
||||
tile.block().update(tile);
|
||||
if(tile.block() == previous && cons != null){
|
||||
cons.update(this);
|
||||
cons.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@ public class Item extends UnlockableContent implements Comparable<Item>{
|
||||
public enum Icon{
|
||||
small(8*2),
|
||||
medium(8*3),
|
||||
large(8*4);
|
||||
large(8*4),
|
||||
xlarge(8*5);
|
||||
|
||||
public final int size;
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ public class BlockInventoryFragment extends Fragment{
|
||||
int row = 0;
|
||||
|
||||
table.margin(6f);
|
||||
table.defaults().size(16 * 2.5f).space(6f);
|
||||
table.defaults().size(8 * 5).space(6f);
|
||||
|
||||
if(tile.block().hasItems){
|
||||
|
||||
@@ -136,7 +136,7 @@ public class BlockInventoryFragment extends Fragment{
|
||||
HandCursorListener l = new HandCursorListener();
|
||||
l.setEnabled(canPick);
|
||||
|
||||
ItemImage image = new ItemImage(item.icon(Icon.large), () -> {
|
||||
ItemImage image = new ItemImage(item.icon(Icon.xlarge), () -> {
|
||||
if(tile == null || tile.entity == null){
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class Tile implements Position, TargetTrait{
|
||||
|
||||
if(block.hasEntity()){
|
||||
entity = block.newEntity().init(this, block.update);
|
||||
entity.cons = new ConsumeModule();
|
||||
entity.cons = new ConsumeModule(entity);
|
||||
if(block.hasItems) entity.items = new ItemModule();
|
||||
if(block.hasLiquids) entity.liquids = new LiquidModule();
|
||||
if(block.hasPower){
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Conveyor extends Block{
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add(BlockStat.itemSpeed, speed * 60, StatUnit.pixelsSecond);
|
||||
stats.add(BlockStat.itemsMoved, speed * 60, StatUnit.itemsSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@@ -22,6 +21,7 @@ public class GenericCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item output;
|
||||
|
||||
protected float craftTime = 80;
|
||||
protected Effect craftEffect = Fx.purify;
|
||||
protected Effect updateEffect = Fx.none;
|
||||
@@ -77,13 +77,9 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
|
||||
if(entity.progress >= 1f){
|
||||
|
||||
//TODO, bad design, crafter has to know that this consumes items
|
||||
//there should be a separate trigger in #cons to consume discrete amounts of items
|
||||
if(consumes.has(ConsumeItem.class)) tile.entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
entity.cons.trigger();
|
||||
|
||||
useContent(tile, output);
|
||||
|
||||
offloadNear(tile, output);
|
||||
Effects.effect(craftEffect, tile.drawx(), tile.drawy());
|
||||
entity.progress = 0f;
|
||||
@@ -94,6 +90,11 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduce(Tile tile){
|
||||
return super.canProduce(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new GenericCrafterEntity();
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.sandbox;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.scene.style.TextureRegionDrawable;
|
||||
import io.anuke.arc.scene.ui.ButtonGroup;
|
||||
@@ -13,9 +12,7 @@ import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.entities.type.Player;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
@@ -38,11 +35,10 @@ public class LiquidSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayBars(Tile tile, Table bars){
|
||||
TileEntity entity = tile.entity;
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add(new Bar("blocks.health", Pal.health, entity::healthf).blink(Color.WHITE));
|
||||
bars.row();
|
||||
bars.remove("liquid");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,6 +52,11 @@ public abstract class Consume{
|
||||
}).size(10 * scale).get().addListener(new Tooltip<>(t));
|
||||
}
|
||||
|
||||
/**Called when a consumption is triggered manually.*/
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
public abstract void buildTooltip(Table table);
|
||||
|
||||
public abstract String getIcon();
|
||||
|
||||
@@ -31,6 +31,11 @@ public class ConsumeItem extends Consume{
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
entity.items.remove(item, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTooltip(Table table){
|
||||
table.add(new ItemImage(new ItemStack(item, amount))).size(8 * 4);
|
||||
|
||||
@@ -46,6 +46,17 @@ public class ConsumeItemFilter extends Consume{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
entity.items.remove(item, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
|
||||
@@ -37,6 +37,13 @@ public class ConsumeItems extends Consume{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
for(ItemStack stack : items){
|
||||
entity.items.remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity.items != null && entity.items.has(items);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ConsumePower extends Consume{
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
if(isBuffered){
|
||||
stats.add(BlockStat.powerCapacity, powerCapacity, StatUnit.powerSecond);
|
||||
stats.add(BlockStat.powerCapacity, powerCapacity, StatUnit.none);
|
||||
}else{
|
||||
stats.add(BlockStat.powerUse, powerPerTick * 60f, StatUnit.powerSecond);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class BlockBars{
|
||||
}
|
||||
|
||||
public void remove(String name){
|
||||
if(!bars.containsKey(name)) throw new RuntimeException("No bar with name '" + name + "' found; current bars: " + bars.keys().toArray());
|
||||
bars.remove(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public enum BlockStat{
|
||||
itemCapacity(StatCategory.items),
|
||||
inputItemCapacity(StatCategory.items),
|
||||
outputItemCapacity(StatCategory.items),
|
||||
itemSpeed(StatCategory.items),
|
||||
itemsMoved(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
liquidOutput(StatCategory.liquids),
|
||||
|
||||
@@ -12,7 +12,6 @@ public enum StatUnit{
|
||||
powerSecond,
|
||||
liquidSecond,
|
||||
itemsSecond,
|
||||
pixelsSecond,
|
||||
liquidUnits,
|
||||
powerUnits,
|
||||
degrees,
|
||||
|
||||
@@ -9,10 +9,13 @@ import java.io.IOException;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid;
|
||||
private TileEntity entity;
|
||||
private final TileEntity entity;
|
||||
|
||||
public void update(TileEntity entity){
|
||||
public ConsumeModule(TileEntity entity){
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
|
||||
@@ -27,8 +30,14 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
cons.trigger(entity.tile.block(), entity);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean valid(){
|
||||
return valid && (entity == null || entity.tile.block().canProduce(entity.tile));
|
||||
return valid && entity.tile.block().canProduce(entity.tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
4
core/src/io/anuke/mindustry/world/producers/Produce.java
Normal file
4
core/src/io/anuke/mindustry/world/producers/Produce.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package io.anuke.mindustry.world.producers;
|
||||
|
||||
public class Produce{
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package io.anuke.mindustry.world.producers;
|
||||
|
||||
public class ProduceItem{
|
||||
}
|
||||
Reference in New Issue
Block a user