Jump to content

[1.8.9] Change recipe output based on day/night


LogicTechCorp

Recommended Posts

One way to do this would be to create a custom recipe interface that extends

IRecipe

. In this interface, you can provide an overload of

getCraftingResult

that either takes the

World

(the world that the recipe is being crafted in) or a

boolean

(is it day in that world?). You can then use this method instead of

getCraftingResult(InventoryCrafting)

for any recipe that implements the interface.

 

Another way would be to have separate lists of day and night recipes and use the appropriate list for the current time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

The server has the correct item in the output slot, but the client doesn't. I suspect something is wrong with your

Container

, but I don't know what.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

In these sort of cases, you need to learn how to debug yourself. It is your code and any such problem will be specific to your code. So it is important to learn how to be self-sufficient.

 

Here is my suggestion -- trace the execution of your code carefully and confirm that every step of the code does exactly what you expect. You can do this through debug mode in Eclipse, but I prefer to use console statements since then you can just play the game and still monitor what is happening.

 

So with console statements I put a System.out.println (or you can use logger) statement in every method to confirm that the method is being called. Then in every conditional statement (like an if statement) I print out the fields that are being tested to make sure the value is correct. Lastly, any code related to the bug, I put a print out of the relevant fields.

 

When you do that, you've very quickly figure out where things are going wrong. Computers are entirely logical, so there is simply some step along the way where your code isn't doing the logic you expect. Look for that.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Again you need to go through every line of the related code and trace the execution. So if you think something is supposed to be in a slot, print out what the computer thinks is in the slot, if you think it should have found a recipe match, print out whether it found a match or not, and so on. I'm sure that if you just trace through you will find that you made some simple mistake (like wrong slot number assignment, or something).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thank you Jabelar.

 

I change the recipe output based on world.isDaytime(). It appears that it is always daytime on the client but the server time is correct. Could this be causing my issues?

 

[10:46:19] [Client thread/INFO]: [CHAT] Set the time to 13000
[10:46:29] [Client thread/INFO]: [soulmagic.item.crafting.SoulMagicCraftingManager:findMatchingRecipe:42]: isDaytime = true
[10:46:29] [server thread/INFO]: [soulmagic.item.crafting.SoulMagicCraftingManager:findMatchingRecipe:42]: isDaytime = false

 

[10:48:00] [Client thread/INFO]: [soulmagic.item.crafting.SoulMagicCraftingManager:findMatchingRecipe:43]: 8xtile.spectral_glass@0
[10:48:00] [server thread/INFO]: [soulmagic.item.crafting.SoulMagicCraftingManager:findMatchingRecipe:43]: 8xtile.spectral_glass@1

Link to comment
Share on other sites

1) I think the server should be the authority on what gets made. The client should dutifully display correct info to a player. If the client doesn't have good data, then the server must send it.

 

2) Don't forget about the End and Nether. They don't have day-night cycles, so you should think about how you want your custom crafting device to behave in those places. Do want your table to be inert? To explode? To act randomly like a clock or compass? To magically follow the day-night value of the overworld? If the day/night function doesn't default to what you envision, then you'll want to take steps.

 

3) I don't trust isDaytime(). IIRC, it is based on light value, in which a thunderstorm can turn day into night. In my own mods, I do modulo arithmetic on WorldTime:

 

  protected int signal(World w) {
    long wt = w.provider.getWorldTime ();

    if (w.provider.getHasNoSky () ||            // No sky means Nether or End (no moon phase)
        (wt % 24000) < 12000) {                 // Time of day 0..11999 is daytime (moon not up)
      return 0;
    } else {... 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Your recipe needs to subtract 1 from the item stacks, then if the stack size is zero, set the slot to null.

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.

Link to comment
Share on other sites

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.