Search in sources :

Example 66 with NBTTagCompound

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");
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 67 with NBTTagCompound

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity)

Example 68 with NBTTagCompound

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();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 69 with NBTTagCompound

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;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) File(java.io.File) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 70 with NBTTagCompound

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);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Aggregations

NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3985 NBTTagList (net.minecraft.nbt.NBTTagList)1052 ItemStack (net.minecraft.item.ItemStack)883 BlockPos (net.minecraft.util.math.BlockPos)229 TileEntity (net.minecraft.tileentity.TileEntity)173 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)148 ArrayList (java.util.ArrayList)99 Block (net.minecraft.block.Block)98 ResourceLocation (net.minecraft.util.ResourceLocation)96 IBlockState (net.minecraft.block.state.IBlockState)92 EntityPlayer (net.minecraft.entity.player.EntityPlayer)81 NBTTagString (net.minecraft.nbt.NBTTagString)79 Nonnull (javax.annotation.Nonnull)74 Map (java.util.Map)71 UUID (java.util.UUID)69 NBTBase (net.minecraft.nbt.NBTBase)66 HashMap (java.util.HashMap)64 EnumFacing (net.minecraft.util.EnumFacing)61 NotNull (org.jetbrains.annotations.NotNull)60 Item (net.minecraft.item.Item)55