Skip to content

Commit

Permalink
better drawing order
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jun 21, 2015
1 parent d261269 commit 93a6a80
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
17 changes: 15 additions & 2 deletions python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
TERRAIN = set((AIR.id,WATER_FLOWING.id,WATER_STATIONARY.id,GRASS.id,DIRT.id,LAVA_FLOWING.id,
LAVA_STATIONARY.id,GRASS.id,DOUBLE_TALLGRASS.id,GRASS_TALL.id,BEDROCK.id,GRAVEL.id))

NEED_SUPPORT = set((SAPLING.id,WATER_FLOWING.id,LAVA_FLOWING.id,GRASS_TALL.id,34,35,FLOWER_YELLOW.id,
FLOWER_CYAN.id,MUSHROOM_BROWN.id,MUSHROOM_RED.id,TORCH.id,63,DOOR_WOOD.id,LADDER.id,
66,68,69,70,DOOR_IRON.id,72,75,76,77,SUGAR_CANE.id,93,94,96,104,105,106,108,111,
113,115,116,117,122,127,131,132,141,142,143,145,147,148,149,150,151,154,157,
167,CARPET.id,SUNFLOWER.id,176,177,178,183,184,185,186,187,188,189,190,191,192,
193,194,195,196,197))

def keyFunction(dict,pos):
return (dict[pos].id in NEED_SUPPORT,pos)

def box(x0,y0,z0,x1,y1,z1):
for x in range(x0,x1+1):
for y in range(y0,y1+1):
Expand Down Expand Up @@ -73,6 +83,7 @@ def scan(x0,y0,z0):

while len(newlyAdded)>0:
adding = set()
mc.postToChat("Added "+str(len(newlyAdded))+" blocks")
for q in newlyAdded:
for x,y,z in box(-1,-1,-1,1,1,1):
pos = (x+q[0],y+q[1],z+q[2])
Expand All @@ -92,7 +103,7 @@ def scan(x0,y0,z0):

offsets = {}

for pos in positions:
for pos in sorted(positions, key=lambda x : keyFunction(positions,x)):
offsets[(pos[0]-x0,pos[1]-y0,pos[2]-z0)] = positions[pos]
if flash:
setBlockWithData(pos,positions[pos])
Expand Down Expand Up @@ -220,8 +231,10 @@ def translate(base,x,y,z):
if curBlock == block:
del todo[pos]
saved[pos] = curBlock
for pos in sorted(todo):
# mc.setting("pause_drawing",1)
for pos in sorted(todo, key=lambda x : keyFunction(todo,x)):
setBlockWithData(pos,todo[pos])
# mc.setting("pause_drawing",0)
oldVehicle = newVehicle
oldPos = vehiclePos
oldRotation = vehicleRotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,12 @@ else if (cmd.equals(EVENTSCHATPOSTS)) {
}
else if (cmd.equals(WORLDSETTING)) {
String setting = scan.next();
if (setting.equals("world_immutable"))
if (setting.equals("world_immutable")) // across connections
eventHandler.setStopChanges(scan.nextInt() != 0);
else if (setting.equals("include_nbt_with_data"))
else if (setting.equals("include_nbt_with_data")) // connection-specific
includeNBTWithData = (scan.nextInt() != 0);
else if (setting.equals("pause_drawing")) // across connections
eventHandler.setPause(scan.nextInt() != 0);
// name_tags not supported
}
else if (cmd.equals(EVENTSSETTING)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
import net.minecraftforge.fml.relauncher.Side;

public class MCEventHandler {
List<SetBlockState> blockActionQueue = new ArrayList<SetBlockState>();
List<HitDescription> hits = new LinkedList<HitDescription>();
List<ChatDescription> chats = new LinkedList<ChatDescription>();
static final int MAX_HITS = 512;
private boolean stopChanges = false;
private boolean restrictToSword = true;
volatile boolean nightVision = false;
ServerChatEvent chatEvents;
static final int MAX_CHATS = 512;
int clientTickCount = 0;
private List<SetBlockState> blockActionQueue = new ArrayList<SetBlockState>();
private List<HitDescription> hits = new LinkedList<HitDescription>();
private List<ChatDescription> chats = new LinkedList<ChatDescription>();
private static final int MAX_HITS = 512;
private volatile boolean stopChanges = false;
private volatile boolean restrictToSword = true;
private volatile boolean nightVision = false;
private volatile boolean pause = false;
private ServerChatEvent chatEvents;
private static final int MAX_CHATS = 512;
private int clientTickCount = 0;

public void setStopChanges(boolean stopChanges) {
this.stopChanges = stopChanges;
Expand Down Expand Up @@ -179,15 +180,17 @@ public void onClientTick(TickEvent.ClientTickEvent event) {

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
World world = MinecraftServer.getServer().getEntityWorld();

synchronized(blockActionQueue) {
for (SetBlockState entry: blockActionQueue) {
if (! RaspberryJamMod.active)
break;
entry.execute(world);
if (!pause) {
World world = MinecraftServer.getServer().getEntityWorld();

synchronized(blockActionQueue) {
for (SetBlockState entry: blockActionQueue) {
if (! RaspberryJamMod.active)
break;
entry.execute(world);
}
blockActionQueue.clear();
}
blockActionQueue.clear();
}
}

Expand Down Expand Up @@ -302,4 +305,17 @@ public String getDescription() {
}


public void setPause(boolean b) {
pause = b;
}

public void setNightVision(boolean b) {
nightVision = b;
}

public boolean getNightVision() {
return nightVision;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void execute(ICommandSender sender, String[] args)
boolean nv;

if (args.length == 0) {
nv = ! eventHandler.nightVision;
nv = ! eventHandler.getNightVision();
}
else if (args[0].toLowerCase().equals("on")) {
nv = true;
Expand All @@ -75,7 +75,7 @@ else if (args[0].toLowerCase().equals("off")) {
throw new CommandException("Usage: /nightvision [on|off]");
}

eventHandler.nightVision = nv;
eventHandler.setNightVision(nv);
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
if (player != null) {
if (nv) {
Expand Down

0 comments on commit 93a6a80

Please sign in to comment.