forked from daedalus4096/ThaumicWonders
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...com/verdantartifice/thaumicwonders/common/crafting/recipes/RecipeDisjunctionClothUse.java
This file contains 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,82 @@ | ||
package com.verdantartifice.thaumicwonders.common.crafting.recipes; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.verdantartifice.thaumicwonders.ThaumicWonders; | ||
import com.verdantartifice.thaumicwonders.common.items.ItemsTW; | ||
|
||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.inventory.InventoryCrafting; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.registries.IForgeRegistryEntry; | ||
|
||
public class RecipeDisjunctionClothUse extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe { | ||
public RecipeDisjunctionClothUse() { | ||
super(); | ||
setRegistryName(ThaumicWonders.MODID, "disenchant"); | ||
} | ||
|
||
@Override | ||
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) { | ||
return RecipeDisjunctionClothUse.matches(inv); | ||
} | ||
|
||
public static boolean matches(@Nonnull IInventory inv) { | ||
boolean foundCloth = false; | ||
boolean foundTarget = false; | ||
|
||
for (int index = 0; index < inv.getSizeInventory(); index++) { | ||
ItemStack stack = inv.getStackInSlot(index); | ||
if (!stack.isEmpty()) { | ||
if (stack.getItem() == ItemsTW.DISJUNCTION_CLOTH && !foundCloth) { | ||
foundCloth = true; | ||
} else if (stack.getItem() != ItemsTW.DISJUNCTION_CLOTH && !foundTarget && stack.isItemEnchanted()) { | ||
foundTarget = true; | ||
} else { | ||
// Invalid item, abort | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return foundCloth && foundTarget; | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) { | ||
ItemStack stackToDisenchant = ItemStack.EMPTY; | ||
|
||
for (int index = 0; index < inv.getSizeInventory(); index++) { | ||
ItemStack stack = inv.getStackInSlot(index); | ||
if (!stack.isEmpty() && stack.getItem() != ItemsTW.DISJUNCTION_CLOTH && stack.isItemEnchanted()) { | ||
stackToDisenchant = stack.copy(); | ||
break; | ||
} | ||
} | ||
if (!stackToDisenchant.isEmpty()) { | ||
stackToDisenchant.getTagCompound().removeTag("ench"); | ||
} | ||
|
||
return stackToDisenchant; | ||
} | ||
|
||
@Override | ||
public boolean canFit(int width, int height) { | ||
return (width >= 2) || (height >= 2); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public ItemStack getRecipeOutput() { | ||
// Recipe is dynamic, so return empty stack | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
@Override | ||
public boolean isDynamic() { | ||
return true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/verdantartifice/thaumicwonders/common/events/CraftingEvents.java
This file contains 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,38 @@ | ||
package com.verdantartifice.thaumicwonders.common.events; | ||
|
||
import com.verdantartifice.thaumicwonders.ThaumicWonders; | ||
import com.verdantartifice.thaumicwonders.common.crafting.recipes.RecipeDisjunctionClothUse; | ||
import com.verdantartifice.thaumicwonders.common.items.ItemsTW; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.PlayerEvent; | ||
import thaumcraft.api.aura.AuraHelper; | ||
|
||
@Mod.EventBusSubscriber(modid = ThaumicWonders.MODID) | ||
public class CraftingEvents { | ||
@SubscribeEvent | ||
public static void onCrafting(PlayerEvent.ItemCraftedEvent event) { | ||
// If this was a disenchantment using a Disjunction Cloth, disperse vis into the aura | ||
if (!event.player.world.isRemote && RecipeDisjunctionClothUse.matches(event.craftMatrix)) { | ||
for (int index = 0; index < event.craftMatrix.getSizeInventory(); index++) { | ||
ItemStack stack = event.craftMatrix.getStackInSlot(index); | ||
if (!stack.isEmpty() && stack.getItem() != ItemsTW.DISJUNCTION_CLOTH && stack.isItemEnchanted()) { | ||
NBTTagList tagList = stack.getEnchantmentTagList(); | ||
int totalLevels = 0; | ||
for (int tagIndex = 0; tagIndex < tagList.tagCount(); tagIndex++) { | ||
NBTTagCompound tag = tagList.getCompoundTagAt(tagIndex); | ||
totalLevels += tag.getInteger("lvl"); | ||
} | ||
if (totalLevels > 0) { | ||
AuraHelper.addVis(event.player.world, event.player.getPosition(), (totalLevels * 5.0F)); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/verdantartifice/thaumicwonders/common/items/misc/ItemDisjunctionCloth.java
This file contains 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,18 @@ | ||
package com.verdantartifice.thaumicwonders.common.items.misc; | ||
|
||
import com.verdantartifice.thaumicwonders.common.items.base.ItemTW; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public class ItemDisjunctionCloth extends ItemTW { | ||
public ItemDisjunctionCloth() { | ||
super("disjunction_cloth"); | ||
setMaxStackSize(1); | ||
setNoRepair(); | ||
} | ||
|
||
@Override | ||
public boolean isBookEnchantable(ItemStack stack, ItemStack book) { | ||
return false; | ||
} | ||
} |
This file contains 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
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/thaumicwonders/models/item/disjunction_cloth.json
This file contains 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,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "thaumicwonders:items/disjunction_cloth" | ||
} | ||
} |
This file contains 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
Binary file added
BIN
+904 Bytes
src/main/resources/assets/thaumicwonders/textures/items/disjunction_cloth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.