forked from VazkiiMods/Botania
-
Notifications
You must be signed in to change notification settings - Fork 49
Add ability to consume GT Food to Gourmaryllis #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yoshy2002
wants to merge
3
commits into
master
Choose a base branch
from
gourmaryllisGTFood
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/vazkii/botania/api/lexicon/multiblock/compat/GTFoodHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package vazkii.botania.common.block.subtile.generating.compat; | ||
|
|
||
| import net.minecraft.item.ItemStack; | ||
|
|
||
| import gregtech.api.interfaces.IFoodStat; | ||
| import gregtech.api.items.MetaGeneratedItem; | ||
|
|
||
| public class GTFoodHelper { | ||
|
|
||
| public static int getFoodHungerValue(ItemStack stack) { | ||
| if (!(stack.getItem() instanceof MetaGeneratedItem)) return -1; | ||
|
|
||
| MetaGeneratedItem metaItem = (MetaGeneratedItem) stack.getItem(); | ||
| IFoodStat foodStat = metaItem.mFoodStats.get((short) stack.getItemDamage()); | ||
| if (foodStat == null) return -1; | ||
|
|
||
| int hungerValue = foodStat.getFoodLevel(metaItem, stack, null); | ||
| return hungerValue > 0 ? hungerValue : -1; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,15 +22,34 @@ | |
| import vazkii.botania.api.subtile.RadiusDescriptor; | ||
| import vazkii.botania.api.subtile.SubTileGenerating; | ||
| import vazkii.botania.common.lexicon.LexiconData; | ||
| import vazkii.botania.common.Botania; | ||
| import vazkii.botania.common.block.subtile.generating.compat.GTFoodHelper; | ||
|
|
||
| public class SubTileGourmaryllis extends SubTileGenerating { | ||
|
|
||
| private static final String TAG_COOLDOWN = "cooldown"; | ||
| private static final String TAG_STORED_MANA = "storedMana"; | ||
| private static final int RANGE = 1; | ||
|
|
||
| int cooldown = 0; | ||
| int storedMana = 0; | ||
|
|
||
| private int getFoodHungerValue(ItemStack stack) { | ||
| if (stack == null) return -1; | ||
|
|
||
|
Yoshy2002 marked this conversation as resolved.
|
||
| // Vanilla food | ||
| if (stack.getItem() instanceof ItemFood) { | ||
| return ((ItemFood) stack.getItem()).func_150905_g(stack); | ||
| } | ||
|
|
||
| // GregTech food | ||
| if (Botania.gt5Loaded) { | ||
| return GTFoodHelper.getFoodHungerValue(stack); | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| @Override | ||
| public void onUpdate() { | ||
| super.onUpdate(); | ||
|
|
@@ -49,42 +68,43 @@ public void onUpdate() { | |
| List<EntityItem> items = supertile.getWorldObj().getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(supertile.xCoord - RANGE, supertile.yCoord - RANGE, supertile.zCoord - RANGE, supertile.xCoord + RANGE + 1, supertile.yCoord + RANGE + 1, supertile.zCoord + RANGE + 1)); | ||
| for(EntityItem item : items) { | ||
| ItemStack stack = item.getEntityItem(); | ||
| if(stack != null && stack.getItem() instanceof ItemFood && !item.isDead && item.age >= slowdown) { | ||
| if(cooldown == 0) { | ||
| if(!remote) { | ||
| int val = ((ItemFood) stack.getItem()).func_150905_g(stack); | ||
| storedMana = val * val * 64; | ||
| cooldown = val * 10; | ||
| supertile.getWorldObj().playSoundEffect(supertile.xCoord, supertile.yCoord, supertile.zCoord, "random.eat", 0.2F, 0.5F + (float) Math.random() * 0.5F); | ||
| sync(); | ||
| } else | ||
| for(int i = 0; i < 10; i++) { | ||
| float m = 0.2F; | ||
| float mx = (float) (Math.random() - 0.5) * m; | ||
| float my = (float) (Math.random() - 0.5) * m; | ||
| float mz = (float) (Math.random() - 0.5) * m; | ||
| supertile.getWorldObj().spawnParticle("iconcrack_" + Item.getIdFromItem(stack.getItem()), item.posX, item.posY, item.posZ, mx, my, mz); | ||
| } | ||
|
|
||
| if (stack == null || item.isDead || item.age < slowdown) continue; | ||
|
|
||
| int hungerValue = getFoodHungerValue(stack); | ||
| if (hungerValue <= 0) continue; | ||
|
|
||
| if (cooldown == 0) { | ||
| if (!remote) { | ||
| storedMana = hungerValue * hungerValue * 64; | ||
| cooldown = hungerValue * 10; | ||
| supertile.getWorldObj().playSoundEffect(supertile.xCoord, supertile.yCoord, supertile.zCoord, "random.eat", 0.2F, 0.5F + (float) Math.random() * 0.5F); | ||
| sync(); | ||
| } else { | ||
| for (int i = 0; i < 10; i++) { | ||
| float m = 0.2F; | ||
| float mx = (float) (Math.random() - 0.5) * m; | ||
| float my = (float) (Math.random() - 0.5) * m; | ||
| float mz = (float) (Math.random() - 0.5) * m; | ||
| supertile.getWorldObj().spawnParticle("iconcrack_" + Item.getIdFromItem(stack.getItem()), item.posX, item.posY, item.posZ, mx, my, mz); | ||
| } | ||
| } | ||
|
|
||
| if(!remote) | ||
| item.setDead(); | ||
| } | ||
| if (!remote) item.setDead(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void writeToPacketNBT(NBTTagCompound cmp) { | ||
| super.writeToPacketNBT(cmp); | ||
| cmp.setInteger(TAG_COOLDOWN, cooldown); | ||
| cmp.setInteger(TAG_COOLDOWN, cooldown); | ||
| cmp.setInteger(TAG_STORED_MANA, storedMana); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This belongs to a different feature not attributed in the MR |
||
| } | ||
|
|
||
| @Override | ||
| public void readFromPacketNBT(NBTTagCompound cmp) { | ||
| super.readFromPacketNBT(cmp); | ||
| cooldown = cmp.getInteger(TAG_COOLDOWN); | ||
| storedMana = cmp.getInteger(TAG_STORED_MANA); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several other mods in GTNH that derive food stats. Have you checked what API is being used for that? If there is none, should we allow GTNH commit the sin of being exclusive at the cost of all the other mods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most notable mods that add food to the game imo are
Natura and Binnies both extend ItemFood, so they get caught by the first check and get consumed ingame. When checking ingame, Pam's food also gets consumed, so I suppose they also extend ItemFood.
So I don't see any "exclusiveness" for GT Food, i just see them being treated the same as the other food.
If im misunderstanding your question, please correct me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm postulating is that the real bug is actually that GregTech foods do not implement ItemFood, and this merge request is a poor man's excuse for not fixing the root cause of the problem.
That is the argument that you have to disprove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are metaitems so they cannot extend ItemFood. It's not an interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Four says, its impossible for them to implement ItemFood, due to them being metaitems. That should "disprove" your argument enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not change the conclusion that GregTech broke compatibility on its own volition by refusing to use ItemFood (and yes I'm aware that migration from one item to another is going to be annoying) and therefore it should normally carry the burden of responsibility.
The other question is also yet unanswered: how do all the other food-related mods interoperate with gregtech foods? There's at least spice of life and a NEI integration that also know how to obtain the food value.