Skip to content

Commit 86679db

Browse files
committed
New BlockLocation class.
1 parent 1235c33 commit 86679db

File tree

2 files changed

+143
-10
lines changed

2 files changed

+143
-10
lines changed

makmods/levelstorage/item/ItemFrequencyCard.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import makmods.levelstorage.LevelStorage;
66
import makmods.levelstorage.ModBlocks;
77
import makmods.levelstorage.ModItems;
8+
import makmods.levelstorage.logic.BlockLocation;
89
import makmods.levelstorage.proxy.ClientProxy;
910
import net.minecraft.client.renderer.texture.IconRegister;
1011
import net.minecraft.entity.player.EntityPlayer;
@@ -39,15 +40,6 @@ public ItemFrequencyCard() {
3940
this.setUnlocalizedName(UNLOCALIZED_NAME);
4041
}
4142

42-
public static boolean isDimIdValid(int idToCheck) {
43-
Integer[] ids = DimensionManager.getIDs();
44-
for (int id : ids) {
45-
if (id == idToCheck)
46-
return true;
47-
}
48-
return false;
49-
}
50-
5143
@Override
5244
public void addInformation(ItemStack par1ItemStack,
5345
EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
@@ -85,7 +77,7 @@ public static boolean isValid(ItemStack stack) {
8577
NBTTagCompound cardNBT = stack.getTagCompound();
8678

8779
if (hasCardData(stack)) {
88-
if (isDimIdValid(cardNBT.getInteger(NBT_DIM_ID))) {
80+
if (BlockLocation.isDimIdValid((cardNBT.getInteger(NBT_DIM_ID)))) {
8981
WorldServer w = DimensionManager.getWorld(cardNBT
9082
.getInteger(NBT_DIM_ID));
9183
int x = cardNBT.getInteger(NBT_X_POS);
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

Comments
 (0)