Jump to content

Recommended Posts

Posted

I still have a lot to learn so i am sure there is an easier way but with what i know now this is how i would do it.

 

create two identical blocks one that emits light and one that dosn't.

 

in the randomDisplayTick() use world.getWorldTime();

 

in the block that dosnt emmit light

if it is night use world.setBlock("light emitting version")

 

in the block that dose emit light

if it is day use world.setBlock("non light emitting version")

 

This should work but im sure there is a better way out there

 

Note to get the "actual time" use

 

double days = world.getWorldTime() / 24000;
int time = (int)(world.getWorldTime() - days * 24000);

I am the author of Draconic Evolution

Posted

randomDisplayTick is client-side only. You will need a TileEntity for proper ticking or constantly schedule Block updates.

 

im a noob so how can I do the TileEntity thingy or block updates

Posted

This example may work on 1.7.2, but I know it works on 1.6.2.  If you do not know how to use tile entities, please see the tutorial on the wiki. Now, on your updateEntity method, you should have something similar to:

 

public void updateEntity() {
   boolean isDay = this.worldObj.isDaytime();

   if (isDay && this.worldObj.getBlockId(this.posX, this.posY, this.posZ) == ModBlocks.litBlock.blockId) {
      this.worldObj.setBlock(this.posX, this.posY, this.posZ, ModBlocks.darkBlock.blockId);
   } else {
      if (!isDay && this.worldObj.getBlockId(this.posX, this.posY, this.posZ) == ModBlocks.darkBlock.blockId) {
         this.worldObj.setBlock(this.posX, this.posY, this.posZ, ModBlocks.litBlock.blockId);
      }
   }
}

 

This is a start, but there may be some unwanted happenings once the block changes, because Minecraft probably won't like the block changing, but not the tile entity. I also didn't include the server-client syncing code (to sync with the server).

  • 6 months later...
Posted

Override

Block#getLightValue

and safely cast the block access to World.

 

Then you can try using

World#isDaytime

to return a different light value.

If that doesn't work, try

World#getWorldTime

- it has a value between 0 and 23,999 in ticks.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

Hi

 

You might gain some useful ideas (in addition to the ones above) by looking how BlockRedstoneLight works.  There are two instances of it;

Blocks.lit_redstone_lamp

and

Blocks.redstone_lamp

 

It switches between them based on whether it is getting redstone power or not.

If you look at BlockDaylightDetector, it shows you how you might tell whether it's daylight or not.

 

-TGG

Posted

There's actually no reason to switch block IDs, you can do it with metadata.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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