diff --git a/models.txt b/models.txt new file mode 100644 index 00000000..7047f174 --- /dev/null +++ b/models.txt @@ -0,0 +1,823 @@ +# Wood Stair - up south +# Cobblestone Stair - up south +block:id=53,id=67,data=0,scale=2 +layer:0 +** +** +layer:1 +-- +** +# Wood Stair - up north +# Cobblestone Stair - up north +block:id=53,id=67,data=1,scale=2 +rotate:id=53,data=0,rot=180 +# Wood Stair - up west +# Cobblestone Stair - up west +block:id=53,id=67,data=2,scale=2 +rotate:id=53,data=0,rot=90 +# Wood Stair - up east +# Cobblestone Stair - up east +block:id=53,id=67,data=3,scale=2 +rotate:id=53,data=0,rot=270 +# Slab (stone, sandstone, wood, cobblestone) +block:id=44,data=*,scale=2 +layer:0 +** +** +layer:1 +-- +-- +# Snow +block:id=78,data=*,scale=4 +layer:0 +**** +**** +**** +**** +# Torch - up +# Redstone torch on - up +# Redstone torch off - up +block:id=50,id=75,id=76,data=5,data=0,scale=8 +layer:0,1,2,3,4 +-------- +-------- +-------- +---**--- +---**--- +-------- +-------- +-------- +# Torch - pointing south +# Redstone torch on - pointing south +# Redstone torch off - pointing south +block:id=50,id=75,id=76,data=1,scale=8 +layer:2 +---**--- +-------- +-------- +-------- +-------- +-------- +-------- +-------- +layer:3,4 +---**--- +---**--- +-------- +-------- +-------- +-------- +-------- +-------- +layer:5 +-------- +---**--- +---**--- +-------- +-------- +-------- +-------- +-------- +# Torch - pointing north +# Redstone torch on - pointing north +# Redstone torch off - pointing north +block:id=50,id=75,id=76,data=2,scale=8 +rotate:id=50,data=1,rot=180 +# Torch - pointing west +# Redstone torch on - pointing west +# Redstone torch off - pointing west +block:id=50,id=75,id=76,data=3,scale=8 +rotate:id=50,data=1,rot=90 +# Torch - pointing east +# Redstone torch on - pointing east +# Redstone torch off - pointing east +block:id=50,id=75,id=76,data=4,scale=8 +rotate:id=50,data=1,rot=270 +# Fence +block:id=85,data=*,scale=8 +layer:0,1,3,4,6 +-------- +-------- +-------- +---**--- +---**--- +-------- +-------- +-------- +layer:2,5 +---**--- +---**--- +---**--- +******** +******** +---**--- +---**--- +---**--- +# Trapdoor +# Stone pressure plate +# Wooden pressure plate +block:id=96,id=72,id=70,data=*,scale=8 +layer:0 +-------- +-******- +-******- +-******- +-******- +-******- +-******- +-------- +# Crops +block:id=59,data=*,scale=8 +layer:0,1,2,3,4,5 +*-*-*-*- +-------- +*-*-*-*- +-------- +*-*-*-*- +-------- +*-*-*-*- +-------- +layer:6,7 +*---*--- +-------- +--*---*- +-------- +*---*--- +-------- +--*---*- +-------- +# Sugar Cane +block:id=83,data=*,scale=8 +layer:0,1,2,3,4,5,6,7 +*-*-*-*- +-------- +*-*-*-*- +-------- +*-*-*-*- +-------- +*-*-*-*- +-------- +# Stone Button - facing south +block:id=77,data=1,data=9,scale=8 +layer:3,4 +---**--- +---**--- +-------- +-------- +-------- +-------- +-------- +-------- +# Stone Button - facing north +block:id=77,data=2,data=10,scale=8 +rotate:id=77,data=1,rot=180 +# Stone Button - facing west +block:id=77,data=3,data=11,scale=8 +rotate:id=77,data=1,rot=90 +# Stone Button - facing east +block:id=77,data=4,data=12,scale=8 +rotate:id=77,data=1,rot=270 +# Rails - flat - east/west +block:id=66,data=0,scale=16 +layer:0 +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +-**--**--**--**- +layer:1,2 +---------------- +---------------- +**************** +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +**************** +**************** +---------------- +---------------- +# Rails - flat - north/south +block:id=66,data=1,scale=16 +rotate:id=66,data=0,rot=90 +# Rails - ascending to south +block:id=66,data=2,scale=16 +layer:1 +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:1 +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:2 +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:3 +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:4 +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:5 +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:6 +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:7 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:8 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:9 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +---------------- +---------------- +---------------- +layer:10 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:11 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +---------------- +---------------- +---------------- +layer:12 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +---------------- +layer:13 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +**************** +---------------- +layer:14 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +---------------- +layer:15 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +--**--------**-- +--**--------**-- +# Rails - ascending to north +block:id=66,data=3,scale=16 +rotate:id=66,data=2,rot=180 +# Rails - ascending to east +block:id=66,data=4,scale=16 +rotate:id=66,data=2,rot=270 +# Rails - ascending to west +block:id=66,data=5,scale=16 +rotate:id=66,data=2,rot=90 +# Rails - northeast corner +block:id=66,data=6,scale=16 +layer:0 +-**------------- +-**------------- +-**---------*--- +-**--------***-- +-**-------***--- +-**------***---- +-**-----***----- +-*-----***------ +-*-----**------- +-*----*--------- +-*---*---------- +-*--*----------- +-*-*------------ +-**------******* +-*************** +---------------- +layer:1,2 +---------------- +---------------- +****------------ +********-------- +----******------ +--------***----- +---------***---- +----------**---- +-----------**--- +-----------**--- +-----------**--- +-----------**--- +***---------**-- +****--------**-- +--**--------**-- +--**--------**-- +# Rails - southeast corner +block:id=66,data=7,scale=16 +rotate:id=66,data=6,rot=90 +# Rails - southwest corner +block:id=66,data=8,scale=16 +rotate:id=66,data=6,rot=180 +# Rails - northwest corner +block:id=66,data=9,scale=16 +rotate:id=66,data=6,rot=270 +# Powered rails - flat - east/west +# Detector rails - flat - east/west +block:id=27,id=28,data=0,data=8,scale=16 +rotate:id=66,data=0,rot=0 +# Powered rails - flat - north/south +# Detector rails - flat - north/south +block:id=27,id=28,data=1,data=9,scale=16 +rotate:id=66,data=1,rot=0 +# Powered rails - ascending to south +# Detector rails - ascending to south +block:id=27,id=28,data=2,data=10,scale=16 +rotate:id=66,data=2,rot=0 +# Powered rails - ascending to north +# Detector rails - ascending to north +block:id=27,id=28,data=3,data=11,scale=16 +rotate:id=66,data=3,rot=0 +# Powered rails - ascending to east +# Detector rails - ascending to east +block:id=27,id=28,data=4,data=12,scale=16 +rotate:id=66,data=4,rot=0 +# Powered rails - ascending to west +# Detector rails - ascending to west +block:id=27,id=28,data=5,data=13,scale=16 +rotate:id=66,data=5,rot=0 +# Ladder - attached to east side of block +block:id=65,data=2,scale=16 +layer:0,3,4,7,8,11,12,15 +---------------- +***------------- +***------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +***------------- +***------------- +---------------- +layer:1,2,5,6,9,10,13,14 +-*-------------- +***------------- +***------------- +-*-------------- +-*-------------- +-*-------------- +-*-------------- +-*-------------- +-*-------------- +***------------- +***------------- +-*-------------- +# Ladder - attached to west side of block +block:id=65,data=3,scale=16 +rotate:id=65,data=2,rot=180 +# Ladder - attached to north side of block +block:id=65,data=4,scale=16 +rotate:id=65,data=2,rot=270 +# Ladder - attached to south side of block +block:id=65,data=5,scale=16 +rotate:id=65,data=2,rot=90 +# Wall sign - facing east +block:id=68,data=2,scale=4 +layer:1,2 +*--- +*--- +*--- +*--- +# Wall sign - facing west +block:id=68,data=3,scale=4 +rotate:id=68,data=2,rot=180 +# Wall sign - facing north +block:id=68,data=4,scale=4 +rotate:id=68,data=2,rot=270 +# Wall sign - facing south +block:id=68,data=5,scale=4 +rotate:id=68,data=2,rot=90 +# Redstone wire +block:id=55,data=*,scale=16 +layer:0 +-------**------- +--------**------ +-------**------- +------**-------- +-------**------- +--------**------ +-*---*-**---*--- +***-******-***-* +*-***-******-*** +---*---**-*---*- +------**-------- +-------**------- +--------**------ +-------**------- +------**-------- +-------**------- +# Signpost - facing west +block:id=63,data=0,scale=16 +layer:0,1,2,3,4,5 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +-------**------- +-------**------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:6,7,8,9,10,11,12 +---------------- +------**-------- +------**-------- +------**-------- +------**-------- +------**-------- +------**-------- +------***------- +------***------- +------**-------- +------**-------- +------**-------- +------**-------- +------**-------- +------**-------- +---------------- +# Signpost - facing north +block:id=63,data=4,scale=16 +rotate:id=63,data=0,rot=90 +# Signpost - facing east +block:id=63,data=8,scale=16 +rotate:id=63,data=0,rot=180 +# Signpost - facing south +block:id=63,data=12,scale=16 +rotate:id=63,data=0,rot=270 +# Signpost - facing northwest +block:id=63,data=2,scale=16 +layer:0,1,2,3,4,5 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +-------**------- +-------**------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:6,7,8,9,10,11,12 +---------------- +---------**----- +---------**----- +--------**------ +--------**------ +-------**------- +-------**------- +------***------- +------***------- +-----**--------- +-----**--------- +----**---------- +----**---------- +---**----------- +---**----------- +---------------- +# Signpost - facing northeast +block:id=63,data=6,scale=16 +rotate:id=63,data=2,rot=90 +# Signpost - facing southeast +block:id=63,data=10,scale=16 +rotate:id=63,data=2,rot=180 +# Signpost - facing southwest +block:id=63,data=14,scale=16 +rotate:id=63,data=2,rot=270 +# Signpost - facing west-northwest +block:id=63,data=1,scale=16 +layer:0,1,2,3,4,5 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +-------**------- +-------**------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:6,7,8,9,10,11,12 +---------------- +-------**------- +-------**------- +-------**------- +-------**------- +------**-------- +------**-------- +------***------- +------***------- +------**-------- +------**-------- +-----**--------- +-----**--------- +-----**--------- +-----**--------- +---------------- +# Signpost - facing north-northeast +block:id=63,data=5,scale=16 +rotate:id=63,data=1,rot=90 +# Signpost - facing north-northeast +block:id=63,data=9,scale=16 +rotate:id=63,data=1,rot=180 +# Signpost - facing north-northeast +block:id=63,data=13,scale=16 +rotate:id=63,data=1,rot=270 +# Signpost - facing west-southwest +block:id=63,data=15,scale=16 +layer:0,1,2,3,4,5 +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +-------**------- +-------**------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +---------------- +layer:6,7,8,9,10,11,12 +---------------- +-----**--------- +-----**--------- +-----**--------- +-----**--------- +------**-------- +------**-------- +------***------- +------***------- +------**-------- +------**-------- +-------**------- +-------**------- +-------**------- +-------**------- +---------------- +# Signpost - facing north-northwest +block:id=63,data=3,scale=16 +rotate:id=63,data=15,rot=90 +# Signpost - facing east-northeast +block:id=63,data=7,scale=16 +rotate:id=63,data=15,rot=180 +# Signpost - facing south-southeast +block:id=63,data=11,scale=16 +rotate:id=63,data=15,rot=270 + diff --git a/src/main/assembly/package.xml b/src/main/assembly/package.xml index 92cdce81..6335a1fd 100644 --- a/src/main/assembly/package.xml +++ b/src/main/assembly/package.xml @@ -31,7 +31,8 @@ shaders.txt perspectives.txt lightings.txt - configuration.txt.sample-hd + configuration.txt.sample-hd + models.txt diff --git a/src/main/java/org/dynmap/Color.java b/src/main/java/org/dynmap/Color.java index 019d8bcf..636d5267 100644 --- a/src/main/java/org/dynmap/Color.java +++ b/src/main/java/org/dynmap/Color.java @@ -52,4 +52,7 @@ public class Color { public final int getComponent(int idx) { return 0xFF & (val >> ((3-idx)*8)); } + public final void setAlpha(int v) { + val = (val & 0x00FFFFFF) | (v << 24); + } } diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 59a5df2a..8cfcfd64 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -34,6 +34,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.debug.Debug; import org.dynmap.debug.Debugger; +import org.dynmap.hdmap.HDBlockModels; import org.dynmap.permissions.NijikokunPermissions; import org.dynmap.permissions.OpPermissions; import org.dynmap.permissions.PermissionProvider; @@ -76,7 +77,8 @@ public class DynmapPlugin extends JavaPlugin { permissions = new OpPermissions(new String[] { "fullrender", "reload" }); dataDirectory = this.getDataFolder(); - + /* Load block models */ + HDBlockModels.loadModels(dataDirectory); org.bukkit.util.config.Configuration bukkitConfiguration = new org.bukkit.util.config.Configuration(new File(this.getDataFolder(), "configuration.txt")); bukkitConfiguration.load(); configuration = new ConfigurationNode(bukkitConfiguration); diff --git a/src/main/java/org/dynmap/hdmap/DefaultHDShader.java b/src/main/java/org/dynmap/hdmap/DefaultHDShader.java index b2461da0..690fad02 100644 --- a/src/main/java/org/dynmap/hdmap/DefaultHDShader.java +++ b/src/main/java/org/dynmap/hdmap/DefaultHDShader.java @@ -163,6 +163,12 @@ public class DefaultHDShader implements HDShader { if (c.getAlpha() > 0) { /* Handle light level, if needed */ lighting.applyLighting(ps, this, c, tmpcolor); + /* If we got alpha from subblock model, use it instead */ + int subalpha = ps.getSubmodelAlpha(); + if(subalpha >= 0) { + for(Color clr : tmpcolor) + clr.setAlpha(subalpha); + } /* Blend color with accumulated color (weighted by alpha) */ if(!transparency) { /* No transparency support */ for(i = 0; i < color.length; i++) diff --git a/src/main/java/org/dynmap/hdmap/HDBlockModels.java b/src/main/java/org/dynmap/hdmap/HDBlockModels.java index f9e17bbc..17f4aef0 100644 --- a/src/main/java/org/dynmap/hdmap/HDBlockModels.java +++ b/src/main/java/org/dynmap/hdmap/HDBlockModels.java @@ -1,9 +1,14 @@ package org.dynmap.hdmap; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.LineNumberReader; import java.util.ArrayList; import java.util.HashMap; import org.bukkit.Material; +import org.dynmap.Log; /** * Custom block models - used for non-cube blocks to represent the physical volume associated with the block @@ -22,8 +27,7 @@ public class HDBlockModels { private short[][][] modelvectors; public final short[] getScaledModel(int blocktype, int blockdata) { - if((blocktype > modelvectors.length) || (modelvectors[blocktype] == null) || - (modelvectors[blocktype][blockdata] == null)) { + if(modelvectors[blocktype] == null) { return null; } return modelvectors[blocktype][blockdata]; @@ -31,111 +35,6 @@ public class HDBlockModels { } private static HashMap scaled_models_by_scale = new HashMap(); - - /* Block models */ - private static HDBlockModels WOOD_STAIR_UP_NORTH = new HDBlockModels(Material.WOOD_STAIRS, 1<<1, 2, new long[] { - 0x03, 0x03, - 0x01, 0x01 }); - private static HDBlockModels WOOD_STAIR_UP_SOUTH = new HDBlockModels(Material.WOOD_STAIRS, 1<<0, 2, new long[] { - 0x03, 0x03, - 0x02, 0x02 }); - private static HDBlockModels WOOD_STAIR_UP_WEST = new HDBlockModels(Material.WOOD_STAIRS, 1<<2, 2, new long[] { - 0x03, 0x03, - 0x00, 0x03 }); - private static HDBlockModels WOOD_STAIR_UP_EAST = new HDBlockModels(Material.WOOD_STAIRS, 1<<3, 2, new long[] { - 0x03, 0x03, - 0x03, 0x00 }); - private static HDBlockModels COBBLE_STAIR_UP_NORTH = new HDBlockModels(Material.COBBLESTONE_STAIRS, 1<<1, WOOD_STAIR_UP_NORTH); - private static HDBlockModels COBBLE_STAIR_UP_SOUTH = new HDBlockModels(Material.COBBLESTONE_STAIRS, 1<<0, WOOD_STAIR_UP_SOUTH); - private static HDBlockModels COBBLE_STAIR_UP_WEST = new HDBlockModels(Material.COBBLESTONE_STAIRS, 1<<2, WOOD_STAIR_UP_WEST); - private static HDBlockModels COBBLE_STAIR_UP_EAST = new HDBlockModels(Material.COBBLESTONE_STAIRS, 1<<3, WOOD_STAIR_UP_EAST); - private static HDBlockModels STEP = new HDBlockModels(Material.STEP, 0x0F, 2, new long[] { - 0x03, - 0x03 }); - private static HDBlockModels SNOW = new HDBlockModels(Material.SNOW, 0x0F, 4, new long[] { - 0x0F, 0x0F, 0x0F, 0x0F }); - private static HDBlockModels TORCH_UP = new HDBlockModels(Material.TORCH, (1<<5) | (1 << 0), 4, new long[] { - 0x00, 0x02, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00 }); - private static HDBlockModels TORCH_SOUTH = new HDBlockModels(Material.TORCH, (1<<1), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels TORCH_NORTH = new HDBlockModels(Material.TORCH, (1<<2), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x00, - 0x00, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels TORCH_WEST = new HDBlockModels(Material.TORCH, (1<<3), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels TORCH_EAST = new HDBlockModels(Material.TORCH, (1<<4), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x02, - 0x00, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels REDSTONETORCHON_UP = new HDBlockModels(Material.REDSTONE_TORCH_ON, (1<<5) | (1 << 0), TORCH_UP); - private static HDBlockModels REDSTONETORCHOFF_UP = new HDBlockModels(Material.REDSTONE_TORCH_OFF, (1<<5) | (1 << 0), TORCH_UP); - private static HDBlockModels REDSTONETORCHON_NORTH = new HDBlockModels(Material.REDSTONE_TORCH_ON, (1<<2), TORCH_NORTH); - private static HDBlockModels REDSTONETORCHOFF_NORTH = new HDBlockModels(Material.REDSTONE_TORCH_OFF, (1<<2), TORCH_NORTH); - private static HDBlockModels REDSTONETORCHON_SOUTH = new HDBlockModels(Material.REDSTONE_TORCH_ON, (1<<1), TORCH_SOUTH); - private static HDBlockModels REDSTONETORCHOFF_SOUTH = new HDBlockModels(Material.REDSTONE_TORCH_OFF, (1<<1), TORCH_SOUTH); - private static HDBlockModels REDSTONETORCHON_EAST = new HDBlockModels(Material.REDSTONE_TORCH_ON, (1<<4), TORCH_EAST); - private static HDBlockModels REDSTONETORCHOFF_EAST = new HDBlockModels(Material.REDSTONE_TORCH_OFF, (1<<4), TORCH_EAST); - private static HDBlockModels REDSTONETORCHON_WEST = new HDBlockModels(Material.REDSTONE_TORCH_ON, (1<<3), TORCH_WEST); - private static HDBlockModels REDSTONETORCHOFF_WEST = new HDBlockModels(Material.REDSTONE_TORCH_OFF, (1<<3), TORCH_WEST); - private static HDBlockModels FENCE = new HDBlockModels(Material.FENCE, 0xFFFF, 4, new long[] { - 0x00, 0x06, 0x06, 0x00, - 0x00, 0x06, 0x06, 0x00, - 0x00, 0x06, 0x06, 0x00, - 0x00, 0x06, 0x06, 0x00 }); - private static HDBlockModels TRAPDOOR = new HDBlockModels(Material.TRAP_DOOR, 0xFFFF, 4, new long[] { - 0x0F, 0x0F, 0x0F, 0x0F }); - private static HDBlockModels WOODPRESSPLATE = new HDBlockModels(Material.WOOD_PLATE, 0xFFFF, 4, new long[] { - 0x0F, 0x0F, 0x0F, 0x0F }); - private static HDBlockModels STONEPRESSPLATE = new HDBlockModels(Material.STONE_PLATE, 0xFFFF, 4, new long[] { - 0x0F, 0x0F, 0x0F, 0x0F }); - private static HDBlockModels WALLSIGN_NORTH = new HDBlockModels(Material.WALL_SIGN, (1<<4), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels WALLSIGN_SOUTH = new HDBlockModels(Material.WALL_SIGN, (1<<5), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels WALLSIGN_EAST = new HDBlockModels(Material.WALL_SIGN, (1<<2), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x0F, - 0x00, 0x00, 0x00, 0x0F, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels WALLSIGN_WEST = new HDBlockModels(Material.WALL_SIGN, (1<<3), 4, new long[] { - 0x00, 0x00, 0x00, 0x00, - 0x0F, 0x00, 0x00, 0x00, - 0x0F, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels REDSTONEWIRE = new HDBlockModels(Material.REDSTONE_WIRE, 0xFFFF, 8, new long[] { - 0x18, 0x18, 0x18, 0xFF, 0xFF, 0x18, 0x18, 0x18 }); - private static HDBlockModels SIGNPOST_EASTWEST = new HDBlockModels(Material.SIGN_POST, 0xC7C7, 8, new long[] { - 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); - private static HDBlockModels SIGHPOST_NORTHSOUTH = new HDBlockModels(Material.SIGN_POST, 0x3838, 8, new long[] { - 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); /** * Block definition - copy from other @@ -159,14 +58,26 @@ public class HDBlockModels { * if array is short, other elements area are assumed to be zero (fills from bottom of block up) */ public HDBlockModels(Material blocktype, int databits, int nativeres, long[] blockflags) { - this.blockid = blocktype.getId(); + this(blocktype.getId(), databits, nativeres, blockflags); + } + /** + * Block definition - positions correspond to Bukkit coordinates (+X is south, +Y is up, +Z is west) + * @param blockid - block ID + * @param databits - bitmap of block data bits matching this model (bit N is set if data=N would match) + * @param nativeres - native subblocks per edge of cube (up to 64) + * @param blockflags - array of native^2 long integers representing volume of block (bit X of element (nativeres*Y+Z) is set if that subblock is filled) + * if array is short, other elements area are assumed to be zero (fills from bottom of block up) + */ + public HDBlockModels(int blockid, int databits, int nativeres, long[] blockflags) { + this.blockid = blockid; this.databits = databits; this.nativeres = nativeres; this.blockflags = new long[nativeres * nativeres]; System.arraycopy(blockflags, 0, this.blockflags, 0, blockflags.length); for(int i = 0; i < 16; i++) { - if((databits & (1< modlist = new ArrayList(); + int layerbits = 0; + int rownum = 0; + int scale = 0; + rdr = new LineNumberReader(new FileReader(new File(plugindir, "models.txt"))); + while((line = rdr.readLine()) != null) { + if(line.startsWith("block:")) { + ArrayList blkids = new ArrayList(); + int databits = 0; + scale = 0; + line = line.substring(6); + String[] args = line.split(","); + for(String a : args) { + String[] av = a.split("="); + if(av.length < 2) continue; + if(av[0].equals("id")) { + blkids.add(Integer.parseInt(av[1])); + } + else if(av[0].equals("data")) { + if(av[1].equals("*")) + databits = 0xFFFF; + else + databits |= (1 << Integer.parseInt(av[1])); + } + else if(av[0].equals("scale")) { + scale = Integer.parseInt(av[1]); + } + } + /* If we have everything, build block */ + if((blkids.size() > 0) && (databits != 0) && (scale > 0)) { + modlist.clear(); + for(Integer id : blkids) { + modlist.add(new HDBlockModels(id.intValue(), databits, scale, new long[0])); + cnt++; + } + } + else { + Log.severe("Block model missing required parameters = line " + rdr.getLineNumber() + " of models.txt"); + } + layerbits = 0; + } + else if(line.startsWith("layer:")) { + line = line.substring(6); + String args[] = line.split(","); + layerbits = 0; + rownum = 0; + for(String a: args) { + layerbits |= (1 << Integer.parseInt(a)); + } + } + else if(line.startsWith("rotate:")) { + line = line.substring(7); + String args[] = line.split(","); + int id = -1; + int data = -1; + int rot = -1; + for(String a : args) { + String[] av = a.split("="); + if(av.length < 2) continue; + if(av[0].equals("id")) { id = Integer.parseInt(av[1]); } + if(av[0].equals("data")) { data = Integer.parseInt(av[1]); } + if(av[0].equals("rot")) { rot = Integer.parseInt(av[1]); } + } + /* get old model to be rotated */ + HDBlockModels mod = models_by_id_data.get((id<<4)+data); + if((mod != null) && ((rot%90) == 0)) { + for(int x = 0; x < scale; x++) { + for(int y = 0; y < scale; y++) { + for(int z = 0; z < scale; z++) { + if(mod.isSubblockSet(x, y, z) == false) continue; + switch(rot) { + case 0: + for(HDBlockModels bm : modlist) + bm.setSubblock(x, y, z, true); + break; + case 90: + for(HDBlockModels bm : modlist) + bm.setSubblock(scale-z-1, y, x, true); + break; + case 180: + for(HDBlockModels bm : modlist) + bm.setSubblock(scale-x-1, y, scale-z-1, true); + break; + case 270: + for(HDBlockModels bm : modlist) + bm.setSubblock(z, y, scale-x-1, true); + break; + } + } + } + } + } + } + else if(line.startsWith("#") || line.startsWith(";")) { + } + else if(layerbits != 0) { /* If we're working pattern lines */ + /* Layerbits determine Y, rows count from North to South (X=0 to X=N-1), columns Z are West to East (N-1 to 0) */ + for(int i = 0; (i < scale) && (i < line.length()); i++) { + if(line.charAt(i) == '*') { /* If an asterix, set flag */ + for(int y = 0; y < scale; y++) { + if((layerbits & (1<= scale) { + rownum = 0; + layerbits = 0; + } + } + } + Log.info("Loaded " + cnt + " block models"); + } catch (IOException iox) { + Log.severe("Error reading models.txt - " + iox.toString()); + } catch (NumberFormatException nfx) { + Log.severe("Format error - line " + rdr.getLineNumber() + " of models.txt"); + } finally { + if(rdr != null) { + try { + rdr.close(); + rdr = null; + } catch (IOException e) { + } + } + } + } } diff --git a/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java b/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java index e51b2749..4903766c 100644 --- a/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java +++ b/src/main/java/org/dynmap/hdmap/HDPerspectiveState.java @@ -52,4 +52,8 @@ public interface HDPerspectiveState { * Get pixel Y coordinate */ int getPixelY(); + /** + * Return submodel alpha value (-1 if no submodel rendered) + */ + int getSubmodelAlpha(); } diff --git a/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java b/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java index 63db00e2..b996f81a 100644 --- a/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java +++ b/src/main/java/org/dynmap/hdmap/IsoHDPerspective.java @@ -86,6 +86,7 @@ public class IsoHDPerspective implements HDPerspective { int x_inc, y_inc, z_inc; double t_next_y, t_next_x, t_next_z; boolean nonairhit; + int subalpha; /** * Get sky light level - only available if shader requested it */ @@ -126,7 +127,12 @@ public class IsoHDPerspective implements HDPerspective { * Get pixel Y coordinate */ public final int getPixelY() { return py; } - + /** + * Return submodel alpha value (-1 if no submodel rendered) + */ + public int getSubmodelAlpha() { + return subalpha; + } /** * Initialize raytrace state variables */ @@ -213,11 +219,15 @@ public class IsoHDPerspective implements HDPerspective { if(nonairhit || (blocktypeid != 0)) { blockdata = mapiter.getBlockData(); boolean missed = false; + /* Look up to see if block is modelled */ short[] model = scalemodels.getScaledModel(blocktypeid, blockdata); if(model != null) { missed = raytraceSubblock(model); } + else { + subalpha = -1; + } if(!missed) { boolean done = true; for(int i = 0; i < shaderstate.length; i++) { @@ -329,9 +339,12 @@ public class IsoHDPerspective implements HDPerspective { mt_next_z = mt + (togo - Math.floor(togo)) * mdt_dz; } double mtend = Math.min(t_next_x, Math.min(t_next_y, t_next_z)); + subalpha = -1; while(mt < mtend) { try { - if(model[modscale*modscale*my + modscale*mz + mx] > 0) { + int blkalpha = model[modscale*modscale*my + modscale*mz + mx]; + if(blkalpha > 0) { + subalpha = blkalpha; return false; } } catch (ArrayIndexOutOfBoundsException aioobx) { /* We're outside the model, so miss */ @@ -451,11 +464,7 @@ public class IsoHDPerspective implements HDPerspective { block.y = inity; block.x += 1; } - MapTile[] result = tiles.toArray(new MapTile[tiles.size()]); - Log.info("processed update for " + loc); - for(MapTile mt : result) - Log.info("need to render " + mt); - return result; + return tiles.toArray(new MapTile[tiles.size()]); } @Override