Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PadFoot2008

Members
  • Joined

  • Last visited

Everything posted by PadFoot2008

  1. I made a mod in Intellij and clicked runClient in Gradle window to run the mod. But I got this error in the Run window : PM 01:18:16: Executing 'runClient'... FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\Tejas Bag\Work\ImmersiveSurvival\build.gradle' line: 10 * What went wrong: A problem occurred evaluating root project 'ImmersiveSurvival'. > net/minecraftforge/gradle/common/util/EnvironmentChecks * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 241ms PM 01:18:18: Execution finished 'runClient'. My Build.gradle file : buildscript { repositories { maven { url = 'https://maven.minecraftforge.net' } mavenCentral() } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true } } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' version = '1.16.5-1.0' group = 'com.padfoot.immersivesurvival' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'immersivesurvival' java.toolchain.languageVersion = JavaLanguageVersion.of(8) // Mojang ships Java 8 to end users, so your mod should target Java 8. println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { mappings channel: 'snapshot', version: '20210309-1.16.5' runs { client { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' mods { immersivesurvival { source sourceSets.main } } } server { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' mods { immersivesurvival { source sourceSets.main } } } data { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' args '--mod', 'immersivesurvival', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') mods { immersivesurvival { source sourceSets.main } } } } } sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { minecraft 'net.minecraftforge:forge:1.16.5-36.2.34' } jar { manifest { attributes([ "Specification-Title": "immersivesurvival", "Specification-Vendor": "immersivesurvivalsareus", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"immersivesurvivalsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } jar.finalizedBy('reobfJar') publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file:///${project.projectDir}/mcmodsrepo" } } } src\main\java\com\padfoot\immersivesurvival\ImmersiveSurvival.java : @Mod(ImmersiveSurvival.MOD_ID) public class ImmersiveSurvival { public static final String MOD_ID ="immersivesurvival"; // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); public ImmersiveSurvival() { // Register the setup method for modloading IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModItems.register(eventBus); ModBlocks.register(eventBus); ModTileEntities.register(eventBus); ModContainers.register(eventBus); ModRecipeTypes.register(eventBus); eventBus.addListener(this::setup); // Register the enqueueIMC method for modloading eventBus.addListener(this::enqueueIMC); // Register the processIMC method for modloading eventBus.addListener(this::processIMC); // Register the doClientStuff method for modloading eventBus.addListener(this::doClientStuff); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) {} private void doClientStuff(final FMLClientSetupEvent event) { event.enqueueWork(() -> { ScreenManager.registerFactory(ModContainers.ENCHANTING_PEDESTRAL_CONTAINER.get(), EnchantingPedestralScreen::new); }); } private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts LOGGER.info("HELLO from server starting"); } // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD // Event bus for receiving Registry Events) @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { // register a new block here LOGGER.info("HELLO from Register Block"); } } } src\main\java\com\padfoot\immersivesurvival\data\recipes\EnchantingPedestralRecipe.java : This is the file where I last made changes to. package com.padfoot.immersivesurvival.data.recipes; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializer; import com.google.gson.JsonObject; import com.padfoot.immersivesurvival.block.ModBlocks; import com.padfoot.immersivesurvival.container.EnchantingPedestralContainer; import com.padfoot.immersivesurvival.screen.EnchantingPedestralScreen; import com.padfoot.immersivesurvival.tileentity.EnchantingPedestralTile; import net.minecraft.enchantment.*; import net.minecraft.entity.item.minecart.MinecartEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapedRecipe; import net.minecraft.nbt.ListNBT; import net.minecraft.network.PacketBuffer; import net.minecraft.util.JSONUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistryEntry; import javax.annotation.Nullable; import java.util.Arrays; import java.util.Objects; public class EnchantingPedestralRecipe implements IEnchantingPedestralRecipe { public enum Weather { CLEAR, RAIN, THUNDERING; public static Weather getWeatherByString(String s) { return Objects.equals(s, "thundering") ? THUNDERING : Objects.equals(s, "rain") ? RAIN : CLEAR; } } private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> recipeItems; private final Weather weather; public static ItemStack outputin; public EnchantingPedestralRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems, Weather weather) { this.id = id; this.output = output; this.recipeItems = recipeItems; this.weather = weather; } @Override public boolean matches(IInventory inv, World worldIn) { if(recipeItems.get(1).test(inv.getStackInSlot(1))) { outputin = inv.getStackInSlot(0); return recipeItems.get(1).test(inv.getStackInSlot(1)); } return false; } @Override public NonNullList<Ingredient> getIngredients() { return recipeItems; } @Override public ItemStack getCraftingResult(IInventory inv) { return output; } @Override public ItemStack getRecipeOutput() { return output.copy(); } public Weather getWeather() { return this.weather; } public ItemStack getIcon() { return new ItemStack(ModBlocks.ENCHANTING_PEDESTRAL.get()); } @Override public ResourceLocation getId() { return id; } @Override public IRecipeSerializer<?> getSerializer() { return ModRecipeTypes.ENCHANTING_SERIALIZER.get(); } public static class EnchantingRecipeType implements IRecipeType<EnchantingPedestralRecipe> { @Override public String toString() { return EnchantingPedestralRecipe.TYPE_ID.toString(); } } public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EnchantingPedestralRecipe> { @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); ItemStack output; if (outputin != null) { output = outputin; int i = EnchantmentHelper.getEnchantmentLevel(enchant, output); int j = enchant.getMaxLevel(); int k = i++; if (output.isEnchantable() == true) { if (i<j) { output.addEnchantment(enchant, k); } } } else { output = new ItemStack(Items.WOODEN_SWORD); output.addEnchantment(enchant, 1); } String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather)); } @Nullable @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.read(buffer)); } ItemStack output = buffer.readItemStack(); return new EnchantingPedestralRecipe(recipeId, output, inputs, null); } @Override public void write(PacketBuffer buffer, EnchantingPedestralRecipe recipe) { buffer.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.write(buffer); } buffer.writeItemStack(recipe.getRecipeOutput(), false); } } } Please help.
  2. Thanks a lot! Everything works now!
  3. Thanks it worked! But I just wanted to know how can I get the max enchantment level of an enchantment like for Power it's 5, for Fortune it's 3, etc. Is there a method I can use like: int enchantmentlevel = SomeClass.getEnchantmentLevel(Enchantments.SILK_TOUCH);
  4. How do I get it in public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer)
  5. Please ignore this message. public boolean matches(IInventory inv, World worldIn)
  6. Wait, let me explain – Currently, in recipe Json, there's 5 objects – 1. Weather – Returns the weather required for the recipe to work 2. Enchantment – Returns the enchantment that will be applied to the output 3. Ingredients (slot 0) – Returns the tool required in slot 0. 4. Ingredients (slot 1) – Returns the crystal required in slot 1. 5. Output – Returns the output tool. So, I get the Output and the Enchantment and then apply the enchantment on the output and then return it in public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) . And in public boolean matches(IInventory inv, World worldIn) I check if Ingredient (slot 0) and Ingredient (slot 1) are placed in their respective slots. This will be really tedious as I have to add recipes for all tools and armour and their respective Enchantments. Instead, I thought it would be better if public boolean matches(IInventory inv, World worldIn) would check for only the Ingredients (slot 1) in slot 1 and any tool that will be placed slot 0 shall be enchanted based it. For that I would need to get what is there in slot 0 in public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) get the enchantment and then enchant it; and return it as the output. So how do I get what's kept in slot 0?
  7. I'm making a Tile Entity. It has 2 slots: one for a tool and the second for a crystal. The tool will be enchanted based on the crystal provided. Which enchantment will be applied in respect to the crystal is kept in a Json file. I've been able to get enchantment from the Json file and it also checks whether the correct crystal is present. But I am unable to get the tool present in the first slot and then enchant it.
  8. Sorry I'm a new modder actually. So what code do I have to add and where do I have to add it?
  9. I don't get what do I have to do exactly. I'm following Kaupenjoe's tutorial: https://github.com/Tutorials-By-Kaupenjoe/Minecraft-1.16.5 Here's the TileEntity class: public class EnchantingPedestralTile extends TileEntity implements ITickableTileEntity { private final ItemStackHandler itemHandler = createHandler(); private final LazyOptional<IItemHandler> handler = LazyOptional.of(() -> itemHandler); public EnchantingPedestralTile(TileEntityType<?> tileEntityTypeIn) { super(tileEntityTypeIn); } public EnchantingPedestralTile() { this(ModTileEntities.ENCHANTING_PEDESTRAL_TILE.get()); } @Override public void read(BlockState state, CompoundNBT nbt) { itemHandler.deserializeNBT(nbt.getCompound("inv")); super.read(state, nbt); } @Override public CompoundNBT write(CompoundNBT compound) { compound.put("inv", itemHandler.serializeNBT()); return super.write(compound); } private ItemStackHandler createHandler() { return new ItemStackHandler(2) { @Override protected void onContentsChanged(int slot) { markDirty(); } @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { return true; } @Override public int getSlotLimit(int slot) { return 1; } @Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if(!isItemValid(slot, stack)) { return stack; } return super.insertItem(slot, stack, simulate); } }; } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return handler.cast(); } return super.getCapability(cap, side); } private void strikeLightning() { if(!this.world.isRemote()) { EntityType.LIGHTNING_BOLT.spawn((ServerWorld)world, null, null, pos, SpawnReason.TRIGGERED, true, true); } } public void craft() { Inventory inv = new Inventory(itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inv.setInventorySlotContents(i, itemHandler.getStackInSlot(i)); } Optional<EnchantingPedestralRecipe> recipe = world.getRecipeManager() .getRecipe(ModRecipeTypes.ENCHANTING_RECIPE, inv, world); recipe.ifPresent(iRecipe -> { ItemStack tool = iRecipe.getRecipeOutput(); if(iRecipe.getWeather().equals(EnchantingPedestralRecipe.Weather.CLEAR) && !world.isRaining()) { craftTheItem(tool); } if(iRecipe.getWeather().equals(EnchantingPedestralRecipe.Weather.RAIN) && world.isRaining()) { craftTheItem(tool); } if(iRecipe.getWeather().equals(EnchantingPedestralRecipe.Weather.THUNDERING) && world.isThundering()) { strikeLightning(); craftTheItem(tool); } markDirty(); }); } private void craftTheItem(ItemStack tool) { itemHandler.extractItem(0, 1, false); itemHandler.extractItem(1, 1, false); itemHandler.insertItem(0, tool, false); } @Override public void tick() { if(world.isRemote) return; craft(); } } And the custom Recipe class: public class EnchantingPedestralRecipe implements IEnchantingPedestralRecipe { public enum Weather { CLEAR, RAIN, THUNDERING; public static Weather getWeatherByString(String s) { return Objects.equals(s, "thundering") ? THUNDERING : Objects.equals(s, "rain") ? RAIN : CLEAR; } } private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> recipeItems; private final Weather weather; public EnchantingPedestralRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems, Weather weather) { this.id = id; this.output = output; this.recipeItems = recipeItems; this.weather = weather; } @Override public boolean matches(IInventory inv, World worldIn) { // Checks for correct focus (Glass Pane) if(recipeItems.get(0).test(inv.getStackInSlot(0))) { return recipeItems.get(1).test(inv.getStackInSlot(1)); } return false; } @Override public NonNullList<Ingredient> getIngredients() { return recipeItems; } @Override public ItemStack getCraftingResult(IInventory inv) { return output; } @Override public ItemStack getRecipeOutput() { return output.copy(); } public Weather getWeather() { return this.weather; } public ItemStack getIcon() { return new ItemStack(ModBlocks.ENCHANTING_PEDESTRAL.get()); } @Override public ResourceLocation getId() { return id; } @Override public IRecipeSerializer<?> getSerializer() { return ModRecipeTypes.ENCHANTING_SERIALIZER.get(); } public static class EnchantingRecipeType implements IRecipeType<EnchantingPedestralRecipe> { @Override public String toString() { return EnchantingPedestralRecipe.TYPE_ID.toString(); } } public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EnchantingPedestralRecipe> { @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); //Here's where I want to get what's in the first slot of my TileEntity ItemStack output = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "output")); output.addEnchantment(enchant,1); String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather)); } @Nullable @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.read(buffer)); } ItemStack output = buffer.readItemStack(); return new EnchantingPedestralRecipe(recipeId, output, inputs, null); } @Override public void write(PacketBuffer buffer, EnchantingPedestralRecipe recipe) { buffer.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.write(buffer); } buffer.writeItemStack(recipe.getRecipeOutput(), false); } } } What do I add to the Recipe class?
  10. I am making a Tile entity with two slots. I want to retrieve the item in the first slot and add to an ItemStack. But I'm not sure how do I do that. Please help.
  11. And the recipe json: { "type": "immersivesurvival:enchanting", "weather": "clear", "enchantment": "minecraft:fire_aspect", "ingredients" : [ { "item": "minecraft:diamond_sword" }, { "item": "immersivesurvival:fire_shard" } ], "output": { "item": "minecraft:diamond_sword" } } Thanks again a lot!
  12. It worked! I also edited the code a bit, and created a new field called enchantment in the recipe json. Thanks for all the help. @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "enchantment"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); ItemStack output = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "output")); output.addEnchantment(enchant,1); String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather)); }
  13. Thanks for all the help. Will try it tomorrow morning +0530GMT
  14. What's the valid registry name for Enchantments.FIRE_ASPECT?
  15. I am trying to make a tile entity with 2 slots - top one will get a tool and bottom one will get a crystal. The tool will be enchanted based on the crystal and get placed in the top slot and the crystal will be deleted. The recipe is provided in I'm using Kaupenjoe's tutorial for this: Here's the original code by Kaupenjoe: @Override public LightningChannelerRecipe read(ResourceLocation recipeId, JsonObject json) { ItemStack output = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "output")); String weather = JSONUtils.getString(json, "weather"); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new LightningChannelerRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather)); } Here the Json file (original): { "type": "immersivesurvival:enchanting", "weather": "clear", "ingredients" : [ { "item": "minecraft:diamond_sword" }, { "item": "immersivesurvival:fire_shard" } ], "output": { "item": "minecraft:diamond_shovel" }} This code works properly and output a diamond shovel, but of course that's not what I want to do. I edited the code such that it gets the item from the first slot and the enchantment given in the Json and then enchants it with the enchantment and then returns it. @Override public EnchantingPedestralRecipe read(ResourceLocation recipeId, JsonObject json) { String enchantraw = JSONUtils.getString(json, "output"); Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantraw)); JsonArray ingredients = JSONUtils.getJsonArray(json, "ingredients"); String rawtool = ingredients.get(0).getAsString(); Item outputraw = ForgeRegistries.ITEMS.getValue(new ResourceLocation(rawtool)); ItemStack output = new ItemStack(outputraw); output.addEnchantment(enchant,1); String weather = JSONUtils.getString(json, "weather"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.deserialize(ingredients.get(i))); } return new EnchantingPedestralRecipe(recipeId, output, inputs, Weather.getWeatherByString(weather)); } And the recipe json: { "type": "immersivesurvival:enchanting", "weather": "clear", "ingredients" : [ { "item": "minecraft:diamond_sword" }, { "item": "immersivesurvival:fire_shard" } ], "output": { "item": "Enchantments.FIRE_ASPECT" }} But it isn't working. Any help will be appreciated.

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.