Merge branch 'master' into crater
# Conflicts: # core/assets/sprites/block_colors.png # core/assets/sprites/sprites.atlas # core/assets/sprites/sprites.png # core/assets/sprites/sprites3.png # core/assets/sprites/sprites5.png # core/src/mindustry/world/modules/ItemModule.java
This commit is contained in:
@@ -84,7 +84,7 @@ public interface Autotiler{
|
||||
default boolean blends(Tile tile, int rotation, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(rotation - direction, 4));
|
||||
if(other != null) other = other.link();
|
||||
return other != null && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
return other != null && other.getTeam() == tile.getTeam() && blends(tile, rotation, other.x, other.y, other.rotation(), other.block());
|
||||
}
|
||||
|
||||
default boolean blendsArmored(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemSelection{
|
||||
private static float scrollPos = 0f;
|
||||
|
||||
public static void buildItemTable(Table table, Prov<Item> holder, Cons<Item> consumer){
|
||||
|
||||
Array<Item> items = content.items();
|
||||
public static <T extends UnlockableContent> void buildTable(Table table, Array<T> items, Prov<T> holder, Cons<T> consumer){
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(38);
|
||||
cont.defaults().size(40);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(Item item : items){
|
||||
for(T item : items){
|
||||
if(!data.isUnlocked(item) && world.isZone()) continue;
|
||||
|
||||
ImageButton button = cont.addImageButton(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get();
|
||||
@@ -38,6 +36,22 @@ public class ItemSelection{
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
//add extra blank spaces so it looks nice
|
||||
if(i % 4 != 0){
|
||||
int remaining = 4 - (i % 4);
|
||||
for(int j = 0; j < remaining; j++){
|
||||
cont.addImage(Styles.black6);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(scrollPos);
|
||||
pane.update(() -> {
|
||||
scrollPos = pane.getScrollY();
|
||||
});
|
||||
|
||||
pane.setOverscroll(false, false);
|
||||
table.add(pane).maxHeight(Scl.scl(40 * 5));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +266,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||
ConveyorEntity e = tile.ent();
|
||||
amount = Math.min(amount, itemCapacity - e.len);
|
||||
|
||||
for(int i = amount - 1; i >= 0; i--){
|
||||
e.add(0);
|
||||
|
||||
@@ -2,13 +2,15 @@ package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.world;
|
||||
|
||||
public class OverflowGate extends Block{
|
||||
public float speed = 1f;
|
||||
public boolean invert = false;
|
||||
@@ -28,6 +30,11 @@ public class OverflowGate extends Block{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeStack(Tile tile, Item item, int amount){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
@@ -47,6 +54,11 @@ public class OverflowGate extends Block{
|
||||
}
|
||||
|
||||
if(entity.lastItem != null){
|
||||
if(entity.lastInput == null){
|
||||
entity.lastItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
entity.time += 1f / speed * Time.delta();
|
||||
Tile target = getTileTarget(tile, entity.lastItem, entity.lastInput, false);
|
||||
|
||||
@@ -120,19 +132,24 @@ public class OverflowGate extends Block{
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(lastInput == null ? Pos.invalid : lastInput.pos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(25, 50f).read(stream);
|
||||
}else if(revision == 3){
|
||||
lastInput = world.tile(stream.readInt());
|
||||
lastItem = items.first();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Sorter extends Block{
|
||||
private static Item lastItem;
|
||||
@@ -46,6 +46,9 @@ public class Sorter extends Block{
|
||||
@Override
|
||||
public void configured(Tile tile, Player player, int value){
|
||||
tile.<SorterEntity>ent().sortItem = content.item(value);
|
||||
if(!headless){
|
||||
renderer.minimap.update(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,7 +136,7 @@ public class Sorter extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
SorterEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class Battery extends PowerDistributor{
|
||||
public int topRegion = reg("-top");
|
||||
|
||||
public Color emptyLightColor = Color.valueOf("f8c266");
|
||||
public Color fullLightColor = Color.valueOf("fb9567");
|
||||
|
||||
public Battery(String name){
|
||||
super(name);
|
||||
outputsPower = true;
|
||||
consumesPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
Draw.color(emptyLightColor, fullLightColor, tile.entity.power.status);
|
||||
Fill.square(tile.drawx(), tile.drawy(), tilesize * size / 2f - 1);
|
||||
Draw.color();
|
||||
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SolarGenerator extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
tile.<GeneratorEntity>ent().productionEfficiency = state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f;
|
||||
tile.<GeneratorEntity>ent().productionEfficiency = state.rules.solarPowerMultiplier < 0 ? (state.rules.lighting ? 1f - state.rules.ambientLight.a : 1f) : state.rules.solarPowerMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -107,6 +107,7 @@ public class Separator extends Block{
|
||||
entity.cons.trigger();
|
||||
|
||||
if(item != null && entity.items.get(item) < itemCapacity){
|
||||
useContent(tile, item);
|
||||
offloadNear(tile, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ public class SolidPump extends Pump{
|
||||
tile.entity.liquids.add(result, maxPump);
|
||||
entity.lastPump = maxPump;
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
if(tile.entity.timer.get(timerContentCheck, 10)) useContent(tile, result);
|
||||
if(Mathf.chance(entity.delta() * updateEffectChance))
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f));
|
||||
}else{
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ItemSource extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
ItemSourceEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.outputItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.outputItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package mindustry.world.blocks.sandbox;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.traits.BuilderTrait.*;
|
||||
import mindustry.entities.type.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class LiquidSource extends Block{
|
||||
public static Liquid lastLiquid;
|
||||
@@ -82,29 +77,10 @@ public class LiquidSource extends Block{
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
LiquidSourceEntity entity = tile.ent();
|
||||
|
||||
Array<Liquid> items = content.liquids();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
|
||||
for(int i = 0; i < items.size; i++){
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton(Tex.clear, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).size(38).group(group).get();
|
||||
button.changed(() -> {
|
||||
tile.configure(button.isChecked() ? items.get(f).id : -1);
|
||||
control.input.frag.config.hideConfig();
|
||||
lastLiquid = items.get(f);
|
||||
});
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(items.get(i).icon(Cicon.medium));
|
||||
button.setChecked(entity.source == items.get(i));
|
||||
|
||||
if(i % 4 == 3){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
ItemSelection.buildTable(table, content.liquids(), () -> entity.source, liquid -> {
|
||||
lastLiquid = liquid;
|
||||
tile.configure(liquid == null ? -1 : liquid.id);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,7 +123,7 @@ public class Unloader extends Block{
|
||||
@Override
|
||||
public void buildConfiguration(Tile tile, Table table){
|
||||
UnloaderEntity entity = tile.ent();
|
||||
ItemSelection.buildItemTable(table, () -> entity.sortItem, item -> {
|
||||
ItemSelection.buildTable(table, content.items(), () -> entity.sortItem, item -> {
|
||||
lastItem = item;
|
||||
tile.configure(item == null ? -1 : item.id);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.ItemStack;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
@@ -69,7 +68,7 @@ public class ItemModule extends BlockModule{
|
||||
return total;
|
||||
}
|
||||
|
||||
public Item first(){ // fixme: entangle with take()
|
||||
public Item first(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
return content.item(i);
|
||||
@@ -81,12 +80,12 @@ public class ItemModule extends BlockModule{
|
||||
public Item take(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
int index = (i + takeRotation);
|
||||
if(index >= items.length) index -= items.length; //conditional instead of mod
|
||||
if(index >= items.length) index -= items.length;
|
||||
if(items[index] > 0){
|
||||
items[index] --;
|
||||
total --;
|
||||
takeRotation = index + 1;
|
||||
return content.item(index % items.length);
|
||||
return content.item(index);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user