fix block id world serialization
This commit is contained in:
parent
0f82ccb890
commit
264c7ffae3
4 changed files with 81 additions and 33 deletions
|
@ -36,6 +36,7 @@ import common.world.AWorldServer;
|
|||
public class BlockLeaves extends BlockLeavesBase
|
||||
{
|
||||
public static final PropertyBool DECAY = PropertyBool.create("decay");
|
||||
public static final PropertyBool BUSH = PropertyBool.create("bush");
|
||||
public static final List<BlockLeaves> LEAVES = Lists.newArrayList();
|
||||
private static final BlockLeaves[] MAPPING = new BlockLeaves[WoodType.values().length * LeavesType.values().length];
|
||||
|
||||
|
@ -53,7 +54,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
super(Material.LEAVES);
|
||||
this.type = type;
|
||||
this.subType = subType;
|
||||
this.setDefaultState(this.getBaseState().withProperty(DECAY, Boolean.valueOf(true)));
|
||||
this.setDefaultState(this.getBaseState().withProperty(DECAY, true).withProperty(BUSH, false));
|
||||
this.setTickRandomly();
|
||||
this.setTab(CheatTab.PLANTS);
|
||||
this.setHardness(0.2F);
|
||||
|
@ -87,7 +88,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
BlockPos blockpos = pos.add(j1, k1, l1);
|
||||
State iblockstate = worldIn.getState(blockpos);
|
||||
|
||||
if (iblockstate.getBlock().getMaterial() == Material.LEAVES && !((Boolean)iblockstate.getValue(DECAY)).booleanValue())
|
||||
if (iblockstate.getBlock().getMaterial() == Material.LEAVES && !iblockstate.getValue(BUSH) && !iblockstate.getValue(DECAY))
|
||||
{
|
||||
worldIn.setState(blockpos, iblockstate.withProperty(DECAY, Boolean.valueOf(true)), 4);
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
|
||||
{
|
||||
if(Vars.seasonLeaves && this.subType != worldIn.getLeavesGen(pos)) {
|
||||
worldIn.setState(pos, getLeavesBlock(this.type, worldIn.getLeavesGen(pos)).getState().withProperty(DECAY, state.getValue(DECAY)), 2);
|
||||
worldIn.setState(pos, getLeavesBlock(this.type, worldIn.getLeavesGen(pos)).getState().withProperty(DECAY, state.getValue(DECAY)).withProperty(BUSH, state.getValue(BUSH)), 2);
|
||||
return;
|
||||
}
|
||||
if(Vars.leafDry && worldIn.getTemperatureC(pos) >= 50.0f) {
|
||||
|
@ -109,7 +110,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
}
|
||||
// if (!worldIn.client)
|
||||
// {
|
||||
else if (Vars.leavesDecay && ((Boolean)state.getValue(DECAY)).booleanValue())
|
||||
else if (Vars.leavesDecay && !state.getValue(BUSH) && state.getValue(DECAY))
|
||||
{
|
||||
int i = 4;
|
||||
int j = i + 1;
|
||||
|
@ -305,7 +306,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
}
|
||||
|
||||
protected Property[] getProperties() {
|
||||
return new Property[] {DECAY};
|
||||
return new Property[] {DECAY, BUSH};
|
||||
}
|
||||
|
||||
public void harvestBlock(World worldIn, EntityNPC player, BlockPos pos, State state, TileEntity te) {
|
||||
|
@ -318,7 +319,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
}
|
||||
|
||||
public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer) {
|
||||
return this.getState().withProperty(DECAY, false);
|
||||
return this.getState().withProperty(DECAY, false).withProperty(BUSH, true);
|
||||
}
|
||||
|
||||
public Model getModel(ModelProvider provider, String name, State state) {
|
||||
|
@ -327,7 +328,7 @@ public class BlockLeaves extends BlockLeavesBase
|
|||
}
|
||||
|
||||
public Property<?>[] getIgnoredProperties() {
|
||||
return new Property[] {DECAY};
|
||||
return new Property[] {DECAY, BUSH};
|
||||
}
|
||||
|
||||
protected Item getItemToRegister() {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class BlockLog extends BlockRotatedPillar
|
|||
{
|
||||
State blk = worldIn.getState(bpos);
|
||||
|
||||
if (blk.getBlock().getMaterial() == Material.LEAVES && !((Boolean)blk.getValue(BlockLeaves.DECAY)).booleanValue())
|
||||
if (blk.getBlock().getMaterial() == Material.LEAVES && !blk.getValue(BlockLeaves.BUSH) && !blk.getValue(BlockLeaves.DECAY))
|
||||
{
|
||||
worldIn.setState(bpos, blk.withProperty(BlockLeaves.DECAY, Boolean.valueOf(true)), 4);
|
||||
}
|
||||
|
|
|
@ -142,6 +142,7 @@ import common.color.DyeColor;
|
|||
import common.item.CheatTab;
|
||||
import common.log.Log;
|
||||
import common.model.TextureAnimation;
|
||||
import common.properties.Property;
|
||||
import common.util.Util;
|
||||
import common.world.State;
|
||||
|
||||
|
@ -190,9 +191,30 @@ public abstract class BlockRegistry {
|
|||
State state = STATE_MAP.get(name);
|
||||
if(state != null)
|
||||
return state;
|
||||
int idx = name.indexOf(",");
|
||||
int idx = name.indexOf(',');
|
||||
Block block = BlockRegistry.byNameExact(idx >= 0 ? name.substring(0, idx) : name);
|
||||
return block != null ? block.getState() : def;
|
||||
if(block == null)
|
||||
return def;
|
||||
state = block.getState();
|
||||
if(idx < 0)
|
||||
return state;
|
||||
String[] tok = name.substring(idx + 1).split(",");
|
||||
for(String str : tok) {
|
||||
idx = str.indexOf('=');
|
||||
if(idx <= 0 || idx == str.length() - 1)
|
||||
continue;
|
||||
String key = str.substring(0, idx);
|
||||
String value = str.substring(idx + 1);
|
||||
for(Property prop : block.getSavedProperties()) {
|
||||
if(prop.getName().equals(key)) {
|
||||
for(Object obj : prop.getStates()) {
|
||||
if(prop.getName((Comparable)obj).equals(value))
|
||||
state = state.withProperty(prop, (Comparable)obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public static String getName(State state) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue