Jump to content

Recommended Posts

Posted

I am currently making a mob that will give off light, I have found that to do this I have to use this.worldObj.setLightLevel. but I am not sure how i have to get the first variable, EnumSkyBlock. Could someone point me in the right direction to figuring this out?

Posted

Hi

 

Unfortunately I think what you're planning will almost certainly not work the way you have in mind.

 

You mean this.worldObj.setLightValue, yes?

 

Here is some background information about how block and sky lighting works

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

 

Torches and other blocks can give off light.  But as far as I know, Entities can't, unless you're willing to overwrite the lightmap for all nearby blocks every time the entity moves, and somehow stop the vanilla code from changing it back. 

 

-TGG

 

 

 

 

Posted

Hi

 

Unfortunately I think what you're planning will almost certainly not work the way you have in mind.

 

You mean this.worldObj.setLightValue, yes?

 

Here is some background information about how block and sky lighting works

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

 

Torches and other blocks can give off light.  But as far as I know, Entities can't, unless you're willing to overwrite the lightmap for all nearby blocks every time the entity moves, and somehow stop the vanilla code from changing it back. 

 

-TGG

ok, thank you for that, i was using

this.worldObj.getBlock((int) this.posX, (int) this.posY, (int) this.posZ).setLightLevel(7F);

but it was causing loads of lag, and i just figured out that it wasnt just doing the block it occupied, being air, but all blocks in the world that were air. I guess my best bet would be just to play around with it until i figure something out.

 

You can "cheat" by making a invisible block that emits light, and moving that along with the entity.

the problem with that is the block would still exist so if the mob fell on a slab the slab would get replaced, same with stairs, and any liquid object. So that just doesnt work out very well. I did think about that to achieve something else until i realized those issues.

Posted

So I have done some digging and now i have this:

this.worldObj.setLightValue(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ, 15);
this.worldObj.scheduleBlockUpdateWithPriority((int)this.posX, (int)this.posY, (int)this.posZ, (Block) this.worldObj.getBlock((int)this.posX, (int)this.posY, (int)this.posZ), 10, 5);

Light does in fact appear, but i cannot get it to go away afterward. I am just playing around with it right now and am guessing that this will produce a flickering effect if the block actually updated like i expected it would. so my question now is, what are the last 2 integers of the update priority? If i could get this to work and it is to fast that its hard to see the flickering, then maybe this would do exactly what i want it to do.

 

I am aware of what you are saying though TGG, Its not that I ignored what you said but I am sure there is a way to do this without have to override the minecraft code. in fact with what is happening it seems that the vanilla code is ignoring the block altogether since it isnt blacking back out even after i kill the mob.

Posted

So I have done some digging and now i have this:

this.worldObj.setLightValue(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ, 15);
this.worldObj.scheduleBlockUpdateWithPriority((int)this.posX, (int)this.posY, (int)this.posZ, (Block) this.worldObj.getBlock((int)this.posX, (int)this.posY, (int)this.posZ), 10, 5);

Light does in fact appear, but i cannot get it to go away afterward. I am just playing around with it right now and am guessing that this will produce a flickering effect if the block actually updated like i expected it would. so my question now is, what are the last 2 integers of the update priority? If i could get this to work and it is to fast that its hard to see the flickering, then maybe this would do exactly what i want it to do.

 

I am aware of what you are saying though TGG, Its not that I ignored what you said but I am sure there is a way to do this without have to override the minecraft code. in fact with what is happening it seems that the vanilla code is ignoring the block altogether since it isnt blacking back out even after i kill the mob.

Keen :-)

 

Perhaps what is happening is that nothing nearby is triggering a lighting update.  Vanilla is very careful to only update lighting when it has to, and even then it does it pseudo-randomly over a long period of time, to avoid overwhelming the game with calculations.

 

I think you probably don't want to use scheduleBlockUpdateWithPriority; to get rid of the light, you might be better to try .updateAllLightTypes(x, y, z);

 

-TGG

 

 

 

 

Posted

I played around with this for a flashlight effect one time and had the same issues you were experiencing where i couldn't get it to go away.  Never did figure out how to do it with skyblocks.  If you do, please share.

 

What I ended up doing was creating a block that decayed and went away in X ticks.  My flashlight would place that block. 

 

You could do something similar with putting a block where the entities head is assuming it is originally an air block.  This has limitations if the mob is near a vine, in water, ect.  Not the best of solutions.

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Keen :-)

 

Perhaps what is happening is that nothing nearby is triggering a lighting update.  Vanilla is very careful to only update lighting when it has to, and even then it does it pseudo-randomly over a long period of time, to avoid overwhelming the game with calculations.

 

I think you probably don't want to use scheduleBlockUpdateWithPriority; to get rid of the light, you might be better to try .updateAllLightTypes(x, y, z);

 

-TGG

 

After putting that into my code, it tells me to cast this.worldObj to (Object) so when I do that it the says to add a cast to the receiver method. So I am not sure what the structure build from "this" is to get that method available.

Posted

Ummm, it put the change into the base Minecraft code?  That doesn't sound like a winner.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Ummm, it put the change into the base Minecraft code?  That doesn't sound like a winner.

It couldnt because it wasnt actually finding a matching method. I looked through the list of available methods a bit more and found the one he was talking about but it also had EnumSkyBlock as the first variable.but it seems to be just shutting off the light. What I need to do is figure out how to provide a block update that updates all blocks around the chicken without over doing the code.

Posted

Well I now have it lighting up the area correctly and removing the light like it should by using this chunk of code:

 

 

this.worldObj.setLightValue(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ, 15);
        this.worldObj.markBlockRangeForRenderUpdate((int)this.posX, (int)this.posY, (int)this.posX, 12, 12, 12);
        this.worldObj.markBlockForUpdate((int)this.posX, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ -1);

 

 

but now if you restart the world then the last spot the chicken was in gets lits up.

Posted

If you put a block or light source down in the vicinity after restart and remove it, does it fix it?  Or is it stuck?

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

The only way to remove it after restart is to place a block in that exact spot. I think what i need is a method to fire  righy after the mob despawns to update the light level of that block.

Posted

YES!!! I figured it out! just had to add this:

if (this.isDead) {
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ);
}

to the end of the living update! :D

 

@TGG

I just have to say this, I really respect you for your knowledge of forge, but... I did what you said probably wouldn't work :P I still have to say thank you so much for your help though.

 

So here is the final block of code:

 

 

private void addLight() {
    	this.worldObj.setLightValue(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ, 15);
        this.worldObj.markBlockRangeForRenderUpdate((int)this.posX, (int)this.posY, (int)this.posX, 12, 12, 12);
        this.worldObj.markBlockForUpdate((int)this.posX, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY +1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY +1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY -1, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY -1, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX +1, (int)this.posY, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ -1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX -1, (int)this.posY, (int)this.posZ);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ +1);
        this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ -1);
    }

    public void onLivingUpdate()
    {
        super.onLivingUpdate();

        this.field_70888_h = this.field_70886_e;
        this.field_70884_g = this.destPos;
        this.destPos = (float)((double) this.destPos + (double)(this.onGround ? -1
                               : 4) * 0.3D);
        addLight();

        if (this.destPos < 0.0F)
        {
            this.destPos = 0.0F;
        }

        if (this.destPos > 1.0F)
        {
            this.destPos = 1.0F;
        }

        if (!this.onGround && this.field_70889_i < 1.0F)
        {
            this.field_70889_i = 1.0F;
        }

        this.field_70889_i = (float)((double) this.field_70889_i * 0.9D);

        if (!this.onGround && this.motionY < 0.0D)
        {
            this.motionY *= 0.6D;
        }

        this.field_70886_e += this.field_70889_i * 2.0F;

        if (this.worldObj.difficultySetting != checked)
        {
            this.difficultyChange();
            checked = this.worldObj.difficultySetting;
        }

        if (!this.isChild() && !this.worldObj.isRemote
                && --this.timeUntilNextEgg == 0)
        {
            this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            this.dropItem((Item) Item.itemRegistry.getObject("glowstone_dust"), 1);
            this.timeUntilNextEgg = this.rand.nextInt(5000) + 6000;
        }
        if (this.isDead) {
        	this.worldObj.updateLightByType(EnumSkyBlock.Block, (int)this.posX, (int)this.posY, (int)this.posZ);
        }
    }

 

 

Posted

@TGG

I just have to say this, I really respect you for your knowledge of forge, but... I did what you said probably wouldn't work :P I still have to say thank you so much for your help though.

Fair enough :-) 

 

Glad you figured it out!

 

-TGG

Posted

@TGG

I just have to say this, I really respect you for your knowledge of forge, but... I did what you said probably wouldn't work :P I still have to say thank you so much for your help though.

Fair enough :-) 

 

Glad you figured it out!

 

-TGG

 

Well i wouldnt have figured it out without you pointing me to the right updating methods. Once again thank you for your help. I am now locking this topic and i hope that it helps anyone who wants to do this same thing in the future.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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