diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 8493610a4f..6c6bf1250d 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -907,7 +907,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } public void draw(){ - Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0); + if(block.variants == 0){ + Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0); + }else{ + Draw.rect(block.variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, block.variantRegions.length - 1))], x, y, block.rotate ? rotdeg() : 0); + } drawTeamTop(); } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 4f2f9a8ccd..b854d6bbab 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -78,6 +78,8 @@ public class Block extends UnlockableContent{ public boolean solidifes; /** whether this is rotateable */ public boolean rotate; + /** number of different variant regions to use */ + public int variants = 0; /** whether to draw a rotation arrow - this does not apply to lines of blocks */ public boolean drawArrow = true; /** for static blocks only: if true, tile data() is saved in world data. */ @@ -240,11 +242,11 @@ public class Block extends UnlockableContent{ public ObjectMap, Cons2> configurations = new ObjectMap<>(); protected TextureRegion[] generatedIcons; - protected TextureRegion[] variantRegions, editorVariantRegions; + protected TextureRegion[] editorVariantRegions; public TextureRegion region, editorIcon; public @Load("@-team") TextureRegion teamRegion; - public TextureRegion[] teamRegions; + public TextureRegion[] teamRegions, variantRegions; protected static final Seq tempTiles = new Seq<>(); protected static final Seq tempTileEnts = new Seq<>(); @@ -264,7 +266,11 @@ public class Block extends UnlockableContent{ if(tile.build != null){ tile.build.draw(); }else{ - Draw.rect(region, tile.drawx(), tile.drawy()); + if(variants == 0){ + Draw.rect(region, tile.drawx(), tile.drawy()); + }else{ + Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.drawx(), tile.drawy()); + } } } @@ -588,7 +594,8 @@ public class Block extends UnlockableContent{ protected TextureRegion[] icons(){ //use team region in vanilla team blocks - return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{region, teamRegions[Team.sharded.id]} : new TextureRegion[]{region}; + TextureRegion r = variants > 0 ? Core.atlas.find(name + "1") : region; + return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{r, teamRegions[Team.sharded.id]} : new TextureRegion[]{r}; } public TextureRegion[] getGeneratedIcons(){ @@ -831,6 +838,15 @@ public class Block extends UnlockableContent{ for(Team team : Team.all){ teamRegions[team.id] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion; } + + if(variants != 0){ + variantRegions = new TextureRegion[variants]; + + for(int i = 0; i < variants; i++){ + variantRegions[i] = Core.atlas.find(name + (i + 1)); + } + region = variantRegions[0]; + } } @Override diff --git a/core/src/mindustry/world/blocks/defense/Wall.java b/core/src/mindustry/world/blocks/defense/Wall.java index cde36ba964..10c5a7e5a9 100644 --- a/core/src/mindustry/world/blocks/defense/Wall.java +++ b/core/src/mindustry/world/blocks/defense/Wall.java @@ -15,8 +15,6 @@ import mindustry.world.meta.*; import static mindustry.Vars.*; public class Wall extends Block{ - public int variants = 0; - /** Lighting chance. -1 to disable */ public float lightningChance = -1f; public float lightningDamage = 20f; @@ -51,20 +49,6 @@ public class Wall extends Block{ } } - @Override - public void load(){ - super.load(); - - if(variants != 0){ - variantRegions = new TextureRegion[variants]; - - for(int i = 0; i < variants; i++){ - variantRegions[i] = Core.atlas.find(name + (i + 1)); - } - region = variantRegions[0]; - } - } - @Override public TextureRegion[] icons(){ return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")}; diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java index b6697991c8..8dcc228d4e 100644 --- a/core/src/mindustry/world/blocks/environment/Floor.java +++ b/core/src/mindustry/world/blocks/environment/Floor.java @@ -20,8 +20,6 @@ import mindustry.world.blocks.*; import static mindustry.Vars.*; public class Floor extends Block{ - /** number of different variant regions to use */ - public int variants = 3; /** edge fallback, used mainly for ores */ public String edge = "stone"; /** Multiplies unit velocity by this when walked on. */ @@ -76,6 +74,8 @@ public class Floor extends Block{ public Floor(String name){ super(name); + + variants = 3; } public Floor(String name, int variants){ @@ -90,7 +90,6 @@ public class Floor extends Block{ //load variant regions for drawing if(variants > 0){ variantRegions = new TextureRegion[variants]; - for(int i = 0; i < variants; i++){ variantRegions[i] = Core.atlas.find(name + (i + 1)); } @@ -98,7 +97,6 @@ public class Floor extends Block{ variantRegions = new TextureRegion[1]; variantRegions[0] = Core.atlas.find(name); } - int size = (int)(tilesize / Draw.scl); if(Core.atlas.has(name + "-edge")){ edges = Core.atlas.find(name + "-edge").split(size, size); diff --git a/core/src/mindustry/world/blocks/environment/Prop.java b/core/src/mindustry/world/blocks/environment/Prop.java index 1056748bce..6adfff5edb 100644 --- a/core/src/mindustry/world/blocks/environment/Prop.java +++ b/core/src/mindustry/world/blocks/environment/Prop.java @@ -7,8 +7,6 @@ import mindustry.content.*; import mindustry.world.*; public class Prop extends Block{ - public int variants; - public Prop(String name){ super(name); breakable = true; @@ -28,17 +26,4 @@ public class Prop extends Block{ public TextureRegion[] icons(){ return variants == 0 ? super.icons() : new TextureRegion[]{Core.atlas.find(name + "1")}; } - - @Override - public void load(){ - super.load(); - - if(variants > 0){ - variantRegions = new TextureRegion[variants]; - - for(int i = 0; i < variants; i++){ - variantRegions[i] = Core.atlas.find(name + (i + 1)); - } - } - } }