Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package theishiopian.sandbox.world;
- import java.util.LinkedHashSet;
- import java.util.List;
- import javax.annotation.Nullable;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldSavedData;
- import net.minecraftforge.common.util.Constants;
- public class Tracking extends WorldSavedData
- {
- private final static LinkedHashSet<BlockPos>scarecrowLocations = new LinkedHashSet<BlockPos>();
- private final static String NAME = "SCL[]";
- private static Tracking instance = null;
- public Tracking()
- {
- super(NAME);
- }
- @Nullable
- public static Tracking get(World world)
- {
- if (world.isRemote)
- {
- return null;
- }
- if (instance != null) {
- return instance;
- }
- instance = (Tracking) world.loadItemData(Tracking.class, NAME);
- if (instance == null)
- {
- instance = new Tracking();
- }
- return instance;
- }
- //clears instance
- public static void clearInstance()
- {
- instance = null;
- }
- //save scarecrow data
- public void save(World world)
- {
- world.setItemData(NAME, this);
- markDirty();
- }
- //returns read only list of scarecrows
- //adds scarecrow to list
- public static void addScarecrow(BlockPos pos)
- {
- scarecrowLocations.add(pos);
- System.out.println("Registering Scarecrow");
- }
- //removes scarecrow from list
- public static void removeScarecrow(BlockPos pos)
- {
- scarecrowLocations.remove(pos);
- System.out.println("Unregistering Scarecrow");
- }
- @Override
- public void readFromNBT(NBTTagCompound scTag)
- {
- scarecrowLocations.clear();
- final NBTTagList scarecrows = scTag.getTagList("Scarecrows", Constants.NBT.TAG_COMPOUND);
- for (int i = 0; i < scarecrows.tagCount(); i++)
- {
- final NBTTagCompound locationTag = scarecrows.getCompoundTagAt(i);
- final BlockPos location = new BlockPos(locationTag.getInteger("posX"), locationTag.getInteger("posY"), locationTag.getInteger("posZ"));
- scarecrowLocations.add(location);
- }
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound scTag)
- {
- final NBTTagList locationList = new NBTTagList();
- for (BlockPos pos : scarecrowLocations)
- {
- final NBTTagCompound locationTag = new NBTTagCompound();
- locationTag.setInteger("posX", pos.getX());
- locationTag.setInteger("posY", pos.getY());
- locationTag.setInteger("posZ", pos.getZ());
- locationList.appendTag(locationTag);
- }
- scTag.setTag("Scarecrows", locationList);
- return scTag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement