Add pistonmoved event handling, full rendering for piston and extension

This commit is contained in:
Mike Primm 2011-08-14 10:34:50 +08:00 committed by mikeprimm
parent 3da03c978b
commit c524c39901
5 changed files with 300 additions and 47 deletions

View File

@ -19,6 +19,8 @@ import java.util.Set;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -27,6 +29,8 @@ import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
@ -332,7 +336,8 @@ public class DynmapPlugin extends JavaPlugin {
private boolean onblockspread;
private boolean onleaves;
private boolean onburn;
private boolean onpiston;
public void registerEvents() {
final PluginManager pm = getServer().getPluginManager();
final MapManager mm = mapManager;
@ -345,97 +350,121 @@ public class DynmapPlugin extends JavaPlugin {
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onplace)
mm.touch(event.getBlockPlaced().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onbreak)
mm.touch(event.getBlock().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onleaves)
mm.touch(event.getBlock().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onburn)
mm.touch(event.getBlock().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onBlockForm(BlockFormEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onblockform)
mm.touch(event.getBlock().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onBlockFade(BlockFadeEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onblockfade)
mm.touch(event.getBlock().getLocation());
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
}
@Override
public void onBlockSpread(BlockSpreadEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
if(onblockspread)
mm.touch(event.getBlock().getLocation());
}
@Override
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
Block b = event.getBlock();
if(onpiston)
mm.touch(b.getLocation());
BlockFace dir = event.getDirection();
for(int i = 0; i < 2; i++) {
b = b.getRelative(dir, 1);
mm.sscache.invalidateSnapshot(b.getLocation());
if(onpiston)
mm.touch(b.getLocation());
}
}
@Override
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if(event.isCancelled())
return;
mm.sscache.invalidateSnapshot(event.getBlock().getLocation());
Block b = event.getBlock();
if(onpiston)
mm.touch(b.getLocation());
BlockFace dir = event.getDirection();
for(int i = 0; i < 1+event.getLength(); i++) {
b = b.getRelative(dir, 1);
mm.sscache.invalidateSnapshot(b.getLocation());
if(onpiston)
mm.touch(b.getLocation());
}
}
};
onplace = isTrigger("blockplaced");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_PLACE, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onbreak = isTrigger("blockbreak");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_BREAK, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
if(isTrigger("snowform")) Log.info("The 'snowform' trigger has been deprecated due to Bukkit changes - use 'blockformed'");
onleaves = isTrigger("leavesdecay");
pm.registerEvent(org.bukkit.event.Event.Type.LEAVES_DECAY, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onburn = isTrigger("blockburn");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_BURN, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onblockform = isTrigger("blockformed");
try {
Class.forName("org.bukkit.event.block.BlockFormEvent");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_FORM, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
} catch (ClassNotFoundException cnfx) {
if(onblockform)
Log.info("BLOCK_FORM event not supported by this version of CraftBukkit - event disabled");
}
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_FORM, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onblockfade = isTrigger("blockfaded");
try {
Class.forName("org.bukkit.event.block.BlockFadeEvent");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_FADE, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
} catch (ClassNotFoundException cnfx) {
if(onblockfade)
Log.info("BLOCK_FADE event not supported by this version of CraftBukkit - event disabled");
}
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_FADE, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onblockspread = isTrigger("blockspread");
try {
Class.forName("org.bukkit.event.block.BlockSpreadEvent");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_SPREAD, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
} catch (ClassNotFoundException cnfx) {
if(onblockspread)
Log.info("BLOCK_SPREAD event not supported by this version of CraftBukkit - event disabled");
}
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_SPREAD, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
onpiston = isTrigger("pistonmoved");
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_PISTON_EXTEND, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
pm.registerEvent(org.bukkit.event.Event.Type.BLOCK_PISTON_RETRACT, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this);
}
{
PlayerListener renderTrigger = new PlayerListener() {

View File

@ -73,6 +73,7 @@ public class TexturePack {
/* Special tile index values */
private static final int BLOCKINDEX_BLANK = -1;
private static final int BLOCKINDEX_GRASSMASK = 38;
private static final int BLOCKINDEX_PISTONSIDE = 108;
private static final int BLOCKINDEX_REDSTONE_NSEW_TONE = 164;
private static final int BLOCKINDEX_REDSTONE_EW_TONE = 165;
private static final int BLOCKINDEX_REDSTONE_NSEW = 180;
@ -81,7 +82,9 @@ public class TexturePack {
private static final int BLOCKINDEX_MOVINGWATER = 258;
private static final int BLOCKINDEX_STATIONARYLAVA = 259;
private static final int BLOCKINDEX_MOVINGLAVA = 260;
private static final int MAX_BLOCKINDEX = 260;
private static final int BLOCKINDEX_PISTONEXTSIDE = 261;
private static final int BLOCKINDEX_PISTONSIDE_EXT = 262;
private static final int MAX_BLOCKINDEX = 262;
private static final int BLOCKTABLELEN = MAX_BLOCKINDEX+1;
private static class LoadedImage {
@ -364,7 +367,7 @@ public class TexturePack {
/* Load terrain.png */
private void loadTerrainPNG(InputStream is) throws IOException {
int i;
int i, j;
/* Load image */
BufferedImage img = ImageIO.read(is);
if(img == null) { throw new FileNotFoundException(); }
@ -399,6 +402,27 @@ public class TexturePack {
terrain_argb[BLOCKINDEX_REDSTONE_EW][i] = tc.getARGB();
}
}
/* Build extended piston side texture - take top 1/4 of piston side, use to make piston extension */
terrain_argb[BLOCKINDEX_PISTONEXTSIDE] = new int[native_scale*native_scale];
System.arraycopy(terrain_argb[BLOCKINDEX_PISTONSIDE], 0, terrain_argb[BLOCKINDEX_PISTONEXTSIDE], 0,
native_scale * native_scale / 4);
for(i = 0; i < native_scale/4; i++) {
for(j = 0; j < (3*native_scale/4); j++) {
terrain_argb[BLOCKINDEX_PISTONEXTSIDE][native_scale*(native_scale/4 + j) + (3*native_scale/8 + i)] =
terrain_argb[BLOCKINDEX_PISTONSIDE][native_scale*i + j];
}
}
/* Build piston side while extended (cut off top 1/4, replace with rotated top for extension */
terrain_argb[BLOCKINDEX_PISTONSIDE_EXT] = new int[native_scale*native_scale];
System.arraycopy(terrain_argb[BLOCKINDEX_PISTONSIDE], native_scale*native_scale/4,
terrain_argb[BLOCKINDEX_PISTONSIDE_EXT], native_scale*native_scale/4,
3 * native_scale * native_scale / 4); /* Copy bottom 3/4 */
for(i = 0; i < native_scale/4; i++) {
for(j = 3*native_scale/4; j < native_scale; j++) {
terrain_argb[BLOCKINDEX_PISTONSIDE_EXT][native_scale*(j - 3*native_scale/4) + (3*native_scale/8 + i)] =
terrain_argb[BLOCKINDEX_PISTONSIDE][native_scale*i + j];
}
}
img.flush();
}

View File

@ -129,6 +129,7 @@ render-triggers:
- blockformed
- blockfaded
- blockspread
- pistonmoved
# The path where the tile-files are placed.
tilespath: web/tiles

View File

@ -1976,3 +1976,152 @@ rotate:id=93,data=0,rot=180
# Redstone repeater (off) facing north
block:id=93,id=94,data=3,data=7,data=11,data=15,scale=16
rotate:id=93,data=0,rot=270
# Sticky piston - extended facing down
# Piston - extended facing down
block:id=29,id=33,data=8,scale=8
layer:0,1
--------
--------
--------
---**---
---**---
--------
--------
--------
layer:2,3,4,5,6,7
********
********
********
********
********
********
********
********
# Sticky piston - extended facing up
block:id=29,id=33,data=9,scale=8
layer:0,1,2,3,4,5
********
********
********
********
********
********
********
********
layer:6,7
--------
--------
--------
---**---
---**---
--------
--------
--------
# Sticky piston - extended facing east
# Piston - extended facing east
block:id=29,id=33,data=10,scale=8
layer:0,1,2,5,6,7
******--
******--
******--
******--
******--
******--
******--
******--
layer:3,4
******--
******--
******--
********
********
******--
******--
******--
# Sticky piston - extended facing west
# Piston - extended facing west
block:id=29,id=33,data=11,scale=8
rotate:id=29,data=10,rot=180
# Sticky piston - extended facing north
# Piston - extended facing north
block:id=29,id=33,data=12,scale=8
rotate:id=29,data=10,rot=270
# Sticky piston - extended facing south
# Piston - extended facing south
block:id=29,id=33,data=13,scale=8
rotate:id=29,data=10,rot=90
# Sticky piston extension - extended facing down
# Piston extension - extended facing down
block:id=34,data=0,data=8,scale=8
layer:2,3,4,5,6,7
--------
--------
--------
---**---
---**---
--------
--------
--------
layer:0,1
********
********
********
********
********
********
********
********
# Sticky piston extension - extended facing up
# Piston extension - extended facing up
block:id=34,data=1,data=9,scale=8
layer:0,1,2,3,4,5
--------
--------
--------
---**---
---**---
--------
--------
--------
layer:6,7
********
********
********
********
********
********
********
********
# Sticky piston extension - extended facing east
# Piston extension - extended facing east
block:id=34,data=2,data=10,scale=8
layer:0,1,2,5,6,7
------**
------**
------**
------**
------**
------**
------**
------**
layer:3,4
------**
------**
------**
********
********
------**
------**
------**
# Sticky piston extension - extended facing west
# Piston extension - extended facing west
block:id=34,data=3,data=11,scale=8
rotate:id=34,data=2,rot=180
# Sticky piston extension - extended facing north
# Piston extension - extended facing north
block:id=34,data=4,data=12,scale=8
rotate:id=34,data=2,rot=270
# Sticky piston extension - extended facing west
# Piston extension - extended facing west
block:id=34,data=5,data=13,scale=8
rotate:id=34,data=2,rot=90

View File

@ -1,7 +1,7 @@
# Mapping of texture resources to block ID and data values
# block:id=<block-id>,data=<data-val|*>,top=<index>,bottom=<index>,north=<index>,south=<index>,east=<index>,west=<index>,allfaces=<index>,allsides=<index>
# <index>=0-255 (index of patch in terrain.png), -1=clear, 1xxx=biome tint from grasscolor.png,257=stationary water,258=moving water,
# 259=stationary lava,260=moving lava,2xxx=biome tint from foliagecolor.png,4xxx=rotate texture 90,
# 259=stationary lava,260=moving lava,261=extended piston side,262=piston side while extended,2xxx=biome tint from foliagecolor.png,4xxx=rotate texture 90,
# 5xxx=rotate texture 180, 6xxx=rotate texture 270, 7xxx=flip texture horizontally, 8xxx=shift down 1/2 block, 9=shift down 1/2,flip horiz,
# 10xxx=inclined-torch,11xxx=grass-side,12xxx=clear if same block
######
@ -116,17 +116,29 @@ block:id=28,data=0,data=4,data=5,top=4195,bottom=4195,allsides=4,transparency=TR
# Detector rail - incline to south
block:id=28,data=1,data=2,data=3,top=195,bottom=195,allsides=4,transparency=TRANSPARENT
# Sticky piston - facing down
block:id=29,data=0,data=8,top=109,bottom=106,allsides=5108
block:id=29,data=0,top=109,bottom=106,allsides=5108
# Sticky piston - facing up
block:id=29,data=1,data=9,top=106,bottom=109,allsides=108
block:id=29,data=1,top=106,bottom=109,allsides=108
# Sticky piston - facing east
block:id=29,data=2,data=10,east=106,west=109,top=6108,bottom=4108,north=4108,south=6108
block:id=29,data=2,east=106,west=109,top=6108,bottom=4108,north=4108,south=6108
# Sticky piston - facing west
block:id=29,data=3,data=11,west=106,east=109,top=4108,bottom=6108,north=6108,south=4108
block:id=29,data=3,west=106,east=109,top=4108,bottom=6108,north=6108,south=4108
# Sticky piston - facing north
block:id=29,data=4,data=12,north=106,south=109,top=108,bottom=5108,east=6108,west=4108
block:id=29,data=4,north=106,south=109,top=108,bottom=5108,east=6108,west=4108
# Sticky piston - facing south
block:id=29,data=5,data=13,north=109,south=106,top=5108,bottom=108,east=4108,west=6108
block:id=29,data=5,north=109,south=106,top=5108,bottom=108,east=4108,west=6108
# Sticky piston - extended facing down
block:id=29,data=8,top=109,bottom=110,allsides=5262
# Sticky piston - extended facing up
block:id=29,data=9,top=110,bottom=109,allsides=262
# Sticky piston - extended facing east
block:id=29,data=10,east=110,west=109,top=6262,bottom=4262,north=4262,south=6262
# Sticky piston - extended facing west
block:id=29,data=11,west=110,east=109,top=4262,bottom=6262,north=6262,south=4262
# Sticky piston - extended facing north
block:id=29,data=12,north=110,south=109,top=262,bottom=5262,east=6262,west=4262
# Sticky piston - extended facing south
block:id=29,data=13,north=109,south=110,top=5262,bottom=262,east=4262,west=6262
# Web
block:id=30,allfaces=11
# Dead shrub
@ -138,19 +150,53 @@ block:id=31,data=2,allsides=1056,top=1000,transparency=TRANSPARENT
# Dead shrub
block:id=32,allsides=55,top=20,transparency=TRANSPARENT
# Piston - facing down
block:id=33,data=0,data=8,top=109,bottom=107,allsides=5108
block:id=33,data=0,top=109,bottom=107,allsides=5108
# Piston - facing up
block:id=33,data=1,data=9,top=107,bottom=109,allsides=108
block:id=33,data=1,top=107,bottom=109,allsides=108
# Piston - facing east
block:id=33,data=2,data=10,east=107,west=109,top=6108,bottom=4108,north=4108,south=6108
block:id=33,data=2,east=107,west=109,top=6108,bottom=4108,north=4108,south=6108
# Piston - facing west
block:id=33,data=3,data=11,west=107,east=109,top=4108,bottom=6108,north=6108,south=4108
block:id=33,data=3,west=107,east=109,top=4108,bottom=6108,north=6108,south=4108
# Piston - facing north
block:id=33,data=4,data=12,north=107,south=109,top=108,bottom=5108,east=6108,west=4108
block:id=33,data=4,north=107,south=109,top=108,bottom=5108,east=6108,west=4108
# Piston - facing south
block:id=33,data=5,data=13,north=109,south=107,top=5108,bottom=108,east=4108,west=6108
# Piston extesions - skipped - render all as if closed
block:id=34
block:id=33,data=5,north=109,south=107,top=5108,bottom=108,east=4108,west=6108
# Piston - extended facing down
block:id=33,data=8,top=109,bottom=110,allsides=5262
# Piston - extended facing up
block:id=33,data=9,top=110,bottom=109,allsides=262
# Piston - extended facing east
block:id=33,data=10,east=110,west=109,top=6262,bottom=4262,north=4262,south=6262
# Piston - extended facing west
block:id=33,data=11,west=110,east=109,top=4262,bottom=6262,north=6262,south=4262
# Piston - extended facing north
block:id=33,data=12,north=110,south=109,top=262,bottom=5262,east=6262,west=4262
# Piston - extended facing south
block:id=33,data=13,north=109,south=110,top=5262,bottom=262,east=4262,west=6262
# Piston extension- facing down
block:id=34,data=0,top=107,bottom=107,allsides=5261
# Piston extension - facing up
block:id=34,data=1,top=107,bottom=107,allsides=261
# Piston extension - facing east
block:id=34,data=2,east=107,west=107,top=6261,bottom=4261,north=4261,south=6261
# Piston extension - facing west
block:id=34,data=3,west=107,east=107,top=4261,bottom=6261,north=6261,south=4261
# Piston extension - facing north
block:id=34,data=4,north=107,south=107,top=261,bottom=5261,east=6261,west=4261
# Piston extension - facing south
block:id=34,data=5,north=107,south=107,top=5261,bottom=261,east=4261,west=6261
# Sticky piston extension - facing down
block:id=34,data=8,top=107,bottom=106,allsides=5261
# Sticky piston extension - facing up
block:id=34,data=9,top=106,bottom=107,allsides=261
# Sticky piston extension - facing east
block:id=34,data=10,east=106,west=107,top=6261,bottom=4261,north=4261,south=6261
# Sticky piston extension - facing west
block:id=34,data=11,west=106,east=107,top=4261,bottom=6261,north=6261,south=4261
# Sticky piston extension - facing north
block:id=34,data=12,north=106,south=107,top=261,bottom=5261,east=6261,west=4261
# Sticky piston extension - facing south
block:id=34,data=13,north=107,south=106,top=5261,bottom=261,east=4261,west=6261
# Wool - white
block:id=35,data=0,allfaces=64
# Wool - orange
@ -257,8 +303,12 @@ block:id=54,data=9,topbottom=25,south=42,north=57,east=26,west=26
block:id=54,data=10,topbottom=25,south=26,north=26,east=42,west=57
# Chest - right side of double, facing north
block:id=54,data=11,topbottom=25,south=57,north=42,east=26,west=26
# Redstone wire (use processed tile - pretoned to active)
block:id=55,allfaces=180,transparency=TRANSPARENT
# Redstone wire (all but NS and EW)
block:id=55,data=0,data=3,data=4,data=5,data=6,data=7,data=8,data=9,data=10,allfaces=180,transparency=TRANSPARENT
# Redstone wire (EW)
block:id=55,data=2,allfaces=181,transparency=TRANSPARENT
# Redstone wire (NS)
block:id=55,data=1,allfaces=4181,transparency=TRANSPARENT
# Diamond ore
block:id=56,allfaces=50
# Diamond block