Jump to content

Blu_Nighttime

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by Blu_Nighttime

  1. Thanks for the examples, shows me some options on how I might be able to restructure my class if needs be in the future. However, I'm failing to understand what I'm passing into getRecipe() that satisfies C as the inventoryIn as the second parameter. the input slot for the custom smelter is an ItemStackHandler but passing this isn't allowed and I'm not sure if it's something that needs casting/converting to something else or what that would mean that C is satisfied. Any knowledge on this is greatly appreciated.
  2. Apologies, do you have any example references you can provide for this? Thank you.
  3. So I've implemented the following statement to be as similar to what's in AbstractFurnaceTileEntity#tick IRecipe<?> irecipe = world.getRecipeManager().getRecipe(IRecipeType.SMELTING, this, world).orElse(null); My tile entity class now implements ISidedInventory like AbstractTileEntity does but now I only ever receive null. Should the param this actually reference my container class for the block or am I missing something else? If I should be referencing the container class, how would I go about doing that to satisfy the inventoryIn param?
  4. Sorry, was trying to be a bit more general for all applications. It's for a custom smelter so currently how it works as just a quickly thrown together system is that when the tile entity is loaded into the world it executed the function, as shown above, and adds the ingredient and result to a map that I then iterate over if the contents for the 0th slot (input slot) are changed and gets corresponding result from the ingredient if it's in that map. I was trying to find a way if I could get a recipe output from the ingredient that's placed inside first, which is how a crafting table works (I believe), but hadn't had any success with trying to implement that so went with the function I showed above and have it only execute once which is upon the tile being placed into the world once it has loaded from the mod starting up. It's apparent that this isn't the greatest way to implement the system but was struggling to find resources on how it should be implemented. If I placed cobblestone into the input slot, would this then return stone if I fetch its smelting/blasting recipe? If so that'd be what I'm looking for, and assuming by what you said this is the case. This would also remove the need to load all recipes on the tile entity being loaded which is just a bodge solution to the scenario. Do I need world or just call RecipeManager? It's IntelliJ's Lint for doing that. It's pretty clear that this is indeed the case so I don't understand why it needs to be flagged but I guess IntelliJ isn't that intelligent. Thanks for the reference, just took brief look at it. It's a bit annoying trying to get what the replacement methods and functions are from 1.12 to 1.14/1.15 as CraftingManager doesn't exist but I'll try to implement something similar along with what Diesie suggested. Thanks in advance as well with what has been suggested.
  5. for (Item item : ForgeRegistries.ITEMS) { IRecipe<?> iRecipe = world.getRecipeManager().getRecipe(Objects.requireNonNull(item.getRegistryName())).orElse(null); if (iRecipe != null) { // get ingredients ... } I'm using the above function to get the recipes of items that have been registered referencing ForgeRegistries. This is successful and I'm able to get the ingredients for a smelting recipe for example, for all vanilla items; however, getRecipes() returns null when item belongs to my mod. There are recipes for smelting/blasting those items and work with a normal furnace/blast furnace in-game yet don't return a IRecipe<?> like the vanilla items do. Just trying to figure out what I'm missing that Minecraft/Forge implements that I don't to get a null return and not valid IRecipe<?> Any help to this would be much appreciated and any pointers to where to further look would be appreciated as well.
  6. Thanks, I messed around this this and never got it to work how I wanted it too. So I just used player.inventory.decrStackSize() and used currentItem() and the value of 1 which did what I needed.
  7. Ah right, I got you. Simple mistake that can be easily made. I changed it to Supplier and Block, now don't get the issue. Of course you're attaching the TileEntity to the block. Also thank you, sometimes seeing an example helps with what it is you have to do Thanks guys.
  8. Trying to register the TileEntity but Eclipse gives me the errors The constructed object of type GrindingWorkbenchTileEntity is incompatible with the descriptor's return type: T The method create(Supplier<? extends T>, Block...) in the type TileEntityType.Builder is not applicable for the arguments (GrindingWorkbenchTileEntity::new, TileEntityType<GrindingWorkbenchTileEntity>) My code register event code looks like this @SubscribeEvent public static void onTileEntityRegistry(final RegistryEvent.Register<TileEntityType<?>> event) { event.getRegistry().register(TileEntityType.Builder.create(GrindingWorkbenchTileEntity::new, BlockList.GRINDING_WORKBENCH_TILEENTITY).build(null)); } NOTE: I know that I haven't setRegistryName() yet, I'll do that when this error is gone And my TileEntity class looks like this package com.github.theonepath.moreores.blocks; import static com.github.theonepath.moreores.lists.BlockList.GRINDING_WORKBENCH_TILEENTITY; import javax.annotation.Nullable; import com.github.theonepath.moreores.util.CraftingDictionary; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; public class GrindingWorkbenchTileEntity extends TileEntity{ private LazyOptional<IItemHandler> handler = LazyOptional.of(this::getHandler); public GrindingWorkbenchTileEntity() { super(GRINDING_WORKBENCH_TILEENTITY); } @Override public void read(CompoundNBT tag) { CompoundNBT invTag = tag.getCompound("inv"); getHandler().deserializeNBT(invTag); super.read(tag); } @Override public CompoundNBT write(CompoundNBT tag) { CompoundNBT compound = getHandler().serializeNBT(); tag.put("inv", compound); return super.write(tag); } private ItemStackHandler getHandler() { return new ItemStackHandler(1) { @Override public boolean isItemValid(int slot, ItemStack stack) { return stack.getItem() == CraftingDictionary.acceptableOres; } @Nullable @Override public ItemStack insertItem(int slot, @Nullable ItemStack stack, boolean simulate) { if(stack.getItem() != CraftingDictionary.acceptableOres) { return stack; } return super.insertItem(slot, stack, simulate); } }; } @Nullable @Override public <T> LazyOptional<T> getCapability(@Nullable Capability<T> cap, @Nullable Direction side){ if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return handler.cast(); } return super.getCapability(cap, side); } } Any advice is appreciated.
  9. Actually, I thought i had it working but turns out when I right-clicked my block, the game crashed. I add this line IItemHandler inv = (IItemHandler) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) but I don't think this is right, any pointers on this one? And PlayerInventory#currentItem is what I was looking for. Thanks.
  10. OK, I have this implemented now; thanks for the redirection from the old API. However, how do I get the slot number that the ItemStack is at? I see get slots but that just returns the number of slots available so is there another way? Cheers.
  11. When the player right-clicks my custom block, I want the a single item from the stack to be removed from the players inventory, i.e. if the player has 50 of an item it goes down to 49. I can easily add items to the players inventory use player.addItemStackToInventory but can't seem to find something similar for removing an item. I thought player.entityDropItem might work but that doesn't seem to work; my block also knows what item was used on right-click. Any help is appreciated.
  12. Ah ha, so the loot tables that I saw mentioned somewhere else is the way that blocks are now dropped. I looked up in the reference library once you said, if I did have a loot table, and found out how to do it. Once I added the loot table for my mod and custom block to it, the block dropped when broken in survival. Thanks again.
  13. When a custom block is broken in survival, it doesn't drop and is just destroyed. I create a block like this: public static final Block CUSTOM_BLOCK = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F)).setRegistryName(id, "custom_block"); And register inside of getRegistry#registerAll, so the block appears and functions 'normally' but doesn't drop on break. I think I saw somewhere that block breaks are something to do with getLootTable but not 100 percent sure. Also looking at the docs for 1.13.x, and not sure if it changed in 1.14.4, there's a function called onBlockDestroyedByPlayer but I'm not sure if I need to implement this into each class for the block. If there's something else I'm missing that would be causing my confusion then please let me know - I've never had this issue before. Thanks.
  14. Ah thanks for the quick reply. After you saying this and me being a little confused I checked ItemAxe class to see how it's performed and now understand how to implement the feature. Thanks again.
  15. Just starting updating my mod to Forge Minecraft 1.14 from 1.12 and all is good, however, I'm trying to implement an onItemUse and depending on the direction the player is looking in, set blocks around the player if they are air to fire - I'm trying to keep the code similar to my 1.12 version and make changes to the code where I need to for 1.14. The issue is that when the player right clicks with the item, nothing more than what the item extends happens (the item extends the flint & steel) so I'm not sure if onItemUse is even triggering. Here's the code listed below. package com.github.theonepath.bfs.items; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.FlintAndSteelItem; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CustomFlintAndSteelItem extends FlintAndSteelItem { public static BlockPos pos1, pos2, pos3, pos4; // variables to change the location of the blocks origin, i.e. offset 1 block to the left // The constructure that is asked to be created public CustomFlintAndSteelItem(Properties builder) { super(builder); } // The onItemUse method. When I add the @Override annotation similar to 1.12 then an error is thrown and '@Override' is asked to be removed. I also don't know if the method is being tiggered or not public ActionResultType onItemUse(PlayerEntity player, World worldIn, BlockPos pos, Hand handIn, Direction facing, float hitX, float hitY, float hitZ) { pos = pos.offset(facing); pos1 = pos.add(1, 0, 0); // pos1 and pos2 for left and right facing North or South pos2 = pos.add(-1, 0, 0); pos3 = pos.add(0, 0, 1); // pos3 and pos4 for left and right facing East or West pos4 = pos.add(0, 0, -1); ItemStack itemstack = player.getHeldItem(handIn); // get Item being held if (!player.canPlayerEdit(pos, facing, itemstack)) { return ActionResultType.FAIL; // return FAIL if condition is true } else { if (worldIn.isAirBlock(pos)) // Otherwise play the sound and set the block in front of the player to fire if the bloack is air { worldIn.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, random.nextFloat() * 0.4F + 0.8F); worldIn.setBlockState(pos, Blocks.FIRE.getDefaultState(), 11); // Set the blocks left and right of the origin to fire depending if the player is Facing North or South, or East or West if(looking[0] == Direction.NORTH || looking[0] == Direction.SOUTH) { if(worldIn.isAirBlock(pos1)) { worldIn.setBlockState(pos1, Blocks.FIRE.getDefaultState(), 11); } } if(player.getHorizontalFacing() == Direction.NORTH || player.getHorizontalFacing() == Direction.SOUTH) { if(worldIn.isAirBlock(pos1)) { worldIn.setBlockState(pos1, Blocks.FIRE.getDefaultState(), 11); } if(worldIn.isAirBlock(pos2)) { worldIn.setBlockState(pos2, Blocks.FIRE.getDefaultState(), 11); } } if(player.getHorizontalFacing() == Direction.EAST || player.getHorizontalFacing() == Direction.WEST) { if(worldIn.isAirBlock(pos3)) { worldIn.setBlockState(pos3, Blocks.FIRE.getDefaultState(), 11); } if(worldIn.isAirBlock(pos4)) { worldIn.setBlockState(pos4, Blocks.FIRE.getDefaultState(), 11); } } } if (player instanceof ServerPlayerEntity) // server-side handling similar to 1.12 { CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)player, pos, itemstack); } itemstack.damageItem(1, player, p_219999_1_ -> p_219999_1_.sendBreakAnimation(player.getActiveHand())); // Damage the item which works and return SUCCESS return ActionResultType.SUCCESS; } } } If the code seems a little janky, then I can make it more efficient later but for now I need to figure out what's not working properly. And the code to call the class for when the item is being created is as followed (I don't believe it to be the issue but here it is anyways). @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents{ @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll( ItemList.customflintandsteelitem = new CustomFlintAndSteelItem(new Item.Properties().group(bfscreativetab).maxStackSize(1).maxDamage(85)).setRegistryName(new ResourceLocation(MODID, "flintandalumbrass")), // ... more items follow ... }; Thanks for any advice in advance.
  16. This is exactly what I was looking for. I found the addInformation event in another forum page but it looked a little like this @Override public void addInformation(ItemStack stack, EntityPlayer entityPlayer, List list, boolean par4){...} I'm not sure if this is an old version but this no longer works. Now I know it's addInformation, I just looked up Item#addInformation and it's completely different now @Override public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn){...} I'm assuming this is the way to add tooltips to already existing items, like vanilla items. Thanks for letting me know the differences and how to perform that way. P.S. Is changing colour of the text a flag or is it a little more complicated? Thanks.
  17. Trying to add a tooltip to an item, seen a couple topics about but nothing is really helping. I've got: public ModItem(){...} //Standard setup public void ItemTooltipEvent(ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, ITooltipFlag flags) { toolTip.add("This Is A ToolTip"); } //Not sure what I'm missing Like I'm asking, I know I'm missing something but not sure what. Any pointers are great and much appreciated. Thanks.
  18. Great, I knew it had something to do with player and EnumFacing but wasn't sure what else is was missing. Looks something like this: if(player.getHorizontalFacing == EnumFacing.NORTH || player.getHorizonalFacing == EnumFacing.SOUTH){...} //Likewise with West and East (For other people's referencing). Thanks guys, I know all of this is already in Forge and the declaration can be viewed in eclipse but sometimes it's so hard to know exactly what you're looking for that a few quick points like this is all you need. Thanks.
  19. Also while this topic is still open, how do I get the player facing direction so i can have something like if(player facing north or south){...} if(player facing east or west){...} I thought it was something to do with EnumFacing but that doesn't seem to be the case.
  20. Cheers guys! Got it working. I needed to use .add(x,y,z) in conjunction with .offset(facing) to achieve several blocks being placed at once. If anyone else sees this (and for clear clarification for what I was looking for) this is the code necessary to place multiple blocks. public static BlockPos pos1; //creates a variable for holding second BlockPos public EnumActionResult onItemUse(...){ //Standard setup pos = pos.offset(facing); //fetch the current BlockPos the player is facing pos1 = pos.add(1, 0, 0) //set BlockPos 1 to the right (east, x) worldIn.setBlockState(pos, ...); //set the block infront of player to whatever worldIn.setBlockSate(pos1, ...); //set the block to the new BlockPos position (i.e. 1 to the right) to whatever. Obviously use if(worldIn.isAirBlock(pos)){...} to test to see if the new location can have a block placed, otherwise without this a block will be replaced which is incorrect (unless that is what you're looking for). And do this every time you need to place a new block that is at offset to the original location. I hope this helps anyone else, I know it definitely did for me. Thanks.
  21. Hi I was wondering how to manipulate a BlockPos, i.e. add 1 to x or z But I'm not sure how to do this, I've got pos = pos.offset(facing); Inside onItemUse, which I know all works as this returns the x,y,z pos of the block. Say I have position BlockPos{x=20, y=40, z=-100}, how do I get this to say {x=20, y=40, z=101} for example. Thanks
  22. I assume this is still the case for 1.12.2, could someone link me the forge doc for this. Or at least an example and where this should be located. Thanks.
  23. Cheers, thanks for the advice. I'll be sure to keep an eye out for your series ✌?
  24. Ah no worries, got it working now. It's annoying not having two monitors to work on. Also is there anywhere else that has good documentation on forge modding, similar to Forgedocs but have more information on other classes like furnaces, crafting, mobs, etc etc.
  25. I'm trying to run Minecraft through eclipse for testing but it doesn't get very far before I get thrown back this error, and I just can't seem to figure out the issue through Google searches. I'll provide ModBlock class, Error Log and ClientProxy class along with one of the blocks I'm trying to create. I do however think the error is mainly being raised in the Client Proxy class but I can't tell what would cause it. Much Appreciated. P.S. Just thinking, is a loop being created by any chance between ModBlocks and ClientProxy? // Error Log java.lang.NullPointerException: Initializing game at com.github.theonepath.alchemical_construct.ModBlocks.initModels(ModBlocks.java:31) at com.github.theonepath.alchemical_construct.proxy.ClientProxy.registerModels(ClientProxy.java:51) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_ClientProxy_registerModels_ModelRegistryEvent.invoke(.dynamic) // After this I'm lost at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) at net.minecraftforge.fml.client.FMLClientHandler.fireSidedRegistryEvents(FMLClientHandler.java:1055) at net.minecraftforge.fml.common.FMLCommonHandler.fireSidedRegistryEvents(FMLCommonHandler.java:758) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:245) at net.minecraft.client.Minecraft.init(Minecraft.java:513) at net.minecraft.client.Minecraft.run(Minecraft.java:421) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:25) // ModBlocks class package com.github.theonepath.alchemical_construct; import com.github.theonepath.alchemical_construct.Main; import com.github.theonepath.alchemical_construct.blocks.*; import com.github.theonepath.alchemical_construct.blocks.bakedmodel.BakedModelBlock; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ModBlocks { @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:firstblock") public static FirstBlock firstBlock; @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:simpletexturedblock") public static SimpleTexturedBlock simpleTexturedBlock; @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:multitexturedblock") public static MultiTexturedBlock multiTexturedBlock; @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:modelblock") public static ModelBlock modelBlock; @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:bakedmodelblock") public static BakedModelBlock bakedModelBlock; @GameRegistry.ObjectHolder("com.github.theonepath.alchemical_construct:statetexturedblock") public static StateTexturedBlock stateTexturedBlock; @SideOnly(Side.CLIENT) public static void initModels() { simpleTexturedBlock.initModel(); multiTexturedBlock.initModel(); stateTexturedBlock.initModel(); modelBlock.initModel(); bakedModelBlock.initModel(); } @SideOnly(Side.CLIENT) public static void initItemModels() { bakedModelBlock.initItemModel(); } } // ClientProxy class package com.github.theonepath.alchemical_construct.proxy; import com.github.theonepath.alchemical_construct.ModBlocks; import com.github.theonepath.alchemical_construct.ModItems; import com.github.theonepath.alchemical_construct.Main; import com.github.theonepath.alchemical_construct.Reference; import com.github.theonepath.alchemical_construct.blocks.bakedmodel.BakedModelLoader; import com.github.theonepath.alchemical_construct.input.InputHandler; import com.github.theonepath.alchemical_construct.input.KeyBindings; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; @Mod.EventBusSubscriber(Side.CLIENT) public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); OBJLoader.INSTANCE.addDomain(Reference.MODID); ModelLoaderRegistry.registerLoader(new BakedModelLoader()); // Typically initialization of models and such goes here: //ModEntities.initModels(); } @Override public void init(FMLInitializationEvent e) { super.init(e); // Initialize our input handler so we can listen to keys MinecraftForge.EVENT_BUS.register(new InputHandler()); KeyBindings.init(); } @Override public void postInit(FMLPostInitializationEvent e) { super.postInit(e); ModBlocks.initItemModels(); } @SubscribeEvent public static void registerModels(ModelRegistryEvent event) { ModBlocks.initModels(); ModItems.initModels(); } } // FirstBlock class -- The Block To Be Created. package com.github.theonepath.alchemical_construct.blocks; import com.github.theonepath.alchemical_construct.Main; import com.github.theonepath.alchemical_construct.Reference; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; public class FirstBlock extends Block{ public FirstBlock() { super(Material.ROCK); setUnlocalizedName(Reference.MODID + ".firstblock"); setRegistryName("firstblock"); setCreativeTab(com.github.theonepath.alchemical_construct.Main.alchemicalConstructTab); } }
×
×
  • Create New...

Important Information

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