more block data fixes

This commit is contained in:
Sen 2025-06-23 11:41:33 +02:00
parent eb815a8e21
commit ea76cecba3
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
24 changed files with 115 additions and 242 deletions

View file

@ -632,7 +632,6 @@ public class BlockPistonBase extends Block implements Directional
BlockPos blockpos2 = (BlockPos)list.get(k); BlockPos blockpos2 = (BlockPos)list.get(k);
State iblockstate = worldIn.getState(blockpos2); State iblockstate = worldIn.getState(blockpos2);
Block block1 = iblockstate.getBlock(); Block block1 = iblockstate.getBlock();
block1.getMetaFromState(iblockstate);
worldIn.setBlockToAir(blockpos2); worldIn.setBlockToAir(blockpos2);
blockpos2 = blockpos2.offset(enumfacing); blockpos2 = blockpos2.offset(enumfacing);
worldIn.setState(blockpos2, Blocks.piston_extension.getState().withProperty(FACING, direction), 4); worldIn.setState(blockpos2, Blocks.piston_extension.getState().withProperty(FACING, direction), 4);

View file

@ -222,39 +222,21 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
private long seed = 0L; private long seed = 0L;
public static void writeState(TagObject tag, String name, String dname, State state) {
if(state == null)
return;
tag.setString(name, BlockRegistry.getNameFromBlock(state.getBlock()));
if(state != state.getBlock().getState())
tag.setByte(dname, (byte)state.getBlock().getMetaFromState(state));
}
public static void writeState(TagObject tag, String name, State state) { public static void writeState(TagObject tag, String name, State state) {
writeState(tag, name, name + "Data", state); if(state != null)
tag.setString(name, state.getId());
} }
public static void writeState(TagObject tag, State state) { public static void writeState(TagObject tag, State state) {
writeState(tag, "Block", "Data", state); writeState(tag, "Block", state);
}
public static State readState(TagObject tag, String name, String dname, State def) {
if(!tag.hasString(name))
return def;
Block block = BlockRegistry.getRegisteredBlock(tag.getString(name));
if(tag.hasByte(dname)) {
byte data = tag.getByte(dname);
return data < 0 || data >= 16 ? block.getState() : block.getStateFromMeta(data);
}
return block.getState();
} }
public static State readState(TagObject tag, String name, State def) { public static State readState(TagObject tag, String name, State def) {
return readState(tag, name, name + "Data", def); return tag.hasString(name) ? State.getState(tag.getString(name), def) : def;
} }
public static State readState(TagObject tag, State def) { public static State readState(TagObject tag, State def) {
return readState(tag, "Block", "Data", def); return readState(tag, "Block", def);
} }
public Dimension(int id, String name) { public Dimension(int id, String name) {
@ -956,12 +938,9 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
this.caveFiller = readState(tag, "CaveFillBlock", Blocks.lava.getState()); this.caveFiller = readState(tag, "CaveFillBlock", Blocks.lava.getState());
if(tag.hasStringArray("Layers")) { if(tag.hasStringArray("Layers")) {
String[] list = tag.getStringArray("Layers"); String[] list = tag.getStringArray("Layers");
byte[] data = tag.hasByteArray("LayerData") ? tag.getByteArray("LayerData") : null;
data = data != null && data.length != list.length ? null : data;
this.layers = new State[list.length]; this.layers = new State[list.length];
for(int z = 0; z < this.layers.length; z++) { for(int z = 0; z < this.layers.length; z++) {
Block block = BlockRegistry.getRegisteredBlock(list[z]); this.layers[z] = State.getState(list[z], Blocks.air.getState());
this.layers[z] = data == null ? block.getState() : block.getStateFromMeta(data[z]);
} }
} }
else { else {
@ -1197,18 +1176,11 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
writeState(tag, "AltBlock2", this.alt2); writeState(tag, "AltBlock2", this.alt2);
writeState(tag, "CaveFillBlock", this.caveFiller); writeState(tag, "CaveFillBlock", this.caveFiller);
if(this.layers != null) { if(this.layers != null) {
boolean dataUsed = false;
String[] list = new String[this.layers.length]; String[] list = new String[this.layers.length];
byte[] data = new byte[this.layers.length];
for(int z = 0; z < this.layers.length; z++) { for(int z = 0; z < this.layers.length; z++) {
State state = this.layers[z]; list[z] = this.layers[z].getId();
list[z] = BlockRegistry.getNameFromBlock(state.getBlock());
data[z] = (byte)state.getBlock().getMetaFromState(state);
dataUsed |= state.getBlock().getState() != state;
} }
tag.setStringArray("Layers", list); tag.setStringArray("Layers", list);
if(dataUsed)
tag.setByteArray("LayerData", data);
} }
if(this.addBiomes != null) { if(this.addBiomes != null) {
String[] list = new String[this.addBiomes.length]; String[] list = new String[this.addBiomes.length];

View file

@ -1061,7 +1061,7 @@ public abstract class Entity
if (block.getMaterial().isColdLiquid()) if (block.getMaterial().isColdLiquid())
{ {
float f = BlockLiquid.getLiquidHeightPercent(iblockstate.getBlock().getMetaFromState(iblockstate)) - 0.11111111F; float f = BlockLiquid.getLiquidHeightPercent(iblockstate.getValue(BlockLiquid.LEVEL)) - 0.11111111F;
float f1 = (float)(blockpos.getY() + 1) - f; float f1 = (float)(blockpos.getY() + 1) - f;
boolean flag = d0 < (double)f1; boolean flag = d0 < (double)f1;
return !flag && this.isPlayer() ? false : flag; return !flag && this.isPlayer() ? false : flag;

View file

@ -1,13 +1,11 @@
package common.entity.item; package common.entity.item;
import common.block.Block;
import common.block.tech.BlockRailBase; import common.block.tech.BlockRailBase;
import common.block.tech.BlockRailPowered; import common.block.tech.BlockRailPowered;
import common.entity.DamageSource; import common.entity.DamageSource;
import common.entity.Entity; import common.entity.Entity;
import common.entity.EntityType; import common.entity.EntityType;
import common.entity.types.EntityLiving; import common.entity.types.EntityLiving;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.init.Items; import common.init.Items;
import common.item.Item; import common.item.Item;
@ -89,9 +87,6 @@ public abstract class EntityCart extends Entity implements IWorldNameable
this.dataWatcher.addObject(17, 0); this.dataWatcher.addObject(17, 0);
this.dataWatcher.addObject(18, 1); this.dataWatcher.addObject(18, 1);
this.dataWatcher.addObject(19, 0); this.dataWatcher.addObject(19, 0);
this.dataWatcher.addObject(20, 0);
this.dataWatcher.addObject(21, 6);
this.dataWatcher.addObject(22, Byte.valueOf((byte)0));
} }
/** /**
@ -755,24 +750,6 @@ public abstract class EntityCart extends Entity implements IWorldNameable
*/ */
protected void readEntity(TagObject tagCompund) protected void readEntity(TagObject tagCompund)
{ {
if (tagCompund.getBool("CustomDisplayTile"))
{
int i = tagCompund.getInt("DisplayData");
if (tagCompund.hasString("DisplayTile"))
{
Block block = BlockRegistry.getRegisteredBlock(tagCompund.getString("DisplayTile"));
this.func_174899_a(block.getStateFromMeta(i));
}
else
{
this.func_174899_a(Blocks.air.getState());
}
this.setDisplayTileOffset(tagCompund.getInt("DisplayOffset"));
}
if (tagCompund.hasString("CustomName") && tagCompund.getString("CustomName").length() > 0) if (tagCompund.hasString("CustomName") && tagCompund.getString("CustomName").length() > 0)
{ {
this.entityName = tagCompund.getString("CustomName"); this.entityName = tagCompund.getString("CustomName");
@ -784,16 +761,6 @@ public abstract class EntityCart extends Entity implements IWorldNameable
*/ */
protected void writeEntity(TagObject tagCompound) protected void writeEntity(TagObject tagCompound)
{ {
if (this.hasDisplayTile())
{
tagCompound.setBool("CustomDisplayTile", true);
State iblockstate = this.getDisplayTile();
String resourcelocation = BlockRegistry.getNameFromBlock(iblockstate.getBlock());
tagCompound.setString("DisplayTile", resourcelocation == null ? "" : resourcelocation);
tagCompound.setInt("DisplayData", iblockstate.getBlock().getMetaFromState(iblockstate));
tagCompound.setInt("DisplayOffset", this.getDisplayTileOffset());
}
if (this.entityName != null && this.entityName.length() > 0) if (this.entityName != null && this.entityName.length() > 0)
{ {
tagCompound.setString("CustomName", this.entityName); tagCompound.setString("CustomName", this.entityName);
@ -972,47 +939,15 @@ public abstract class EntityCart extends Entity implements IWorldNameable
public abstract EntityCart.EnumMinecartType getMinecartType(); public abstract EntityCart.EnumMinecartType getMinecartType();
public State getDisplayTile() public State getDisplayTile()
{
return !this.hasDisplayTile() ? this.getDefaultDisplayTile() : BlockRegistry.getStateById(this.getDataWatcher().getWatchableObjectInt(20));
}
public State getDefaultDisplayTile()
{ {
return Blocks.air.getState(); return Blocks.air.getState();
} }
public int getDisplayTileOffset() public int getDisplayTileOffset()
{
return !this.hasDisplayTile() ? this.getDefaultDisplayTileOffset() : this.getDataWatcher().getWatchableObjectInt(21);
}
public int getDefaultDisplayTileOffset()
{ {
return 6; return 6;
} }
public void func_174899_a(State p_174899_1_)
{
this.getDataWatcher().updateObject(20, Integer.valueOf(BlockRegistry.getStateId(p_174899_1_)));
this.setHasDisplayTile(true);
}
public void setDisplayTileOffset(int p_94086_1_)
{
this.getDataWatcher().updateObject(21, Integer.valueOf(p_94086_1_));
this.setHasDisplayTile(true);
}
public boolean hasDisplayTile()
{
return this.getDataWatcher().getWatchableObjectByte(22) == 1;
}
public void setHasDisplayTile(boolean p_94096_1_)
{
this.getDataWatcher().updateObject(22, Byte.valueOf((byte)(p_94096_1_ ? 1 : 0)));
}
/** /**
* Sets the custom name tag for this entity * Sets the custom name tag for this entity
*/ */

View file

@ -48,12 +48,12 @@ public class EntityChestCart extends EntityCartContainer
return EntityCart.EnumMinecartType.CHEST; return EntityCart.EnumMinecartType.CHEST;
} }
public State getDefaultDisplayTile() public State getDisplayTile()
{ {
return Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.NORTH); return Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.NORTH);
} }
public int getDefaultDisplayTileOffset() public int getDisplayTileOffset()
{ {
return 8; return 8;
} }

View file

@ -203,10 +203,7 @@ public class EntityFalling extends Entity implements IObjectData
*/ */
protected void writeEntity(TagObject tagCompound) protected void writeEntity(TagObject tagCompound)
{ {
Block block = this.fallTile != null ? this.fallTile.getBlock() : Blocks.air; tagCompound.setString("Block", (this.fallTile != null ? this.fallTile : Blocks.air.getState()).getId());
String resourcelocation = BlockRegistry.getNameFromBlock(block);
tagCompound.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
tagCompound.setByte("Data", (byte)block.getMetaFromState(this.fallTile));
tagCompound.setByte("Time", (byte)this.fallTime); tagCompound.setByte("Time", (byte)this.fallTime);
tagCompound.setBool("DropItem", this.shouldDropItem); tagCompound.setBool("DropItem", this.shouldDropItem);
tagCompound.setBool("HurtEntities", this.hurtEntities); tagCompound.setBool("HurtEntities", this.hurtEntities);
@ -219,11 +216,9 @@ public class EntityFalling extends Entity implements IObjectData
*/ */
protected void readEntity(TagObject tagCompund) protected void readEntity(TagObject tagCompund)
{ {
int i = tagCompund.getByte("Data") & 255;
if (tagCompund.hasString("Block")) if (tagCompund.hasString("Block"))
{ {
this.fallTile = BlockRegistry.getRegisteredBlock(tagCompund.getString("Block")).getStateFromMeta(i); this.fallTile = State.getState(tagCompund.getString("Block"), Blocks.sand.getState());
} }
else else
{ {

View file

@ -40,12 +40,12 @@ public class EntityHopperCart extends EntityCartContainer implements IHopper
return EntityCart.EnumMinecartType.HOPPER; return EntityCart.EnumMinecartType.HOPPER;
} }
public State getDefaultDisplayTile() public State getDisplayTile()
{ {
return Blocks.hopper.getState(); return Blocks.hopper.getState();
} }
public int getDefaultDisplayTileOffset() public int getDisplayTileOffset()
{ {
return 1; return 1;
} }

View file

@ -35,7 +35,7 @@ public class EntityTntCart extends EntityCart
return EntityCart.EnumMinecartType.TNT; return EntityCart.EnumMinecartType.TNT;
} }
public State getDefaultDisplayTile() public State getDisplayTile()
{ {
return Blocks.tnt.getState(); return Blocks.tnt.getState();
} }

View file

@ -11,7 +11,6 @@ import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving; import common.entity.types.EntityLiving;
import common.entity.types.IObjectData; import common.entity.types.IObjectData;
import common.entity.types.IProjectile; import common.entity.types.IProjectile;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.init.Items; import common.init.Items;
import common.init.SoundEvent; import common.init.SoundEvent;
@ -32,8 +31,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
private int xTile = -1; private int xTile = -1;
private int yTile = -1; private int yTile = -1;
private int zTile = -1; private int zTile = -1;
private Block inTile; private State inTile;
private int inData;
private boolean inGround; private boolean inGround;
/** 1 if the player can pick up the arrow */ /** 1 if the player can pick up the arrow */
@ -219,9 +217,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
if (this.inGround) if (this.inGround)
{ {
int j = block.getMetaFromState(iblockstate); if (iblockstate == this.inTile)
if (block == this.inTile && j == this.inData)
{ {
++this.ticksInGround; ++this.ticksInGround;
@ -383,8 +379,7 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
this.yTile = blockpos1.getY(); this.yTile = blockpos1.getY();
this.zTile = blockpos1.getZ(); this.zTile = blockpos1.getZ();
State iblockstate1 = this.worldObj.getState(blockpos1); State iblockstate1 = this.worldObj.getState(blockpos1);
this.inTile = iblockstate1.getBlock(); this.inTile = iblockstate1;
this.inData = this.inTile.getMetaFromState(iblockstate1);
this.motionX = (double)((float)(movingobjectposition.vec.xCoord - this.posX)); this.motionX = (double)((float)(movingobjectposition.vec.xCoord - this.posX));
this.motionY = (double)((float)(movingobjectposition.vec.yCoord - this.posY)); this.motionY = (double)((float)(movingobjectposition.vec.yCoord - this.posY));
this.motionZ = (double)((float)(movingobjectposition.vec.zCoord - this.posZ)); this.motionZ = (double)((float)(movingobjectposition.vec.zCoord - this.posZ));
@ -397,9 +392,9 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
this.arrowShake = 7; this.arrowShake = 7;
this.setIsCritical(false); this.setIsCritical(false);
if (this.inTile != Blocks.air) if (this.inTile.getBlock() != Blocks.air)
{ {
this.inTile.onEntityCollidedWithBlock(this.worldObj, blockpos1, iblockstate1, this); this.inTile.getBlock().onEntityCollidedWithBlock(this.worldObj, blockpos1, iblockstate1, this);
} }
} }
} }
@ -478,10 +473,8 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
tagCompound.setShort("zTile", (short)this.zTile); tagCompound.setShort("zTile", (short)this.zTile);
tagCompound.setShort("life", (short)this.ticksInGround); tagCompound.setShort("life", (short)this.ticksInGround);
if(this.inTile != null) { if(this.inTile != null) {
String id = BlockRegistry.getNameFromBlock(this.inTile); tagCompound.setString("inTile", this.inTile.getId());
tagCompound.setString("inTile", id == null ? "" : id.toString());
} }
tagCompound.setByte("inData", (byte)this.inData);
tagCompound.setByte("shake", (byte)this.arrowShake); tagCompound.setByte("shake", (byte)this.arrowShake);
tagCompound.setBool("inGround", this.inGround); tagCompound.setBool("inGround", this.inGround);
tagCompound.setByte("pickup", (byte)this.canBePickedUp); tagCompound.setByte("pickup", (byte)this.canBePickedUp);
@ -500,14 +493,13 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
if (tagCompund.hasString("inTile")) if (tagCompund.hasString("inTile"))
{ {
this.inTile = BlockRegistry.getRegisteredBlock(tagCompund.getString("inTile")); this.inTile = State.getState(tagCompund.getString("inTile"), null);
} }
else else
{ {
this.inTile = null; this.inTile = null;
} }
this.inData = tagCompund.getByte("inData") & 255;
this.arrowShake = tagCompund.getByte("shake") & 255; this.arrowShake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getBool("inGround"); this.inGround = tagCompund.getBool("inGround");

View file

@ -132,14 +132,12 @@ import common.color.DyeColor;
import common.item.CheatTab; import common.item.CheatTab;
import common.log.Log; import common.log.Log;
import common.model.TextureAnimation; import common.model.TextureAnimation;
import common.util.IdMap;
import common.util.Mapping; import common.util.Mapping;
import common.util.Util; import common.util.Util;
import common.world.State; import common.world.State;
public abstract class BlockRegistry { public abstract class BlockRegistry {
public static final Mapping<Block> REGISTRY = new Mapping("air"); public static final Mapping<Block> REGISTRY = new Mapping("air");
public static final IdMap<State> STATEMAP = new IdMap();
private static int nextBlockId = 0; private static int nextBlockId = 0;
@ -147,56 +145,29 @@ public abstract class BlockRegistry {
return REGISTRY.getId(block); return REGISTRY.getId(block);
} }
public static Block getBlockById(int id) {
return REGISTRY.byId(id);
}
public static String getNameFromBlock(Block block) { public static String getNameFromBlock(Block block) {
return REGISTRY.getName(block); return REGISTRY.getName(block);
} }
public static Block getRegisteredBlock(String name) {
return REGISTRY.byName(name);
}
public static int getStateId(State state) { public static int getStateId(State state) {
Block block = state.getBlock(); Block block = state.getBlock();
return getIdFromBlock(block) + (block.getMetaFromState(state) << 12); return getIdFromBlock(block) + (block.getMetaFromState(state) << 12);
} }
public static Block getBlockById(int id) {
return REGISTRY.byId(id);
}
public static State getStateById(int id) { public static State getStateById(int id) {
int i = id & 4095; int i = id & 4095;
int j = id >> 12 & 15; int j = id >> 12 & 15;
return getBlockById(i).getStateFromMeta(j); return getBlockById(i).getStateFromMeta(j);
} }
public static State getFromIdName(String name, State def) {
if(name == null)
return def;
String[] tok = name.split(":");
if(tok.length < 1 || tok.length > 2)
return def;
Block block = REGISTRY.byNameExact(tok[0]);
if(block == null)
return def;
byte data;
if(tok.length == 2) {
try {
int i = Integer.parseUnsignedInt(tok[1]);
if(i >= 16)
return def;
data = (byte)i;
}
catch(NumberFormatException e) {
return def;
}
}
else {
data = (byte)block.getMetaFromState(block.getState());
}
return block.getStateFromMeta(data);
}
public static Block getRegisteredBlock(String name) {
return REGISTRY.byName(name);
}
private static void registerBlock(String name, Block block) { private static void registerBlock(String name, Block block) {
REGISTRY.register(nextBlockId++, name, block); REGISTRY.register(nextBlockId++, name, block);
} }
@ -651,7 +622,6 @@ public abstract class BlockRegistry {
for(Block block : REGISTRY) { for(Block block : REGISTRY) {
for(State state : block.getValidStates()) { for(State state : block.getValidStates()) {
STATEMAP.put(state, REGISTRY.getId(block) << 4 | block.getMetaFromState(state));
state.buildSaved(); state.buildSaved();
} }
} }

View file

@ -93,25 +93,16 @@ public abstract class ItemRegistry {
return item == null ? 0 : REGISTRY.getId(item); return item == null ? 0 : REGISTRY.getId(item);
} }
public static String getNameFromItem(Item item) {
return REGISTRY.getName(item);
}
public static Item getItemById(int id) { public static Item getItemById(int id) {
return REGISTRY.byId(id); return REGISTRY.byId(id);
} }
public static Item getRegisteredItem(String name) { public static String getNameFromItem(Item item) {
return REGISTRY.byName(name); return REGISTRY.getName(item);
} }
public static ItemStack getFromIdName(String name, ItemStack def) { public static Item getRegisteredItem(String name) {
if(name == null) return REGISTRY.byName(name);
return def;
Item item = REGISTRY.byName(name);
if(item == null)
return def;
return new ItemStack(item);
} }
private static void registerItem(String name, Item item) { private static void registerItem(String name, Item item) {

View file

@ -1,6 +1,7 @@
package common.item; package common.item;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -67,6 +68,17 @@ public final class ItemStack
return itemstack.getItem() != null ? itemstack : null; return itemstack.getItem() != null ? itemstack : null;
} }
public static ItemStack getStack(String name, ItemStack def) {
if(name == null)
return def;
Item item = ItemRegistry.REGISTRY.byNameExact(name);
return item == null ? def : new ItemStack(item);
}
public static Collection<String> getKeys() {
return ItemRegistry.REGISTRY.getKeys();
}
private ItemStack() private ItemStack()
{ {
} }

View file

@ -2,7 +2,6 @@ package common.packet;
import java.io.IOException; import java.io.IOException;
import common.init.BlockRegistry;
import common.network.IClientPlayer; import common.network.IClientPlayer;
import common.network.Packet; import common.network.Packet;
import common.network.PacketBuffer; import common.network.PacketBuffer;
@ -31,7 +30,7 @@ public class SPacketBlockChange implements Packet<IClientPlayer>
public void readPacketData(PacketBuffer buf) throws IOException public void readPacketData(PacketBuffer buf) throws IOException
{ {
this.blockPosition = buf.readBlockPos(); this.blockPosition = buf.readBlockPos();
this.blockState = (State)BlockRegistry.STATEMAP.getByValue(buf.readVarInt()); this.blockState = (State)State.ID_MAP.getByValue(buf.readVarInt());
} }
/** /**
@ -40,7 +39,7 @@ public class SPacketBlockChange implements Packet<IClientPlayer>
public void writePacketData(PacketBuffer buf) throws IOException public void writePacketData(PacketBuffer buf) throws IOException
{ {
buf.writeBlockPos(this.blockPosition); buf.writeBlockPos(this.blockPosition);
buf.writeVarInt(BlockRegistry.STATEMAP.get(this.blockState)); buf.writeVarInt(State.ID_MAP.get(this.blockState));
} }
/** /**

View file

@ -2,7 +2,6 @@ package common.packet;
import java.io.IOException; import java.io.IOException;
import common.init.BlockRegistry;
import common.network.IClientPlayer; import common.network.IClientPlayer;
import common.network.Packet; import common.network.Packet;
import common.network.PacketBuffer; import common.network.PacketBuffer;
@ -39,7 +38,7 @@ public class SPacketMultiBlockChange implements Packet<IClientPlayer>
for (int i = 0; i < this.changedBlocks.length; ++i) for (int i = 0; i < this.changedBlocks.length; ++i)
{ {
this.changedBlocks[i] = new SPacketMultiBlockChange.BlockUpdateData(buf.readLong(), (State)BlockRegistry.STATEMAP.getByValue(buf.readVarInt())); this.changedBlocks[i] = new SPacketMultiBlockChange.BlockUpdateData(buf.readLong(), (State)State.ID_MAP.getByValue(buf.readVarInt()));
} }
} }
@ -55,7 +54,7 @@ public class SPacketMultiBlockChange implements Packet<IClientPlayer>
for (SPacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : this.changedBlocks) for (SPacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : this.changedBlocks)
{ {
buf.writeLong(s22packetmultiblockchange$blockupdatedata.getRawPos()); buf.writeLong(s22packetmultiblockchange$blockupdatedata.getRawPos());
buf.writeVarInt(BlockRegistry.STATEMAP.get(s22packetmultiblockchange$blockupdatedata.getBlockState())); buf.writeVarInt(State.ID_MAP.get(s22packetmultiblockchange$blockupdatedata.getBlockState()));
} }
} }

View file

@ -4,7 +4,6 @@ import java.util.List;
import common.collect.Lists; import common.collect.Lists;
import common.entity.Entity; import common.entity.Entity;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BoundingBox; import common.util.BoundingBox;
@ -201,7 +200,7 @@ public class TileEntityPiston extends TileEntity implements ITickable
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
this.pistonState = BlockRegistry.getRegisteredBlock(compound.getString("blockId")).getStateFromMeta(compound.getInt("blockData")); this.pistonState = State.getState(compound.getString("block"), Blocks.air.getState());
this.pistonFacing = Facing.getFront(compound.getInt("facing")); this.pistonFacing = Facing.getFront(compound.getInt("facing"));
this.lastProgress = this.progress = compound.getFloat("progress"); this.lastProgress = this.progress = compound.getFloat("progress");
this.extending = compound.getBool("extending"); this.extending = compound.getBool("extending");
@ -210,8 +209,7 @@ public class TileEntityPiston extends TileEntity implements ITickable
public void writeTags(TagObject compound) public void writeTags(TagObject compound)
{ {
super.writeTags(compound); super.writeTags(compound);
compound.setString("blockId", BlockRegistry.getNameFromBlock(this.pistonState.getBlock())); compound.setString("block", this.pistonState.getId());
compound.setInt("blockData", this.pistonState.getBlock().getMetaFromState(this.pistonState));
compound.setInt("facing", this.pistonFacing.getIndex()); compound.setInt("facing", this.pistonFacing.getIndex());
compound.setFloat("progress", this.lastProgress); compound.setFloat("progress", this.lastProgress);
compound.setBool("extending", this.extending); compound.setBool("extending", this.extending);

View file

@ -3,7 +3,6 @@ package common.world;
import java.util.Arrays; import java.util.Arrays;
import common.block.Block; import common.block.Block;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.util.NibbleArray; import common.util.NibbleArray;
@ -22,14 +21,14 @@ public class BlockArray {
if(sky) if(sky)
this.skylight = new NibbleArray(); this.skylight = new NibbleArray();
if(filler != null && filler.getBlock() != Blocks.air) { if(filler != null && filler.getBlock() != Blocks.air) {
Arrays.fill(this.data, (char)BlockRegistry.STATEMAP.get(filler)); Arrays.fill(this.data, (char)State.ID_MAP.get(filler));
this.blocks = this.data.length; this.blocks = this.data.length;
this.ticked = filler.getBlock().getTickRandomly() ? this.data.length : 0; this.ticked = filler.getBlock().getTickRandomly() ? this.data.length : 0;
} }
} }
public State get(int x, int y, int z) { public State get(int x, int y, int z) {
State iblockstate = BlockRegistry.STATEMAP.getByValue(this.data[y << 8 | z << 4 | x]); State iblockstate = State.ID_MAP.getByValue(this.data[y << 8 | z << 4 | x]);
return iblockstate != null ? iblockstate : Blocks.air.getState(); return iblockstate != null ? iblockstate : Blocks.air.getState();
} }
@ -47,18 +46,13 @@ public class BlockArray {
if(block.getTickRandomly()) if(block.getTickRandomly())
++this.ticked; ++this.ticked;
} }
this.data[y << 8 | z << 4 | x] = (char)BlockRegistry.STATEMAP.get(state); this.data[y << 8 | z << 4 | x] = (char)State.ID_MAP.get(state);
} }
public Block getBlock(int x, int y, int z) { public Block getBlock(int x, int y, int z) {
return this.get(x, y, z).getBlock(); return this.get(x, y, z).getBlock();
} }
public int getMeta(int x, int y, int z) {
State state = this.get(x, y, z);
return state.getBlock().getMetaFromState(state);
}
public boolean isEmpty() { public boolean isEmpty() {
return this.blocks == 0; return this.blocks == 0;
} }

View file

@ -19,9 +19,9 @@ import common.collect.StandardTable;
import common.collect.Table; import common.collect.Table;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.properties.Property; import common.properties.Property;
import common.util.IdMap;
public class State { public class State {
// private static final Joiner COMMA_JOINER = Joiner.on(',');
private static final Function<Entry<Property, Comparable>, String> MAP_ENTRY_TO_STRING = private static final Function<Entry<Property, Comparable>, String> MAP_ENTRY_TO_STRING =
new Function<Entry<Property, Comparable>, String>() { new Function<Entry<Property, Comparable>, String>() {
public String apply(Entry<Property, Comparable> entry) { public String apply(Entry<Property, Comparable> entry) {
@ -34,6 +34,8 @@ public class State {
} }
} }
}; };
private static final Map<String, State> NAME_MAP = Maps.newLinkedHashMap();
public static final IdMap<State> ID_MAP = new IdMap();
private final Block block; private final Block block;
private final ImmutableMap<Property, Comparable> properties; private final ImmutableMap<Property, Comparable> properties;
@ -76,6 +78,25 @@ public class State {
return sb.toString(); return sb.toString();
} }
public static State getState(String name, State def) {
if(name == null)
return def;
State state = NAME_MAP.get(name);
if(state != null)
return state;
int idx = name.indexOf(",");
if(idx >= 0) {
Block block = BlockRegistry.REGISTRY.byNameExact(name.substring(0, idx));
if(block != null)
return block.getState();
}
return def;
}
public static Collection<String> getKeys() {
return NAME_MAP.keySet();
}
public State(Block block, ImmutableMap<Property, Comparable> properties) { public State(Block block, ImmutableMap<Property, Comparable> properties) {
this.block = block; this.block = block;
this.properties = properties; this.properties = properties;
@ -184,7 +205,8 @@ public class State {
public void buildSaved() { public void buildSaved() {
if(this.saved != null) if(this.saved != null)
throw new IllegalStateException(); throw new IllegalStateException();
ID_MAP.put(this, BlockRegistry.getIdFromBlock(this.block) << 4 | this.block.getMetaFromState(this));
this.saved = ImmutableSet.copyOf(getSavedProperties(this.block)); this.saved = ImmutableSet.copyOf(getSavedProperties(this.block));
this.id = filterProperties(this, this.saved); NAME_MAP.put(this.id = filterProperties(this, this.saved), this);
} }
} }

View file

@ -1,7 +1,6 @@
package server.command.commands; package server.command.commands;
import java.util.Collection; import java.util.Collection;
import common.init.BlockRegistry;
import common.tags.TagObject; import common.tags.TagObject;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.util.BlockPos; import common.util.BlockPos;
@ -19,7 +18,7 @@ public class CommandBlock extends Command {
this.addString("block", false, new StringCompleter() { this.addString("block", false, new StringCompleter() {
public Collection<String> complete(CommandEnvironment env) { public Collection<String> complete(CommandEnvironment env) {
return BlockRegistry.REGISTRY.getKeys(); return State.getKeys();
} }
}); });
this.addBlockPos("position", true); this.addBlockPos("position", true);
@ -30,7 +29,7 @@ public class CommandBlock extends Command {
} }
public Object exec(CommandEnvironment env, Executor exec, String block, BlockPos position, WorldServer world, TagObject tag) { public Object exec(CommandEnvironment env, Executor exec, String block, BlockPos position, WorldServer world, TagObject tag) {
State state = BlockRegistry.getFromIdName(block, null); State state = State.getState(block, null);
if(state == null) if(state == null)
throw new RunException("Block '%s' existiert nicht", block); throw new RunException("Block '%s' existiert nicht", block);
boolean success = world.setState(position, state); boolean success = world.setState(position, state);

View file

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.init.ItemRegistry;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import server.command.Command; import server.command.Command;
@ -20,7 +19,7 @@ public class CommandItem extends Command {
this.addString("item", false, new StringCompleter() { this.addString("item", false, new StringCompleter() {
public Collection<String> complete(CommandEnvironment env) { public Collection<String> complete(CommandEnvironment env) {
return ItemRegistry.REGISTRY.getKeys(); return ItemStack.getKeys();
} }
}); });
this.setParamsOptional(); this.setParamsOptional();
@ -31,7 +30,7 @@ public class CommandItem extends Command {
} }
public Object exec(CommandEnvironment env, Executor exec, String item, int amount, TagObject tag, List<EntityNPC> players) { public Object exec(CommandEnvironment env, Executor exec, String item, int amount, TagObject tag, List<EntityNPC> players) {
ItemStack stack = ItemRegistry.getFromIdName(item, null); ItemStack stack = ItemStack.getStack(item, null);
if(stack == null) if(stack == null)
throw new RunException("Gegenstand '%s' existiert nicht", item); throw new RunException("Gegenstand '%s' existiert nicht", item);
stack.setTagCompound(tag); stack.setTagCompound(tag);

View file

@ -5,7 +5,6 @@ import java.util.Set;
import common.biome.Biome; import common.biome.Biome;
import common.block.Block; import common.block.Block;
import common.entity.Entity; import common.entity.Entity;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.log.Log; import common.log.Log;
import common.rng.Random; import common.rng.Random;
@ -31,7 +30,7 @@ public class ChunkServer extends Chunk {
for(int bx = 0; bx < 16; ++bx) { for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) { for(int bz = 0; bz < 16; ++bz) {
for(int by = 0; by < height; ++by) { for(int by = 0; by < height; ++by) {
State state = BlockRegistry.STATEMAP.getByValue(data[bx << 4 | bz | by << 8]); State state = State.ID_MAP.getByValue(data[bx << 4 | bz | by << 8]);
if(state != null && state.getBlock() != Blocks.air) { if(state != null && state.getBlock() != Blocks.air) {
int y = by >> 4; int y = by >> 4;
BlockArray arr = this.getArray(y); BlockArray arr = this.getArray(y);

View file

@ -51,7 +51,6 @@ import common.entity.animal.EntitySquid;
import common.entity.animal.EntityWolf; import common.entity.animal.EntityWolf;
import common.entity.item.EntityBoat; import common.entity.item.EntityBoat;
import common.entity.item.EntityMinecart; import common.entity.item.EntityMinecart;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.init.EntityRegistry; import common.init.EntityRegistry;
import common.init.TileRegistry; import common.init.TileRegistry;
@ -272,7 +271,7 @@ public abstract class Converter {
} }
private static void mapBlock(State state, int id, int data) { private static void mapBlock(State state, int id, int data) {
BLOCK_MAP[(id << 4) | data] = (char)BlockRegistry.STATEMAP.get(state); BLOCK_MAP[(id << 4) | data] = (char)State.ID_MAP.get(state);
} }
private static void mapBlock(State state, int id) { private static void mapBlock(State state, int id) {

View file

@ -54,7 +54,7 @@ public class Region {
State state = block.getStateFromMeta(n); State state = block.getStateFromMeta(n);
String id = state.getId(); String id = state.getId();
List<Character> ids = current.get(id); List<Character> ids = current.get(id);
char mid = (char)BlockRegistry.STATEMAP.get(state); char mid = (char)State.ID_MAP.get(state);
if(ids == null) { if(ids == null) {
current.put(id, Lists.newArrayList(mid)); current.put(id, Lists.newArrayList(mid));
} }

View file

@ -1,6 +1,5 @@
package server.worldgen; package server.worldgen;
import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.world.State; import common.world.State;
@ -18,11 +17,11 @@ public class ChunkPrimer {
} }
public State get(int x, int y, int z) { public State get(int x, int y, int z) {
State state = BlockRegistry.STATEMAP.getByValue(this.data[x << 4 | z | y << 8]); State state = State.ID_MAP.getByValue(this.data[x << 4 | z | y << 8]);
return state != null ? state : Blocks.air.getState(); return state != null ? state : Blocks.air.getState();
} }
public void set(int x, int y, int z, State state) { public void set(int x, int y, int z, State state) {
this.data[x << 4 | z | y << 8] = (short)BlockRegistry.STATEMAP.get(state); this.data[x << 4 | z | y << 8] = (short)State.ID_MAP.get(state);
} }
} }

View file

@ -4,9 +4,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import common.biome.Biome; import common.biome.Biome;
import common.block.Block;
import common.block.artificial.BlockSlab; import common.block.artificial.BlockSlab;
import common.block.artificial.BlockStairs; import common.block.artificial.BlockStairs;
import common.block.foliage.BlockCrops;
import common.block.foliage.BlockLog; import common.block.foliage.BlockLog;
import common.block.tech.BlockTorch; import common.block.tech.BlockTorch;
import common.collect.Lists; import common.collect.Lists;
@ -381,10 +381,10 @@ public class StructureVillage
public static class Field1 extends StructureVillage.Village public static class Field1 extends StructureVillage.Village
{ {
private Block cropTypeA; private BlockCrops cropTypeA;
private Block cropTypeB; private BlockCrops cropTypeB;
private Block cropTypeC; private BlockCrops cropTypeC;
private Block cropTypeD; private BlockCrops cropTypeD;
public Field1() public Field1()
{ {
@ -413,13 +413,13 @@ public class StructureVillage
protected void readTags(TagObject tagCompound) protected void readTags(TagObject tagCompound)
{ {
super.readTags(tagCompound); super.readTags(tagCompound);
this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA")); this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA")) instanceof BlockCrops crops ? crops : Blocks.wheat;
this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB")); this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB")) instanceof BlockCrops crops ? crops : Blocks.wheat;
this.cropTypeC = BlockRegistry.getRegisteredBlock(tagCompound.getString("CC")); this.cropTypeC = BlockRegistry.getRegisteredBlock(tagCompound.getString("CC")) instanceof BlockCrops crops ? crops : Blocks.wheat;
this.cropTypeD = BlockRegistry.getRegisteredBlock(tagCompound.getString("CD")); this.cropTypeD = BlockRegistry.getRegisteredBlock(tagCompound.getString("CD")) instanceof BlockCrops crops ? crops : Blocks.wheat;
} }
private Block func_151559_a(Random rand) private BlockCrops func_151559_a(Random rand)
{ {
switch (rand.zrange(5)) switch (rand.zrange(5))
{ {
@ -469,14 +469,14 @@ public class StructureVillage
for (int i = 1; i <= 7; ++i) for (int i = 1; i <= 7; ++i)
{ {
this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(randomIn.range(2, 7)), 1, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeA.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 1, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(randomIn.range(2, 7)), 2, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeA.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 2, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(randomIn.range(2, 7)), 4, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeB.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 4, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(randomIn.range(2, 7)), 5, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeB.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 5, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeC.getStateFromMeta(randomIn.range(2, 7)), 7, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeC.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 7, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeC.getStateFromMeta(randomIn.range(2, 7)), 8, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeC.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 8, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeD.getStateFromMeta(randomIn.range(2, 7)), 10, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeD.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 10, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeD.getStateFromMeta(randomIn.range(2, 7)), 11, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeD.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 11, 1, i, structureBoundingBoxIn);
} }
for (int k = 0; k < 9; ++k) for (int k = 0; k < 9; ++k)
@ -494,8 +494,8 @@ public class StructureVillage
public static class Field2 extends StructureVillage.Village public static class Field2 extends StructureVillage.Village
{ {
private Block cropTypeA; private BlockCrops cropTypeA;
private Block cropTypeB; private BlockCrops cropTypeB;
public Field2() public Field2()
{ {
@ -520,11 +520,11 @@ public class StructureVillage
protected void readTags(TagObject tagCompound) protected void readTags(TagObject tagCompound)
{ {
super.readTags(tagCompound); super.readTags(tagCompound);
this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA")); this.cropTypeA = BlockRegistry.getRegisteredBlock(tagCompound.getString("CA")) instanceof BlockCrops crops ? crops : Blocks.wheat;
this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB")); this.cropTypeB = BlockRegistry.getRegisteredBlock(tagCompound.getString("CB")) instanceof BlockCrops crops ? crops : Blocks.wheat;
} }
private Block func_151560_a(Random rand) private BlockCrops func_151560_a(Random rand)
{ {
switch (rand.zrange(5)) switch (rand.zrange(5))
{ {
@ -570,10 +570,10 @@ public class StructureVillage
for (int i = 1; i <= 7; ++i) for (int i = 1; i <= 7; ++i)
{ {
this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(randomIn.range(2, 7)), 1, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeA.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 1, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeA.getStateFromMeta(randomIn.range(2, 7)), 2, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeA.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 2, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(randomIn.range(2, 7)), 4, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeB.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 4, 1, i, structureBoundingBoxIn);
this.setBlockState(worldIn, this.cropTypeB.getStateFromMeta(randomIn.range(2, 7)), 5, 1, i, structureBoundingBoxIn); this.setBlockState(worldIn, this.cropTypeB.getState().withProperty(BlockCrops.AGE, randomIn.range(2, 7)), 5, 1, i, structureBoundingBoxIn);
} }
for (int k = 0; k < 9; ++k) for (int k = 0; k < 9; ++k)