Did more work on the Ritual Reader - functionally, it is at about 80%.

This commit is contained in:
WayofTime 2016-04-10 22:09:32 -04:00
parent 30f233b81a
commit 057a951732
5 changed files with 77 additions and 7 deletions

View file

@ -1,14 +1,16 @@
package WayofTime.bloodmagic.api.ritual;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import WayofTime.bloodmagic.api.Constants;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
public abstract class AreaDescriptor implements Iterator<BlockPos>
{
public List<BlockPos> getContainedPositions(BlockPos pos)
@ -27,6 +29,16 @@ public abstract class AreaDescriptor implements Iterator<BlockPos>
public abstract void resetIterator();
public void readFromNBT(NBTTagCompound tag)
{
}
public void writeToNBT(NBTTagCompound tag)
{
}
/**
* This method changes the area descriptor so that its range matches the two
* blocks that are selected. When implementing this method, assume that
@ -189,6 +201,24 @@ public abstract class AreaDescriptor implements Iterator<BlockPos>
resetIterator();
resetCache();
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
minimumOffset = new BlockPos(tag.getInteger(Constants.NBT.X_COORD + "min"), tag.getInteger(Constants.NBT.Y_COORD + "min"), tag.getInteger(Constants.NBT.Z_COORD + "min"));
maximumOffset = new BlockPos(tag.getInteger(Constants.NBT.X_COORD + "max"), tag.getInteger(Constants.NBT.Y_COORD + "max"), tag.getInteger(Constants.NBT.Z_COORD + "max"));
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
tag.setInteger(Constants.NBT.X_COORD + "min", minimumOffset.getX());
tag.setInteger(Constants.NBT.Y_COORD + "min", minimumOffset.getY());
tag.setInteger(Constants.NBT.Z_COORD + "min", minimumOffset.getZ());
tag.setInteger(Constants.NBT.X_COORD + "max", maximumOffset.getX());
tag.setInteger(Constants.NBT.Y_COORD + "max", maximumOffset.getY());
tag.setInteger(Constants.NBT.Z_COORD + "max", maximumOffset.getZ());
}
}
public static class HemiSphere extends AreaDescriptor

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -12,6 +13,7 @@ import lombok.ToString;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
@ -51,12 +53,44 @@ public abstract class Ritual
public void readFromNBT(NBTTagCompound tag)
{
NBTTagList tags = tag.getTagList("areas", 10);
if (tags.hasNoTags())
{
return;
}
for (int i = 0; i < tags.tagCount(); i++)
{
NBTTagCompound newTag = tags.getCompoundTagAt(i);
String rangeKey = newTag.getString("key");
NBTTagCompound storedTag = newTag.getCompoundTag("area");
AreaDescriptor desc = this.getBlockRange(rangeKey);
if (desc != null)
{
desc.readFromNBT(storedTag);
}
}
}
public void writeToNBT(NBTTagCompound tag)
{
NBTTagList tags = new NBTTagList();
for (Entry<String, AreaDescriptor> entry : modableRangeMap.entrySet())
{
NBTTagCompound newTag = new NBTTagCompound();
newTag.setString("key", entry.getKey());
NBTTagCompound storedTag = new NBTTagCompound();
entry.getValue().writeToNBT(storedTag);
newTag.setTag("area", storedTag);
tags.appendTag(newTag);
}
tag.setTag("areas", tags);
}
/**