/
PhotometerGetter.java
56 lines (51 loc) · 1.81 KB
/
PhotometerGetter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package knightminer.inspirations.tools.client;
import knightminer.inspirations.Inspirations;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
public class PhotometerGetter implements IItemPropertyGetter {
@Override
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entityIn) {
Entity entity = entityIn != null ? entityIn : stack.getItemFrame();
if(entity == null) {
return 0;
}
if(world == null) {
if(entity.world == null) {
return 0;
}
world = entity.world;
}
// if currently holding the item, use the block the player is looking at
BlockPos pos = null;
if (entity == Minecraft.getMinecraft().player) {
EntityPlayer player = Minecraft.getMinecraft().player;
if (player.getHeldItemMainhand() == stack || player.getHeldItemOffhand() == stack) {
RayTraceResult trace = Minecraft.getMinecraft().objectMouseOver;
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) {
pos = trace.getBlockPos();
if (world.isBlockFullCube(pos)) {
pos = pos.offset(trace.sideHit);
}
}
}
}
// if any part failed, just use the entity position
if (pos == null) {
pos = new BlockPos(entity);
}
// only use block light, skylight is not too useful
return world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, pos);
}
}