Jump to content

Recommended Posts

Posted

I don't know if this is easily possible, but... Is there anyway to check an item's lifespan while it's in a container, and or get the container it's in assuming the container is in a loaded chunk?

 

The idea would be to make food items that go stale and moldy over a period of time.. and not "age" while in a safe container (like a custom chest... fridge) or in a container with another item (such as ice).

 

Basically: I know I can get the age based on amount of time it spends in a player's inventory and save it to the item's NBT, but is there something similar for general time or time spent in container?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

u can save the time of creation/ the expire data in the items nbt and validate that every time u want do so. so u know "this steak was created 100 ticks ago" and if the steak is 200 ticks old make it to rotten flesh or sth like that

Posted

So I can get the world time into the NBT on creation with getWorldTime()... Then later get the world time again and say if the new world time is x amount larger than the original... then decay.. That would work for overall decay but what if I wanted to expand/delay the amount of time it takes to decay if it's in a particular container.. or is that just beyond what I can do with Minecraft?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

There are no such things as limits - you can do whatever you please.

It is matter of design.

 

Using provided tools (NBT) you could save time of creation, then also time of transition to container. Only thing to do then is to update all Items whenever container is opened - update ofc based on stored data. But doing complicated things require you to complicate your code - what if you put in and out your item few times (say freeze it for some time, then unfreeze and again freeze for some time) - at thins point you have to redesign.

 

What I would store:

int decayFactor - say it starts from 0 and goes to x number. Say max will be 48000 tick = two days.

When player has food in inventory you can easily increment this factor.

When item is in world - you can also operate on EntityItem and change NBT.

When item is put into container you save timestamp and leave decayFactor.

int storeTimestamp - moment of transition to container.

When you pull out food from container you calculate based on time passed (currentTime - storeTimestamp) and container type how much should be added to decayFactor.

 

Viola - cut and dried fridge system. :P

 

Note: Keep in mind: 1st - it is a game, moreover Minecraft, it is not supposed to be real; 2nd - don't overcomplicate systems - makes harder to track things down, uses more resources and memory. Better to make "imitation" such as one above.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Okay so right now... I have it so that 100 ticks after creation the item goes stale.. and 100 ticks after that it goes moldy.. It does this by storing time and data to the ItemStack's TagCompound. I'm not sure where to go from here though, how do I transfer/read that from the entityitem and or detect when items are placed into a container?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

U can access the actual open container of the player by player.openContainer.

Which means u can use a PlayerTickEvent, iterate through the items of the open container, check the nbt tags, and after that dance to some music.

Posted

Okay, using a PlayerTickEvent items now degrade correctly when in chests. I can either lower the amount of change or just not check at all I guess, if they are in a "fridge". Cool. Now what I have left is the entity item. I see you can just get the itemstack from the entity item so that shouldn't be too hard to just call on onEntityItemUpdate.  I'm just not quite sure about one thing.. the method I'm using to get the time (world.getWorldTime()) always seems to return a big number. Does it reset to 0.. like when the next day starts? If not how long before it's too big to be cast as int/long/double or whatever I store it in? If so how does that work with the check.. or am I using the wrong type of time?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

World#getWorldTime

returns the current time of day (so it resets to 0 at the start of the in-game day),

World#getTotalWorldTime

returns the total number of ticks that the world has been active (so it doesn't reset).

 

If you store the time as a long (what it's given to you as), that will last for

Long.MAX_VALUE

(

2^63-1

) ticks; which at 20 ticks per second is equivalent to

1.2810238940076 x 10^14

hours,

5337599558365

days or roughly

14623560433

years. I don't think you need to worry too much about your code running for that long.

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.

Posted

EDIT: I still don't know how to deal with Item Frames.. but my problem my last problem was one number out of place messing the numbers up.

Anyone have any ideas about how to work with item frames? Do I still have access to the entityItem / the itemstack's nbt or something somehow while it's on an item frame?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

EDIT: I still don't know how to deal with Item Frames.. but my problem my last problem was one number out of place messing the numbers up.

Anyone have any ideas about how to work with item frames? Do I still have access to the entityItem / the itemstack's nbt or something somehow while it's on an item frame?

 

Items in ItemFrames basically don't exist as far as Minecraft is concerned.  There's no code that triggers when an item is placed into the frame (seriously, the item stack isn't told, the item isn't told, and there's no Forge event, and no update methods are called) or when the item frame is broken (although that causes it to drop, and now that the item is an ItemEntity, there is the

onEntityItemUpdate

method, which runs every tick, so you could check there).

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.

Posted

Hmm. Interesting. I COULD compound things by adding checks to see how long it's been since the update function of the entityitem has ran similar to how I handled the chest..but I'm not sure I care THAT much, at least right now... I guess item frames are free safe storage for my foods then. Thanks. :)

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

I guess item frames are free safe storage for my foods then. Thanks. :)

 

Only sort of.  If you're checking onUpdate how long its been since creation (rather than incrementing a counter every tick) then it's not free.  As soon as the player breaks the item frame and picks up the food, it'll go rotten.

 

But I know what you're thinking, it turned into a kind of "phylactery" effect for my Unique Artifacts mod.  If a player found an item that increased their health (or speed, etc.) they could shove it into an item frame and get the bonus permanently.  Wasn't something I could prevent so I called it a feature.

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.

Posted

Wasn't something I could prevent so I called it a feature.

Reminds me of:

 

"It's not a bug! it's an undocumented feature!" - Abraham Lincoln, 1862

1.7.10 is no longer supported by forge, you are on your own.

Posted

Wasn't something I could prevent so I called it a feature.

Single simple non-disruptive ASM hook in EntityItemFrame ;)

 

I suppose I could, but when it was reported, I looked into existing hooks and didn't find anything and said, "Actually, that effect is really neat, I like it."

 

So yes, with some ASM I could "fix" the bug, but I thought it was a neat trick.  It adds a little something to PvP servers.  If someone finds your base where you've stashed all your stat boost items and breaks them, you're no longer so uber.

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.