Jump to content

[SOLVED] [1.7.2] Make mob give off light


saxon564

Recommended Posts

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?

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
        }
    }

 

 

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.