mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-10 07:47:25 +07:00
Various bugfixes / Fixed persistent inventory, block crashes
This commit is contained in:
@ -461,8 +461,8 @@ block.splitter.name=Splitter
|
||||
block.splitter.description=Outputs items into two opposite directions immediately after they are recieved.
|
||||
block.router.name=Router
|
||||
block.router.description=Splits items into all 4 directions. Can store items as a buffer.
|
||||
block.multiplexer.name=Multiplexer
|
||||
block.multiplexer.description=A router that can split items into 8 directions.
|
||||
block.distributor.name=Distributor
|
||||
block.distributor.description=A splitter that can split items into 8 directions.
|
||||
block.sorter.name=Sorter
|
||||
block.sorter.description=Sorts items. If an item matches the selection, it is allowed to pass. Otherwise, the item is outputted to the left and right.
|
||||
block.overflow-gate.name=Overflow Gate
|
||||
|
@ -117,6 +117,7 @@ public class CraftingBlocks extends BlockList implements ContentList {
|
||||
liquidPerItem = 50f;
|
||||
itemCapacity = 50;
|
||||
size = 2;
|
||||
hasPower = true;
|
||||
|
||||
consumes.power(0.1f);
|
||||
consumes.item(Items.titanium);
|
||||
|
@ -170,6 +170,10 @@ public class World extends Module{
|
||||
for(int x = 0; x < tiles.length; x ++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
tiles[x][y].updateOcclusion();
|
||||
|
||||
if(tiles[x][y].entity != null){
|
||||
tiles[x][y].entity.updateProximity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,14 +39,16 @@ public class MapEditor{
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void beginEdit(MapTileData map, ObjectMap<String, String> tags){
|
||||
public void beginEdit(MapTileData map, ObjectMap<String, String> tags, boolean clear){
|
||||
this.map = map;
|
||||
this.brushSize = 1;
|
||||
this.tags = tags;
|
||||
|
||||
for (int x = 0; x < map.width(); x++) {
|
||||
for (int y = 0; y < map.height(); y++) {
|
||||
map.write(x, y, DataPosition.floor, (byte)Blocks.stone.id);
|
||||
if(clear) {
|
||||
for (int x = 0; x < map.width(); x++) {
|
||||
for (int y = 0; y < map.height(); y++) {
|
||||
map.write(x, y, DataPosition.floor, (byte) Blocks.stone.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
MapMeta meta = MapIO.readMapMeta(stream);
|
||||
MapTileData data = MapIO.readTileData(stream, meta, false);
|
||||
|
||||
editor.beginEdit(data, meta.tags);
|
||||
editor.beginEdit(data, meta.tags, false);
|
||||
view.clearStack();
|
||||
}catch (Exception e){
|
||||
ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
|
||||
@ -125,7 +125,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
try{
|
||||
MapTileData data = MapIO.readPixmap(new Pixmap(file));
|
||||
|
||||
editor.beginEdit(data, editor.getTags());
|
||||
editor.beginEdit(data, editor.getTags(), false);
|
||||
view.clearStack();
|
||||
}catch (Exception e){
|
||||
ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
|
||||
@ -213,7 +213,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
MapMeta meta = MapIO.readMapMeta(stream);
|
||||
MapTileData data = MapIO.readTileData(stream, meta, false);
|
||||
|
||||
editor.beginEdit(data, meta.tags);
|
||||
editor.beginEdit(data, meta.tags, false);
|
||||
view.clearStack();
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.editor.errormapload", Strings.parseException(e, false)));
|
||||
@ -254,7 +254,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
view.clearStack();
|
||||
Core.scene.setScrollFocus(view);
|
||||
if(!shownWithMap){
|
||||
editor.beginEdit(new MapTileData(256, 256), new ObjectMap<>());
|
||||
editor.beginEdit(new MapTileData(256, 256), new ObjectMap<>(), true);
|
||||
}
|
||||
shownWithMap = false;
|
||||
|
||||
@ -348,7 +348,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
shownWithMap = true;
|
||||
DataInputStream stream = new DataInputStream(is);
|
||||
MapMeta meta = MapIO.readMapMeta(stream);
|
||||
editor.beginEdit(MapIO.readTileData(stream, meta, false), meta.tags);
|
||||
editor.beginEdit(MapIO.readTileData(stream, meta, false), meta.tags, false);
|
||||
is.close();
|
||||
show();
|
||||
}catch (Exception e){
|
||||
|
@ -69,11 +69,12 @@ public class BlockInventoryFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void rebuild(boolean actions){
|
||||
|
||||
Player player = input.player;
|
||||
|
||||
IntSet container = new IntSet();
|
||||
|
||||
table.clear();
|
||||
table.clearChildren();
|
||||
table.background("inventory");
|
||||
table.setTouchable(Touchable.enabled);
|
||||
table.update(() -> {
|
||||
@ -121,7 +122,12 @@ public class BlockInventoryFragment extends Fragment {
|
||||
HandCursorListener l = new HandCursorListener();
|
||||
l.setEnabled(canPick);
|
||||
|
||||
ItemImage image = new ItemImage(item.region, () -> round(tile.entity.items.get(item)));
|
||||
ItemImage image = new ItemImage(item.region, () -> {
|
||||
if(tile == null || tile.entity == null){
|
||||
return "";
|
||||
}
|
||||
return round(tile.entity.items.get(item));
|
||||
});
|
||||
image.addListener(l);
|
||||
|
||||
image.addListener(new InputListener(){
|
||||
|
@ -84,7 +84,6 @@ public class DebugFragment extends Fragment {
|
||||
FloatingDialog dialog = new FloatingDialog("debug spawn");
|
||||
for(UnitType type : UnitType.all()){
|
||||
dialog.content().addImageButton("white", 40, () -> {
|
||||
dialog.hide();
|
||||
BaseUnit unit = type.create(player.getTeam());
|
||||
unit.inventory.addAmmo(type.weapon.getAmmoType(type.weapon.getAcceptedItems().iterator().next()));
|
||||
unit.setWave();
|
||||
|
@ -7,6 +7,7 @@ import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.Consumers;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@ -68,7 +69,7 @@ public abstract class BaseBlock {
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return tile.entity != null && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
||||
return tile.entity != null && consumes.has(ConsumeItem.class) && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
@ -210,7 +211,7 @@ public abstract class BaseBlock {
|
||||
for (int ii = 0; ii < Item.all().size; ii++) {
|
||||
Item item = Item.getByID(ii);
|
||||
|
||||
if (other.block().acceptItem(item, other, in) && canDump(tile, other, item)) {
|
||||
if (entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)) {
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.items.remove(item, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
|
@ -392,7 +392,7 @@ public class Tile implements PosTrait, TargetTrait {
|
||||
|
||||
if (block.hasEntity()) {
|
||||
entity = block.getEntity().init(this, block.update);
|
||||
if(block.consumes.hasAny()) entity.cons = new ConsumeModule();
|
||||
entity.cons = new ConsumeModule();
|
||||
if(block.hasItems) entity.items = new InventoryModule();
|
||||
if(block.hasLiquids) entity.liquids = new LiquidModule();
|
||||
if(block.hasPower) entity.power = new PowerModule();
|
||||
|
@ -133,10 +133,13 @@ public class BuildBlock extends Block {
|
||||
public void drawShadow(Tile tile) {
|
||||
BuildEntity entity = tile.entity();
|
||||
|
||||
if(entity.recipe != null){
|
||||
entity.recipe.result.drawShadow(tile);
|
||||
}else if(entity.previous != null){
|
||||
entity.previous.drawShadow(tile);
|
||||
Recipe recipe = entity.recipe;
|
||||
Block previous = entity.previous;
|
||||
|
||||
if(recipe != null){
|
||||
recipe.result.drawShadow(tile);
|
||||
}else if(previous != null){
|
||||
previous.drawShadow(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,6 +184,7 @@ public class BuildBlock extends Block {
|
||||
/**The block that used to be here.
|
||||
* If a non-recipe block is being deconstructed, this is the block that is being deconstructed.*/
|
||||
public Block previous;
|
||||
public int builderID = -1;
|
||||
|
||||
private float[] accumulator;
|
||||
|
||||
@ -195,8 +199,12 @@ public class BuildBlock extends Block {
|
||||
|
||||
progress = Mathf.clamp(progress + maxProgress);
|
||||
|
||||
if(builder instanceof Player){
|
||||
builderID = builder.getID();
|
||||
}
|
||||
|
||||
if(progress >= 1f){
|
||||
CallBlocks.onConstructFinish(tile, recipe.result, builder.getID(), tile.getRotation(), tile.getTeam());
|
||||
CallBlocks.onConstructFinish(tile, recipe.result, builderID, tile.getRotation(), tile.getTeam());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,8 @@ public class ItemBridge extends Block {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
endRegion = Draw.region(name + "-end");
|
||||
bridgeRegion = Draw.region(name + "-bridge");
|
||||
arrowRegion = Draw.region(name + "-arrow");
|
||||
@ -221,6 +223,29 @@ public class ItemBridge extends Block {
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source) {
|
||||
ItemBridgeEntity entity = tile.entity();
|
||||
Tile other = world.tile(entity.link);
|
||||
|
||||
if(linkValid(tile, other)){
|
||||
int rel = tile.absoluteRelativeTo(other.x, other.y);
|
||||
int rel2 = tile.relativeTo(source.x, source.y);
|
||||
|
||||
if(rel == rel2) return false;
|
||||
}else{
|
||||
int i = tile.relativeTo(source.x, source.y);
|
||||
|
||||
IntSetIterator it = entity.incoming.iterator();
|
||||
|
||||
while(it.hasNext){
|
||||
int v = it.next();
|
||||
int x = v % world.width();
|
||||
int y = v / world.width();
|
||||
if(tile.absoluteRelativeTo(x, y) == i){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
@ -70,13 +69,7 @@ public class Drill extends Block{
|
||||
liquidCapacity = 5f;
|
||||
hasItems = true;
|
||||
|
||||
consumes.add(new ConsumeLiquid(Liquids.water, 0.05f){
|
||||
@Override
|
||||
public void display(BlockStats stats) {
|
||||
stats.add(BlockStat.coolantUse, use * 60f, StatUnit.liquidSecond);
|
||||
stats.add(BlockStat.coolant, liquid);
|
||||
}
|
||||
}).optional(true);
|
||||
consumes.add(new ConsumeLiquid(Liquids.water, 0.05f)).optional(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,11 +2,15 @@ package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class LiquidMixer extends LiquidBlock{
|
||||
protected Liquid outputLiquid;
|
||||
@ -26,6 +30,15 @@ public class LiquidMixer extends LiquidBlock{
|
||||
stats.add(BlockStat.liquidOutput, outputLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars() {
|
||||
super.setBars();
|
||||
|
||||
bars.remove(BarType.liquid);
|
||||
bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.get(consumes.liquid()) / liquidCapacity));
|
||||
bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.get(outputLiquid) / liquidCapacity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
return tile.entity.liquids.get(outputLiquid) < liquidCapacity;
|
||||
@ -42,13 +55,31 @@ public class LiquidMixer extends LiquidBlock{
|
||||
for (int i = 0; i < (int)(entity.accumulator / liquidPerItem); i++) {
|
||||
if(!entity.items.has(consumes.item())) break;
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
entity.accumulator --;
|
||||
entity.accumulator -= liquidPerItem;
|
||||
}
|
||||
}
|
||||
|
||||
tryDumpLiquid(tile, outputLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidModule mod = tile.entity.liquids;
|
||||
|
||||
int rotation = rotate ? tile.getRotation() * 90 : 0;
|
||||
|
||||
Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
|
||||
if(mod.total() > 0.001f){
|
||||
Draw.color(outputLiquid.color);
|
||||
Draw.alpha(mod.get(outputLiquid) / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new LiquidMixerEntity();
|
||||
|
@ -32,6 +32,7 @@ public class LiquidModule extends BlockModule {
|
||||
public void add(Liquid liquid, float amount){
|
||||
liquids[liquid.id] += amount;
|
||||
total += amount;
|
||||
current = liquid;
|
||||
}
|
||||
|
||||
public void remove(Liquid liquid, float amount){
|
||||
|
Reference in New Issue
Block a user