diff --git a/core/src/mindustry/world/blocks/TileBitmask.java b/core/src/mindustry/world/blocks/TileBitmask.java
new file mode 100644
index 0000000000..f911469267
--- /dev/null
+++ b/core/src/mindustry/world/blocks/TileBitmask.java
@@ -0,0 +1,23 @@
+package mindustry.world.blocks;
+
+public class TileBitmask{
+ /** Autotile bitmasks for 8-directional sprites (see tile-gen)*/
+ public static final int[] values = {
+ 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
+ 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
+ 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
+ 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
+ 3, 4, 3, 4, 15, 40, 15, 20, 3, 4, 3, 4, 15, 40, 15, 20,
+ 5, 28, 5, 28, 29, 10, 29, 23, 5, 28, 5, 28, 31, 11, 31, 32,
+ 3, 4, 3, 4, 15, 40, 15, 20, 3, 4, 3, 4, 15, 40, 15, 20,
+ 2, 30, 2, 30, 9, 46, 9, 22, 2, 30, 2, 30, 14, 44, 14, 6,
+ 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
+ 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
+ 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
+ 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
+ 3, 0, 3, 0, 15, 42, 15, 12, 3, 0, 3, 0, 15, 42, 15, 12,
+ 5, 8, 5, 8, 29, 35, 29, 33, 5, 8, 5, 8, 31, 34, 31, 7,
+ 3, 0, 3, 0, 15, 42, 15, 12, 3, 0, 3, 0, 15, 42, 15, 12,
+ 2, 1, 2, 1, 9, 45, 9, 19, 2, 1, 2, 1, 14, 18, 14, 13,
+ };
+}
diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java
index 68809deafe..7b9f9ebe3f 100644
--- a/core/src/mindustry/world/blocks/environment/Floor.java
+++ b/core/src/mindustry/world/blocks/environment/Floor.java
@@ -15,6 +15,7 @@ import mindustry.graphics.*;
import mindustry.graphics.MultiPacker.*;
import mindustry.type.*;
import mindustry.world.*;
+import mindustry.world.blocks.*;
import java.util.*;
@@ -77,8 +78,11 @@ public class Floor extends Block{
public int blendId = -1;
/** If >0, this floor is drawn as parts of a large texture. */
public int tilingVariants = 0;
+ /** If true, this floor uses autotiling; variants are not supported. See https://github.com/GglLfr/tile-gen*/
+ public boolean autotile = false;
protected TextureRegion[][][] tilingRegions;
+ protected TextureRegion[] autotileRegions;
protected int tilingSize;
protected TextureRegion[][] edges;
protected Seq blenders = new Seq<>();
@@ -104,6 +108,10 @@ public class Floor extends Block{
public void load(){
super.load();
+ if(autotile){
+ variants = 0;
+ }
+
int tsize = (int)(tilesize / Draw.scl);
if(tilingVariants > 0 && !headless){
@@ -132,6 +140,13 @@ public class Floor extends Block{
variantRegions[0] = Core.atlas.find(name);
}
+ if(autotile){
+ autotileRegions = new TextureRegion[47];
+ for(int i = 0; i < 47; i++){
+ autotileRegions[i] = Core.atlas.find(name + "-" + i);
+ }
+ }
+
if(Core.atlas.has(name + "-edge")){
edges = Core.atlas.find(name + "-edge").split(tsize, tsize);
}
@@ -208,6 +223,17 @@ public class Floor extends Block{
int index = Mathf.randomSeed(Point2.pack(tile.x / tilingSize, tile.y / tilingSize), 0, tilingVariants - 1);
TextureRegion[][] regions = tilingRegions[index];
Draw.rect(regions[tile.x % tilingSize][tilingSize - 1 - tile.y % tilingSize], tile.worldx(), tile.worldy());
+ }else if(autotile){
+ int bits = 0;
+
+ for(int i = 0; i < 8; i++){
+ Tile other = tile.nearby(Geometry.d8[i]);
+ if(other != null && other.floor().blendGroup == blendGroup){
+ bits |= (1 << i);
+ }
+ }
+
+ Draw.rect(autotileRegions[TileBitmask.values[bits]], tile.worldx(), tile.worldy());
}else{
Draw.rect(variantRegions[variant(tile.x, tile.y)], tile.worldx(), tile.worldy());
}
diff --git a/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java b/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java
index 03effdfcc4..a6ff9d3aed 100644
--- a/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java
+++ b/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java
@@ -13,6 +13,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.world.*;
+import mindustry.world.blocks.*;
import static mindustry.Vars.*;
@@ -27,25 +28,6 @@ public class TileableLogicDisplay extends LogicDisplay{
public @Load(value = "@-#", length = 47) TextureRegion[] tileRegion;
public @Load("@-back") TextureRegion backRegion;
- static final int[] bitmasks = {
- 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
- 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
- 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
- 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
- 3, 4, 3, 4, 15, 40, 15, 20, 3, 4, 3, 4, 15, 40, 15, 20,
- 5, 28, 5, 28, 29, 10, 29, 23, 5, 28, 5, 28, 31, 11, 31, 32,
- 3, 4, 3, 4, 15, 40, 15, 20, 3, 4, 3, 4, 15, 40, 15, 20,
- 2, 30, 2, 30, 9, 46, 9, 22, 2, 30, 2, 30, 14, 44, 14, 6,
- 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
- 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
- 39, 36, 39, 36, 27, 16, 27, 24, 39, 36, 39, 36, 27, 16, 27, 24,
- 38, 37, 38, 37, 17, 41, 17, 43, 38, 37, 38, 37, 26, 21, 26, 25,
- 3, 0, 3, 0, 15, 42, 15, 12, 3, 0, 3, 0, 15, 42, 15, 12,
- 5, 8, 5, 8, 29, 35, 29, 33, 5, 8, 5, 8, 31, 34, 31, 7,
- 3, 0, 3, 0, 15, 42, 15, 12, 3, 0, 3, 0, 15, 42, 15, 12,
- 2, 1, 2, 1, 9, 45, 9, 19, 2, 1, 2, 1, 14, 18, 14, 13,
- };
-
public TileableLogicDisplay(String name){
super(name);
@@ -247,7 +229,7 @@ public class TileableLogicDisplay extends LogicDisplay{
Draw.z(Layer.block + 0.02f);
- Draw.rect(tileRegion[bitmasks[bits]], x, y);
+ Draw.rect(tileRegion[TileBitmask.values[bits]], x, y);
}
@Override