mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 03:05:28 +01:00
More tweaks in DynmapBlockState
This commit is contained in:
parent
99d5416acb
commit
e4de854df6
@ -27,6 +27,7 @@ public class DynmapBlockState {
|
|||||||
public final int legacyBlockID;
|
public final int legacyBlockID;
|
||||||
// List of block states (only defined on base block), indexed by stateIndex (null if single state base block)
|
// List of block states (only defined on base block), indexed by stateIndex (null if single state base block)
|
||||||
private DynmapBlockState[] states;
|
private DynmapBlockState[] states;
|
||||||
|
private int stateLastIdx = 0;
|
||||||
// Full name for state (base name, or base name[state name])
|
// Full name for state (base name, or base name[state name])
|
||||||
private final String fullName;
|
private final String fullName;
|
||||||
// Material string
|
// Material string
|
||||||
@ -131,23 +132,20 @@ public class DynmapBlockState {
|
|||||||
blockName = blkname;
|
blockName = blkname;
|
||||||
stateName = (statename != null) ? statename : "";
|
stateName = (statename != null) ? statename : "";
|
||||||
|
|
||||||
if (stateIndex > 4096) {
|
|
||||||
System.out.println(String.format("DynmapBlockStste(%d, %s, %s, %s, %d)", stateidx, blkname, statename, material, legacyblkid));
|
|
||||||
Thread.dumpStack();
|
|
||||||
}
|
|
||||||
if (base != this) { // If we aren't base block state
|
if (base != this) { // If we aren't base block state
|
||||||
if (base.states == null) { // If no state list yet
|
if (base.states == null) { // If no state list yet
|
||||||
base.states = new DynmapBlockState[stateidx+1]; // Enough for us to fit
|
base.states = new DynmapBlockState[Math.max((stateidx+1)*3 / 2, 16)]; // Enough for us to fit
|
||||||
Arrays.fill(base.states, AIR);
|
Arrays.fill(base.states, AIR);
|
||||||
base.states[0] = base; // Add base state as index 0
|
base.states[0] = base; // Add base state as index 0
|
||||||
}
|
}
|
||||||
else if (base.states.length <= stateidx) { // Not enough room
|
else if (base.states.length <= stateidx) { // Not enough room
|
||||||
// Resize it
|
// Resize it
|
||||||
DynmapBlockState[] newstates = Arrays.copyOf(base.states, stateidx+1);
|
DynmapBlockState[] newstates = Arrays.copyOf(base.states, Math.max((stateidx+1)*3 / 2, 16));
|
||||||
Arrays.fill(newstates, base.states.length, newstates.length, AIR);
|
Arrays.fill(newstates, base.states.length, newstates.length, AIR);
|
||||||
base.states = newstates;
|
base.states = newstates;
|
||||||
}
|
}
|
||||||
base.states[stateidx] = this;
|
base.states[stateidx] = this;
|
||||||
|
base.stateLastIdx = Math.max(base.stateLastIdx, stateidx);
|
||||||
}
|
}
|
||||||
stateList = stateName.toLowerCase().split(",");
|
stateList = stateName.toLowerCase().split(",");
|
||||||
// If base block state, add to map
|
// If base block state, add to map
|
||||||
@ -205,7 +203,7 @@ public class DynmapBlockState {
|
|||||||
if (baseState.states == null) {
|
if (baseState.states == null) {
|
||||||
return (idx == 0) ? this : null;
|
return (idx == 0) ? this : null;
|
||||||
}
|
}
|
||||||
return ((idx >= 0) && (idx < baseState.states.length)) ? baseState.states[idx] : DynmapBlockState.AIR;
|
return ((idx >= 0) && (idx <= baseState.stateLastIdx)) ? baseState.states[idx] : DynmapBlockState.AIR;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Find base block state by block name
|
* Find base block state by block name
|
||||||
@ -339,12 +337,7 @@ public class DynmapBlockState {
|
|||||||
* @return state count
|
* @return state count
|
||||||
*/
|
*/
|
||||||
public final int getStateCount() {
|
public final int getStateCount() {
|
||||||
if (baseState.states == null) {
|
return baseState.stateLastIdx + 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return baseState.states.length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get nth state index within base block state
|
* Get nth state index within base block state
|
||||||
@ -356,7 +349,7 @@ public class DynmapBlockState {
|
|||||||
return (idx == 0) ? this : AIR;
|
return (idx == 0) ? this : AIR;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return (idx < baseState.states.length) ? baseState.states[idx] : AIR;
|
return (idx <= baseState.stateLastIdx) ? baseState.states[idx] : AIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user