-
Notifications
You must be signed in to change notification settings - Fork 18
/
PhotometerGetter.java
54 lines (48 loc) · 1.74 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
package knightminer.inspirations.tools.client;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
import javax.annotation.Nullable;
public class PhotometerGetter implements IItemPropertyGetter {
@Override
public float call(ItemStack stack, @Nullable World world, @Nullable LivingEntity 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.getInstance().player) {
PlayerEntity player = Minecraft.getInstance().player;
if (player.getHeldItemMainhand() == stack || player.getHeldItemOffhand() == stack) {
RayTraceResult trace = Minecraft.getInstance().objectMouseOver;
if (trace != null && trace.getType() == RayTraceResult.Type.BLOCK) {
pos = ((BlockRayTraceResult)trace).getPos();
if (world.getBlockState(pos).isOpaqueCube(world, pos)) {
pos = pos.offset(((BlockRayTraceResult) trace).getFace());
}
}
}
}
// 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.getLightFor(LightType.BLOCK, pos);
}
}