Search in sources :

Example 1 with ChunkSet

use of ValkyrienWarfareBase.ChunkManagement.ChunkSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BlockPosToShipUUIDData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    Set<Entry<UUID, ChunkSet>> entries = UUIDToChunkSet.entrySet();
    //2 ints, 1 byte (radius), and 2 longs for each ship, that comes out to 25 bytes per entry
    int byteArraySize = entries.size() * 25;
    ByteBuffer buffer = ByteBuffer.allocate(byteArraySize);
    for (Entry<UUID, ChunkSet> entry : entries) {
        int centerX = entry.getValue().centerX;
        int centerZ = entry.getValue().centerZ;
        byte radius = (byte) entry.getValue().radius;
        long mostBits = entry.getKey().getMostSignificantBits();
        long leastBits = entry.getKey().getLeastSignificantBits();
        buffer.putInt(centerX);
        buffer.putInt(centerZ);
        buffer.put(radius);
        buffer.putLong(mostBits);
        buffer.putLong(leastBits);
    }
    NBTUtils.setByteBuf("WorldChunkSetUUIDMix", buffer, compound);
    return compound;
}
Also used : Entry(java.util.Map.Entry) ChunkSet(ValkyrienWarfareBase.ChunkManagement.ChunkSet) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ChunkSet

use of ValkyrienWarfareBase.ChunkManagement.ChunkSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BlockPosToShipUUIDData method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound compound) {
    ByteBuffer buffer = NBTUtils.getByteBuf("WorldChunkSetUUIDMix", compound);
    //		buffer.flip();
    while (buffer.hasRemaining()) {
        int centerX = buffer.getInt();
        int centerZ = buffer.getInt();
        byte radius = buffer.get();
        long mostBits = buffer.getLong();
        long leastBits = buffer.getLong();
        //			System.out.println("Loaded a ChunkSet at " + centerX + ":" + centerZ);
        UUID persistantID = new UUID(mostBits, leastBits);
        ChunkSet set = new ChunkSet(centerX, centerZ, radius);
        UUIDToChunkSet.put(persistantID, set);
        for (int x = centerX - radius; x <= centerX + radius; x++) {
            for (int z = centerZ - radius; z <= centerZ + radius; z++) {
                chunkposToShipUUID.put(ChunkPos.chunkXZ2Int(x, z), persistantID);
            }
        }
    }
}
Also used : ChunkSet(ValkyrienWarfareBase.ChunkManagement.ChunkSet) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 3 with ChunkSet

use of ValkyrienWarfareBase.ChunkManagement.ChunkSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method readSpawnData.

public void readSpawnData(ByteBuf additionalData) {
    PacketBuffer modifiedBuffer = new PacketBuffer(additionalData);
    ownedChunks = new ChunkSet(modifiedBuffer.readInt(), modifiedBuffer.readInt(), modifiedBuffer.readInt());
    wrapper.posX = modifiedBuffer.readDouble();
    wrapper.posY = modifiedBuffer.readDouble();
    wrapper.posZ = modifiedBuffer.readDouble();
    wrapper.pitch = modifiedBuffer.readDouble();
    wrapper.yaw = modifiedBuffer.readDouble();
    wrapper.roll = modifiedBuffer.readDouble();
    wrapper.prevPitch = wrapper.pitch;
    wrapper.prevYaw = wrapper.yaw;
    wrapper.prevRoll = wrapper.roll;
    wrapper.lastTickPosX = wrapper.posX;
    wrapper.lastTickPosY = wrapper.posY;
    wrapper.lastTickPosZ = wrapper.posZ;
    centerCoord = new Vector(modifiedBuffer);
    for (boolean[] array : ownedChunks.chunkOccupiedInLocal) {
        for (int i = 0; i < array.length; i++) {
            array[i] = modifiedBuffer.readBoolean();
        }
    }
    loadClaimedChunks();
    renderer.updateOffsetPos(refrenceBlockPos);
    coordTransform.stack.pushMessage(new PhysWrapperPositionMessage(this));
    try {
        NBTTagCompound entityFixedPositionNBT = modifiedBuffer.readNBTTagCompoundFromBuffer();
        entityLocalPositions = NBTUtils.readEntityPositionMap("entityFixedPosMap", entityFixedPositionNBT);
    // if(worldObj.isRemote){
    // System.out.println(entityLocalPositions.containsKey(Minecraft.getMinecraft().thePlayer.getPersistentID().hashCode()));
    // System.out.println(Minecraft.getMinecraft().thePlayer.getPersistentID().hashCode());
    // }
    } catch (IOException e) {
        System.err.println("Couldn't load the entityFixedPosNBT; this is really bad.");
        e.printStackTrace();
    }
    isNameCustom = modifiedBuffer.readBoolean();
    shipType = modifiedBuffer.readEnumValue(ShipType.class);
}
Also used : PhysWrapperPositionMessage(ValkyrienWarfareBase.Network.PhysWrapperPositionMessage) ChunkSet(ValkyrienWarfareBase.ChunkManagement.ChunkSet) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) Vector(ValkyrienWarfareBase.API.Vector) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 4 with ChunkSet

use of ValkyrienWarfareBase.ChunkManagement.ChunkSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method readFromNBTTag.

public void readFromNBTTag(NBTTagCompound compound) {
    ownedChunks = new ChunkSet(compound);
    lastTickCenterCoord = centerCoord = NBTUtils.readVectorFromNBT("c", compound);
    wrapper.pitch = compound.getDouble("pitch");
    wrapper.yaw = compound.getDouble("yaw");
    wrapper.roll = compound.getDouble("roll");
    doPhysics = compound.getBoolean("doPhysics");
    for (int row = 0; row < ownedChunks.chunkOccupiedInLocal.length; row++) {
        boolean[] curArray = ownedChunks.chunkOccupiedInLocal[row];
        for (int column = 0; column < curArray.length; column++) {
            curArray[column] = compound.getBoolean("CC:" + row + ":" + column);
        }
    }
    String shipTypeName = compound.getString("shipType");
    if (!shipTypeName.equals("")) {
        shipType = ShipType.valueOf(ShipType.class, shipTypeName);
    } else {
        //Assume its an older Ship, and that its fully unlocked
        shipType = ShipType.Full_Unlocked;
    }
    loadClaimedChunks();
    entityLocalPositions = NBTUtils.readEntityPositionMap("entityPosHashMap", compound);
    physicsProcessor.readFromNBTTag(compound);
    pilotingController.readFromNBTTag(compound);
    String[] toAllow = compound.getString("allowedUsers").split(";");
    for (String s : toAllow) {
        allowedUsers.add(s);
    }
    creator = compound.getString("owner");
    claimedChunksInMap = compound.getBoolean("claimedChunksInMap");
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            worldObj.getChunkFromChunkCoords(x, z);
        }
    }
    isNameCustom = compound.getBoolean("isNameCustom");
    wrapper.dataManager.set(PhysicsWrapperEntity.IS_NAME_CUSTOM, isNameCustom);
}
Also used : ChunkSet(ValkyrienWarfareBase.ChunkManagement.ChunkSet) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ChunkSet (ValkyrienWarfareBase.ChunkManagement.ChunkSet)4 ByteBuffer (java.nio.ByteBuffer)2 UUID (java.util.UUID)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysWrapperPositionMessage (ValkyrienWarfareBase.Network.PhysWrapperPositionMessage)1 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1