-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f87d3a0
commit 09c7e3e
Showing
10 changed files
with
399 additions
and
25 deletions.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/dev/marston/randomloot/recipes/Recipies.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,29 @@ | ||
package dev.marston.randomloot.recipes; | ||
|
||
import dev.marston.randomloot.RandomLootMod; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraftforge.registries.IForgeRegistry; | ||
|
||
public final class Recipies { | ||
|
||
private Recipies() { | ||
|
||
} | ||
|
||
|
||
|
||
public static void init(IForgeRegistry<RecipeSerializer<?>> recipeSerializers) { | ||
RandomLootMod.LOGGER.info("registering recipes!"); | ||
register(recipeSerializers, new ResourceLocation(RandomLootMod.MODID, "texture_change_recipe"), TextureChangeRecipe.getMySerializer()); | ||
register(recipeSerializers, new ResourceLocation(RandomLootMod.MODID, "trait_poison"), TraitAdditionRecipe.getMySerializer()); | ||
|
||
} | ||
|
||
private static void register(IForgeRegistry<RecipeSerializer<?>> registry, ResourceLocation id, | ||
RecipeSerializer<?> serializer) { | ||
registry.register(id, serializer); | ||
} | ||
} | ||
|
108 changes: 108 additions & 0 deletions
108
src/main/java/dev/marston/randomloot/recipes/TextureChangeRecipe.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,108 @@ | ||
package dev.marston.randomloot.recipes; | ||
|
||
import dev.marston.randomloot.RandomLootMod; | ||
import dev.marston.randomloot.loot.LootRegistry; | ||
import dev.marston.randomloot.loot.LootUtils; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.Container; | ||
import net.minecraft.world.inventory.CraftingContainer; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.item.crafting.CraftingBookCategory; | ||
import net.minecraft.world.item.crafting.CustomRecipe; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
import net.minecraft.world.item.crafting.RecipeSerializer; | ||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class TextureChangeRecipe extends CustomRecipe { | ||
public static SimpleCraftingRecipeSerializer<TextureChangeRecipe> SERIALIZER = null; | ||
|
||
private static final Ingredient CHANGE_TEXTURE_INGREDIENT = Ingredient.of(Items.AMETHYST_SHARD); | ||
private static final Item ITEM = LootRegistry.ToolItem; | ||
|
||
public TextureChangeRecipe(ResourceLocation name, CraftingBookCategory cat) { | ||
super(name, cat); | ||
} | ||
|
||
@Override | ||
public boolean matches(CraftingContainer inv, Level level) { | ||
return !this.getOutput(inv).isEmpty(); | ||
} | ||
|
||
private ItemStack getOutput(Container inv) { | ||
RandomLootMod.LOGGER.info("Checking recipe output!"); | ||
int size = inv.getContainerSize(); | ||
|
||
int modCount = 0; | ||
ItemStack toolItem = null; | ||
|
||
for(int i = 0; i < size; i ++) { | ||
ItemStack item = inv.getItem(i); | ||
if (item.isEmpty()) { // skip empty items | ||
RandomLootMod.LOGGER.info("skipping empty item"); | ||
continue; | ||
} | ||
|
||
if (ITEM == item.getItem()) { | ||
if (toolItem != null) { | ||
RandomLootMod.LOGGER.info("can't have two tools"); | ||
return ItemStack.EMPTY; | ||
} | ||
RandomLootMod.LOGGER.info("found our tool!"); | ||
toolItem = item.copy(); | ||
continue; | ||
} | ||
|
||
if (CHANGE_TEXTURE_INGREDIENT.test(item)) { | ||
modCount ++; | ||
} | ||
|
||
|
||
} | ||
|
||
if (toolItem == null) { | ||
RandomLootMod.LOGGER.info("needs to have at least one tool"); | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
if (modCount == 0 ) { | ||
RandomLootMod.LOGGER.info("no modifiers"); | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
LootUtils.addTexture(toolItem, modCount); | ||
|
||
return toolItem; | ||
|
||
} | ||
|
||
@Override | ||
public ItemStack assemble(CraftingContainer inv, RegistryAccess registryAccess) { | ||
return this.getOutput(inv); | ||
} | ||
|
||
@Override | ||
public boolean canCraftInDimensions(int width, int height) { | ||
return false; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public RecipeSerializer<?> getSerializer() { | ||
return getMySerializer(); | ||
} | ||
|
||
public static RecipeSerializer<?> getMySerializer() { | ||
RandomLootMod.LOGGER.info("Getting TextureChange Serializer!!!"); | ||
if (SERIALIZER == null) { | ||
SERIALIZER = new SimpleCraftingRecipeSerializer<TextureChangeRecipe>( | ||
(name, category) -> new TextureChangeRecipe(name, category)); | ||
} | ||
return SERIALIZER; | ||
} | ||
|
||
} |
Oops, something went wrong.