Created
May 7, 2014 11:33
-
-
Save Jezza/5137a084f4ce391180d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package me.jezzadabomb.es2.common.core; | |
| import java.util.HashMap; | |
| import java.util.Iterator; | |
| import java.util.Map; | |
| import java.util.Map.Entry; | |
| import java.util.Set; | |
| import net.minecraft.util.ChunkCoordinates; | |
| import net.minecraft.world.World; | |
| import me.jezzadabomb.es2.common.core.utils.coordset.CoordSet; | |
| import me.jezzadabomb.es2.common.lib.Reference; | |
| public class IPylonRegistry { | |
| private static HashMap<Integer, HashMap<CoordSet, Integer>> pylonMap = new HashMap<Integer, HashMap<CoordSet, Integer>>(); | |
| public static boolean registerPylon(World world, CoordSet coordSet, int tier) { | |
| int dimID = world.provider.dimensionId; | |
| confirm(dimID); | |
| pylonMap.get(dimID).put(coordSet, tier); | |
| return pylonMap.get(dimID).containsKey(coordSet); | |
| } | |
| public static boolean registerPylon(World world, int x, int y, int z, int tier) { | |
| return registerPylon(world, new CoordSet(x, y, z), tier); | |
| } | |
| public static boolean removePylon(World world, CoordSet coordSet) { | |
| int dimID = world.provider.dimensionId; | |
| confirm(dimID); | |
| pylonMap.get(dimID).remove(coordSet); | |
| return !pylonMap.get(dimID).containsKey(coordSet); | |
| } | |
| public static boolean removePylon(World world, int x, int y, int z) { | |
| return removePylon(world, new CoordSet(x, y, z)); | |
| } | |
| public static boolean isPowered(World world, CoordSet coordSet) { | |
| int dimID = world.provider.dimensionId; | |
| confirm(dimID); | |
| Iterator<Entry<CoordSet, Integer>> it = pylonMap.get(dimID).entrySet().iterator(); | |
| while (it.hasNext()) { | |
| Entry<CoordSet, Integer> pairs = it.next(); | |
| if (pairs.getKey().withinRangeDEBUG(coordSet, (pairs.getValue() + 1) * Reference.PYLON_POWER_RANGE)) | |
| return true; | |
| } | |
| return false; | |
| } | |
| public static boolean isPowered(World world, int x, int y, int z) { | |
| return isPowered(world, new CoordSet(x, y, z)); | |
| } | |
| private static void confirm(int dimID) { | |
| if (!pylonMap.containsKey(dimID)) | |
| pylonMap.put(dimID, new HashMap<CoordSet, Integer>()); | |
| } | |
| private static class CoordSetTier { | |
| private CoordSet coordSet; | |
| private int tier; | |
| private CoordSetTier(CoordSet coordSet, int tier) { | |
| this.coordSet = coordSet; | |
| this.tier = tier; | |
| } | |
| public CoordSet getCoordSet() { | |
| return coordSet; | |
| } | |
| public int getTier() { | |
| return tier; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment