Jump to content

elias54

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by elias54

  1. I've finally managed to find a way to do it, in a "2 times" function. @OnlyIn(Dist.CLIENT) public boolean isEnoughDark(World world, BlockPos pos) { if(world.getCelestialAngle(1.0F) >= 0.26F && world.getCelestialAngle(1.0F) <= 0.82) { return true; } else { return world.func_226658_a_(LightType.SKY, pos) <= 9 ? true : false; } } 1) When the night comes, hostile mobs spawn everywhere, technically. Because of that, when it's night, the function returns true. 2) Otherwise, if it's plain day, it'll check if the block where i'm standing on is dark enough to return true. (e.g : cave/deep shelter...) I still have to catch up the case when i'm in another dimension than the overworld, and i'll be good.
  2. By the way, I forgot to put that detail in my post that I've already checked the debug menu and unfortunately the Server/Client Lights values shows the same values as what I've been tried to print in the console. So in the end, it doesn't answer my question at all. Why the value still keep being stuck at 15 even in the middle of the night except in caves when it's supposed to be decremented to the correct light value ? If that's not the way it's supposed to work (even if at many places in the code definitely show it), then what should I use other than the light system to check if a block is dark enough and whatever if it can see the sky or not so hostile mobs can spawn ? Thank you, in advance.
  3. Hello ! I'm currently facing an issue for over a day now. I am making an Item that indicate if the Block right under my position is "dark enough" to make hostile mobs to spawn. For such a need, the function World#getLightValue(BlockPos) fits well. It is supposed to return an integer between 0 and 15. As i'm referring to the way it works and after reading some vanilla code parts that calls this function (such as MonsterEntity), the less the value is, the more the hostile mobs can spawn (around 8 and below). But the problem is, I've been trying to play around with this function, and it always returns 0. No matter if it's in the middle of the night or if i'm in a cave. I have been trying some alternatives such as World#getLight(BlockPos) (without the 'Value' keyword in the name), but this time I got something working a way better than the first function. However, I have a weird behavior when i'm on a top surface block (so, not in a cave which it seems to works fine), the value keep being stuck at 0 when i'm just walking on the blocks or at 15 if i'm jumping/flying, whatever if it's plain day or night... So I've been trying many solutions that cames to my mind such as Client/Server tests, but nothing worked at all. I'm still desperate now. Here is the code snipped that i'm using to check the values of World#getLight / getLightValue : My Item class: public class SafeometerItem extends Item { public SafeometerItem(Properties properties) { super(properties); this.addPropertyOverride(new ResourceLocation("darken"), new IItemPropertyGetter() { @OnlyIn(Dist.CLIENT) private float[] TEX_COORDS = { 0.0f, 0.045f, 0.09f, 0.135f, 0.18f, 0.22500001f, 0.27f, 0.315f, 0.36f, 0.40500003f, 0.45000002f, 0.495f, 0.54f, 0.58500004f, 0.63f, 0.675f, 0.72f, 0.76500005f, 0.81000006f, 0.855f, 0.90000004f, 0.94500005f }; @OnlyIn(Dist.CLIENT) public float call(ItemStack arg0, World arg1, LivingEntity arg2) { boolean flag = arg2 != null; Entity entity = (Entity)(flag ? arg2 : arg0.getItemFrame()); if (arg1 == null && entity != null) { arg1 = entity.world; } if(arg1 != null && arg2 != null) { BlockPos pos = new BlockPos(MathHelper.floor(arg2.getPosition().getX()), MathHelper.floor(arg2.getPosition().getY())-1, MathHelper.floor(arg2.getPosition().getZ())); System.out.println(arg1.getLight(pos)); System.out.println(arg1.getLightValue(pos)); return arg1.getLight(pos) <= 8 ? TEX_COORDS[11] : TEX_COORDS[0];//i <= 8 ? 0.495F : 0.0F; } else { return 0.0F; } } }); } } Yes, it is an Item with a dynamic texture such as Compass / Clock. Thanks for your help.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.