|
| 1 | +package makmods.levelstorage.logic; |
| 2 | + |
| 3 | +import net.minecraft.tileentity.TileEntity; |
| 4 | +import net.minecraftforge.common.DimensionManager; |
| 5 | + |
| 6 | +public class BlockLocation { |
| 7 | + private int dimId; |
| 8 | + private int x; |
| 9 | + private int y; |
| 10 | + private int z; |
| 11 | + |
| 12 | + /** |
| 13 | + * Initializes a new instance of BlockLocation |
| 14 | + * |
| 15 | + * @param dimId |
| 16 | + * Dimension ID |
| 17 | + * @param x |
| 18 | + * X Coordinate |
| 19 | + * @param y |
| 20 | + * Y Coordinate |
| 21 | + * @param z |
| 22 | + * Z Coordinate |
| 23 | + */ |
| 24 | + public BlockLocation(int dimId, int x, int y, int z) { |
| 25 | + this.dimId = dimId; |
| 26 | + this.x = x; |
| 27 | + this.y = y; |
| 28 | + this.z = z; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Initializes empty instance of BlockLocation (all values are 0s) |
| 33 | + */ |
| 34 | + public BlockLocation() { |
| 35 | + this.dimId = 0; |
| 36 | + this.x = 0; |
| 37 | + this.y = 0; |
| 38 | + this.z = 0; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Self-descriptive |
| 43 | + * |
| 44 | + * @param other |
| 45 | + * BlockLocation for comparison |
| 46 | + * @return Amount of space between two points, or Integer.MAX_VALUE if |
| 47 | + * another dimension |
| 48 | + */ |
| 49 | + public int getDistance(BlockLocation other) { |
| 50 | + if (this.dimId != other.dimId) |
| 51 | + return Integer.MAX_VALUE; |
| 52 | + int xDistance = Math.abs(this.x - other.x); |
| 53 | + int yDistance = Math.abs(this.y - other.y); |
| 54 | + int zDistance = Math.abs(this.z - other.z); |
| 55 | + |
| 56 | + return xDistance + yDistance + zDistance; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Gets energy discount for given energy and distance |
| 61 | + * @param energy Energy |
| 62 | + * @param distance Distance |
| 63 | + * @return energy discount |
| 64 | + */ |
| 65 | + public int getEnergyDiscount(int energy, int distance) { |
| 66 | + // Cross-Dimensional |
| 67 | + if (distance == Integer.MAX_VALUE) |
| 68 | + return (int)(energy * 0.25f); |
| 69 | + // Distance < 1000 |
| 70 | + if (distance < 1000) |
| 71 | + return (int)(energy * 0.05f); |
| 72 | + // Distance > 1000 <2000 |
| 73 | + if (distance > 1000 && distance < 2000) |
| 74 | + return (int)(energy * 0.1f); |
| 75 | + // Distance > 2000 |
| 76 | + if (distance > 2000) |
| 77 | + return (int)(energy * 0.15f); |
| 78 | + // IDK what happened here |
| 79 | + return 0; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns whether or not DimensionId is valid |
| 84 | + * @param dimId Dimension id |
| 85 | + */ |
| 86 | + public static boolean isDimIdValid(int dimId) { |
| 87 | + Integer[] ids = DimensionManager.getIDs(); |
| 88 | + for (int id : ids) { |
| 89 | + if (id == dimId) |
| 90 | + return true; |
| 91 | + } |
| 92 | + return false; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Gets TileEntity |
| 97 | + * |
| 98 | + * @return TileEntity of block on given coordinates |
| 99 | + */ |
| 100 | + public TileEntity getTileEntity() { |
| 101 | + if (!isDimIdValid(this.dimId)) |
| 102 | + return null; |
| 103 | + return DimensionManager.getWorld(this.dimId).getBlockTileEntity(this.x, |
| 104 | + this.y, this.z); |
| 105 | + } |
| 106 | + |
| 107 | + // Getters & setters ahead |
| 108 | + public int getDimId() { |
| 109 | + return dimId; |
| 110 | + } |
| 111 | + |
| 112 | + public void setDimId(int dimId) { |
| 113 | + this.dimId = dimId; |
| 114 | + } |
| 115 | + |
| 116 | + public int getX() { |
| 117 | + return x; |
| 118 | + } |
| 119 | + |
| 120 | + public void setX(int x) { |
| 121 | + this.x = x; |
| 122 | + } |
| 123 | + |
| 124 | + public int getY() { |
| 125 | + return y; |
| 126 | + } |
| 127 | + |
| 128 | + public void setY(int y) { |
| 129 | + this.y = y; |
| 130 | + } |
| 131 | + |
| 132 | + public int getZ() { |
| 133 | + return z; |
| 134 | + } |
| 135 | + |
| 136 | + public void setZ(int z) { |
| 137 | + this.z = z; |
| 138 | + } |
| 139 | + |
| 140 | + // End of getters and setters |
| 141 | +} |
0 commit comments