mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-27 15:33:05 +00:00
Additional ISBRH compat + JSONModel Compat from GTNHLib (#54)
This commit is contained in:
1 parent
f10595d062
commit
2d050bdd08
15 files changed
+307
-28
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package codechicken.multipart;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import codechicken.lib.raytracer.ExtendedMOP;
|
||||
import scala.Tuple2;
|
||||
|
||||
/**
|
||||
* A helper class for resolving parts so we don't do a double look up
|
||||
*/
|
||||
public final class RenderPartResolver {
|
||||
|
||||
public static TMultiPart resolve(IBlockAccess world, int x, int y, int z) {
|
||||
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
// Make sure the hit is actually this block.
|
||||
MovingObjectPosition hit = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if (hit == null || hit.blockX != x || hit.blockY != y || hit.blockZ != z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object data = ExtendedMOP.getData(hit);
|
||||
|
||||
if (!(data instanceof Tuple2)) {
|
||||
return null;
|
||||
}
|
||||
Tuple2<?, ?> hitInfo = (Tuple2<?, ?>) data;
|
||||
Object indexObject = hitInfo._1();
|
||||
if (!(indexObject instanceof Integer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int index = (Integer) indexObject;
|
||||
TileMultipartClient tile = getMultipartTile(world, x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Needed because scala is stupid and the client tile doesn't expose what we need.
|
||||
TileMultipart multipart = (TileMultipart) tile;
|
||||
|
||||
if (index < 0 || index >= multipart.jPartList().size()) {
|
||||
return null;
|
||||
}
|
||||
return multipart.jPartList().get(index);
|
||||
}
|
||||
|
||||
private static TileMultipartClient getMultipartTile(IBlockAccess world, int x, int y, int z) {
|
||||
if (world.getTileEntity(x, y, z) instanceof TileMultipartClient) {
|
||||
return (TileMultipartClient) world.getTileEntity(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user