use of net.minecraft.nbt.NBTTagCompound in project Witchworks by Um-Mitternacht.
the class TileApiary method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
final NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.itemStacks = ItemNullHelper.asList(19);
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
final NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
final int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < 19) {
this.itemStacks.set(j, new ItemStack(nbttagcompound));
}
}
if (compound.hasKey("CustomName", 8)) {
this.customName = compound.getString("CustomName");
}
}
use of net.minecraft.nbt.NBTTagCompound in project Witchworks by Um-Mitternacht.
the class TileItemInventory method getUpdatePacket.
@Override
public final SPacketUpdateTileEntity getUpdatePacket() {
final NBTTagCompound tag = getUpdateTag();
writeDataNBT(tag);
return new SPacketUpdateTileEntity(pos, 0, tag);
}
use of net.minecraft.nbt.NBTTagCompound in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method assembleShip.
private void assembleShip(EntityPlayer player, SpatialDetector detector, BlockPos centerInWorld) {
MutableBlockPos pos = new MutableBlockPos();
TIntIterator iter = detector.foundSet.iterator();
int radiusNeeded = 1;
while (iter.hasNext()) {
int i = iter.next();
detector.setPosWithRespectTo(i, BlockPos.ORIGIN, pos);
int xRad = Math.abs(pos.getX() >> 4);
int zRad = Math.abs(pos.getZ() >> 4);
radiusNeeded = Math.max(Math.max(zRad, xRad), radiusNeeded + 1);
}
// radiusNeeded = Math.max(radiusNeeded, 5);
iter = detector.foundSet.iterator();
radiusNeeded = Math.min(radiusNeeded, ValkyrienWarfareMod.chunkManager.getManagerForWorld(wrapper.worldObj).maxChunkRadius);
// System.out.println(radiusNeeded);
claimNewChunks(radiusNeeded);
claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
Chunk chunk = new Chunk(worldObj, x, z);
injectChunkIntoWorld(chunk, x, z, true);
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
}
}
//Prevents weird shit from spawning at the edges of a ship
replaceOuterChunksWithAir();
VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
int minChunkX = claimedChunks[0][0].xPosition;
int minChunkZ = claimedChunks[0][0].zPosition;
refrenceBlockPos = getRegionCenter();
centerCoord = new Vector(refrenceBlockPos.getX(), refrenceBlockPos.getY(), refrenceBlockPos.getZ());
createPhysicsCalculations();
//The ship just got build, how can it not be the latest?
physicsProcessor.isShipPastBuild90 = true;
BlockPos centerDifference = refrenceBlockPos.subtract(centerInWorld);
while (iter.hasNext()) {
int i = iter.next();
detector.setPosWithRespectTo(i, centerInWorld, pos);
IBlockState state = detector.cache.getBlockState(pos);
TileEntity worldTile = detector.cache.getTileEntity(pos);
pos.setPos(pos.getX() + centerDifference.getX(), pos.getY() + centerDifference.getY(), pos.getZ() + centerDifference.getZ());
ownedChunks.chunkOccupiedInLocal[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ] = true;
Chunk chunkToSet = claimedChunks[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ];
int storageIndex = pos.getY() >> 4;
if (chunkToSet.storageArrays[storageIndex] == chunkToSet.NULL_BLOCK_STORAGE) {
chunkToSet.storageArrays[storageIndex] = new ExtendedBlockStorage(storageIndex << 4, true);
}
chunkToSet.storageArrays[storageIndex].set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, state);
if (worldTile != null) {
NBTTagCompound tileEntNBT = new NBTTagCompound();
tileEntNBT = worldTile.writeToNBT(tileEntNBT);
// Change the Block position to be inside of the Ship
tileEntNBT.setInteger("x", pos.getX());
tileEntNBT.setInteger("y", pos.getY());
tileEntNBT.setInteger("z", pos.getZ());
//Fuck this old code
// TileEntity newInstance = VKChunkCache.getTileEntity(pos);
// newInstance.readFromNBT(tileEntNBT);
TileEntity newInstance = TileEntity.create(worldObj, tileEntNBT);
newInstance.validate();
Class tileClass = newInstance.getClass();
Field[] fields = tileClass.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Object o = field.get(newInstance);
if (o != null) {
if (o instanceof BlockPos) {
BlockPos inTilePos = (BlockPos) o;
int hash = detector.getHashWithRespectTo(inTilePos.getX(), inTilePos.getY(), inTilePos.getZ(), detector.firstBlock);
if (detector.foundSet.contains(hash)) {
if (!(o instanceof MutableBlockPos)) {
inTilePos = inTilePos.add(centerDifference.getX(), centerDifference.getY(), centerDifference.getZ());
field.set(newInstance, inTilePos);
} else {
MutableBlockPos mutable = (MutableBlockPos) o;
mutable.setPos(inTilePos.getX() + centerDifference.getX(), inTilePos.getY() + centerDifference.getY(), inTilePos.getZ() + centerDifference.getZ());
}
}
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
worldObj.setTileEntity(newInstance.getPos(), newInstance);
newInstance.markDirty();
}
// chunkCache.setBlockState(pos, state);
// worldObj.setBlockState(pos, state);
}
iter = detector.foundSet.iterator();
short[][] changes = new short[claimedChunks.length][claimedChunks[0].length];
while (iter.hasNext()) {
int i = iter.next();
// BlockPos respectTo = detector.getPosWithRespectTo(i, centerInWorld);
detector.setPosWithRespectTo(i, centerInWorld, pos);
// detector.cache.setBlockState(pos, Blocks.air.getDefaultState());
// TODO: Get this to update on clientside as well, you bastard!
TileEntity tile = worldObj.getTileEntity(pos);
if (tile != null) {
tile.invalidate();
}
worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
// claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
// claimedChunks[x-ownedChunks.minX][z-ownedChunks.minZ].checkLight();
}
}
detectBlockPositions();
//TODO: This fixes the lighting, but it adds lag; maybe remove this
for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
// claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].checkLight();
}
}
coordTransform = new CoordTransformObject(this);
physicsProcessor.processInitialPhysicsData();
physicsProcessor.updateParentCenterOfMass();
}
use of net.minecraft.nbt.NBTTagCompound in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method changeOwner.
/**
* Tries to change the owner of this PhysicsObject.
*
* @param newOwner
* @return
*/
public EnumChangeOwnerResult changeOwner(EntityPlayer newOwner) {
if (!ValkyrienWarfareMod.canChangeAirshipCounter(true, newOwner)) {
return EnumChangeOwnerResult.ERROR_NEWOWNER_NOT_ENOUGH;
}
if (newOwner.entityUniqueID.toString().equals(creator)) {
return EnumChangeOwnerResult.ALREADY_CLAIMED;
}
EntityPlayer player = null;
try {
player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(UUID.fromString(creator));
} catch (NullPointerException e) {
newOwner.addChatMessage(new TextComponentString("That airship doesn't have an owner, you get to have it :D"));
newOwner.getCapability(ValkyrienWarfareMod.airshipCounter, null).onCreate();
allowedUsers.clear();
creator = newOwner.entityUniqueID.toString();
return EnumChangeOwnerResult.SUCCESS;
}
if (player != null) {
player.getCapability(ValkyrienWarfareMod.airshipCounter, null).onLose();
} else {
try {
File f = new File(DimensionManager.getCurrentSaveRootDirectory(), "playerdata/" + creator + ".dat");
NBTTagCompound tag = CompressedStreamTools.read(f);
NBTTagCompound capsTag = tag.getCompoundTag("ForgeCaps");
capsTag.setInteger("valkyrienwarfare:IAirshipCounter", capsTag.getInteger("valkyrienwarfare:IAirshipCounter") - 1);
CompressedStreamTools.safeWrite(tag, f);
} catch (IOException e) {
e.printStackTrace();
}
}
newOwner.getCapability(ValkyrienWarfareMod.airshipCounter, null).onCreate();
allowedUsers.clear();
creator = newOwner.entityUniqueID.toString();
return EnumChangeOwnerResult.SUCCESS;
}
use of net.minecraft.nbt.NBTTagCompound in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method onSetBlockState.
public void onSetBlockState(IBlockState oldState, IBlockState newState, BlockPos posAt) {
//If the block here is not to be physicsed, just treat it like you'd treat AIR blocks.
boolean oldStateOnBlackList = false, newStateOnBlackList = false;
if (oldState != null && BlockPhysicsRegistration.blocksToNotPhysicise.contains(oldState.getBlock())) {
oldState = Blocks.AIR.getDefaultState();
oldStateOnBlackList = true;
}
if (newState != null && BlockPhysicsRegistration.blocksToNotPhysicise.contains(newState.getBlock())) {
newState = Blocks.AIR.getDefaultState();
newStateOnBlackList = true;
}
boolean isOldAir = oldState == null || oldState.getBlock().equals(Blocks.AIR);
boolean isNewAir = newState == null || newState.getBlock().equals(Blocks.AIR);
if (!ownedChunks.isChunkEnclosedInMaxSet(posAt.getX() >> 4, posAt.getZ() >> 4)) {
return;
}
if (!ownedChunks.isChunkEnclosedInSet(posAt.getX() >> 4, posAt.getZ() >> 4)) {
return;
}
blocksChanged = true;
if (isNewAir) {
blockPositions.remove(posAt);
if (!worldObj.isRemote) {
balloonManager.onBlockPositionRemoved(posAt);
}
}
if ((isOldAir && !isNewAir)) {
if (!worldObj.isRemote) {
balloonManager.onBlockPositionAdded(posAt);
blockPositions.add(posAt);
} else {
if (!blockPositions.contains(posAt)) {
blockPositions.add(posAt);
}
}
int chunkX = (posAt.getX() >> 4) - claimedChunks[0][0].xPosition;
int chunkZ = (posAt.getZ() >> 4) - claimedChunks[0][0].zPosition;
ownedChunks.chunkOccupiedInLocal[chunkX][chunkZ] = true;
}
if (blockPositions.isEmpty()) {
try {
if (!worldObj.isRemote) {
if (creator != null) {
EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(UUID.fromString(creator));
if (player != null) {
player.getCapability(ValkyrienWarfareMod.airshipCounter, null).onLose();
} else {
try {
File f = new File(DimensionManager.getCurrentSaveRootDirectory(), "playerdata/" + creator + ".dat");
NBTTagCompound tag = CompressedStreamTools.read(f);
NBTTagCompound capsTag = tag.getCompoundTag("ForgeCaps");
capsTag.setInteger("valkyrienwarfare:IAirshipCounter", capsTag.getInteger("valkyrienwarfare:IAirshipCounter") - 1);
CompressedStreamTools.safeWrite(tag, f);
} catch (IOException e) {
e.printStackTrace();
}
}
ValkyrienWarfareMod.chunkManager.getManagerForWorld(worldObj).data.avalibleChunkKeys.add(ownedChunks.centerX);
}
}
} catch (Exception e) {
e.printStackTrace();
}
destroy();
}
if (!worldObj.isRemote) {
if (physicsProcessor != null) {
physicsProcessor.onSetBlockState(oldState, newState, posAt);
}
}
// System.out.println(blockPositions.size() + ":" + wrapper.isDead);
}
Aggregations