Jump to content

Koward

Forge Modder
  • Posts

    141
  • Joined

  • Last visited

Everything posted by Koward

  1. The method works when used in matches() but I think you're right, it's probably called on null in getRemainingItems() because the tool is probably already consumed but I don't know how to avoid it. I can avoid the crash by not calling the function when null (easy) but then I don't receive the tool at all, it's just plainly consume like the recipeItems. isTool() method : protected boolean isTool(ItemStack itemstack) { return ToolClass.isInstance(itemstack.getItem()); } Crash report : http://hastebin.com/tefukadada.vhdl I think my actual problem can therefore be resumed by : how to NOT consume an item while still keeping it as important in the matches() method.
  2. Hi ! I wanted to create a type of recipe that damages a tool you put in the crafting inventory. It's based on ShapelessRecipes. The tool should remain after crafting in the left part, but with -1 damage. For example, a sword and a zombie head gives rotten meat and the sword is damaged. The matches() works, but the getRemainingItems() has a problem. public ItemStack[] getRemainingItems(InventoryCrafting inv) { ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; for (int i = 0; i < aitemstack.length; ++i) { ItemStack itemstack = inv.getStackInSlot(i); if (isTool(itemstack)) itemstack.attemptDamageItem(1, new Random()); else aitemstack[i] = net.minecraftforge.common.ForgeHooks .getContainerItem(itemstack); } return aitemstack; } It crashes when trying to take the result. I know the error is in the lines if (isTool(itemstack)) itemstack.attemptDamageItem(1, new Random()); But I haven't managed to fix it. I think it has something to do with the tool being "consumed" along the recipeItems during the process, but the process itself is fairly magic. I don't know how the games know which items it should consume, there is no explicit method for that, as the getRemainingItems() just returns everything from the left area (except the tool in my method of course but it doesn't work).
  3. Don't worry I knew you wanted to write this one, I was already using the good statistic I don't know if there is a way to make reliable measurements but it looks like the time is in seconds (the ticks are probably divided when added to the stats, maybe to get lower numbers ?) but checking the source would be the only way to know for sure of course. Thanks a lot ! My problems are now solved.
  4. The values look a bit low to be game ticks, but you may be right, I should just do some tests.
  5. Clever, but if the game already does that for us I suppose it's better to use it. Worked perfectly, thank you. I don't know what is the time unit of this value, but I'll figure out by testing.
  6. Hi ! I'm trying to access the time since the last death of the player. I know it's somewhere with StatList.timeSinceDeathStat but I don't see any method that could indicate in which variables the time is stored. There isn't a lot of documentation about using the ingame stats for modding. If anyone knows how they work, I would be glad to learn.
  7. Thank you everyone. I was aware of the maxUse value but this one also makes the tool indestructible if you put it to 0 and gives two uses if you put it to 1. I found a "solution" with @SubscribeEvent public void onCrafting(ItemCraftedEvent event){ if(event.crafting.getItem() == ModItems.stupid_pickaxe) event.crafting.damageItem(1, event.player); } But I should try the 2 damage per block idea, that should be cleaner.
  8. Hi ! I decided to create a tool that can only be used once. The setMaxDamage(n) method allows a tool to be used n+1 times. But when n = 0, it makes the tool indestructible. (IMHO they should have assigned the negatives numbers to that, since n is an integer anyway.. but hey, there might be a reason) So I had to find another way. I tried using an event to damage the tool immediately when it's crafted : public class ToolsEventHandler { @SubscribeEvent public void onCrafting(ItemCraftedEvent event){ if(event.crafting.getItem() == ModItems.stupid_pickaxe) event.crafting.setItemDamage(0); } } But I do not see any effect. I registered this event on the FML bus and I do think it's the right one.. I could break the tool as soon as it hits a block with an event, but I do not know any method allowing that. Anyone has an elegant solution ? I hope I'm not asking here a stupid question.
  9. Thank you, that's very interesting. I'm not sure I understand this step, though : if (!canHarvest && f <= 1.0F) { f += f1 * 0.08F; } You're adding a diminished version of the enchantment speed, why ? Also, does this take in account the water, jumping and potions you mention in the comments or are they discarded, or does blockStrength() take care of that ? At the moment, my code crash the game as soon as I try to hit a block, but I find the problem is not too big. EDIT : float hardness = this.getBlockHardness(worldIn, pos); is the problem. EDIT 3 : Success ! Here is the latest version of my function : http://hastebin.com/takokuyawa.java It's basically a simple "If not the proper tool, then multiply the default speed by X" (Here X=1/3, not 0 so you can still break a block in a long time if you placed yours in front of you by mistake and you don't have any tool). Thank you a lot. EDIT 4 : Right now I have a bug, the breaking animation doesn't display on blocks anymore. All blocks. So I think it's unrelated, but I need to find where the Test client is to check as the "run" folder seems to not contain it entirely.
  10. I still haven't found a solution to this problem. BreakSpeed doesn't change the hardness, and getPlayerRelativeBlockHardness acts strangely. Try yourself, if you put @Override public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos) { return 5.5F; } In your Block, then it will have a 0.0F and not a 5.5F.
  11. Thanks jeffry, I would have never found that bug on my own.
  12. Now it crashed immediately. Here is the console of the session : http://hastebin.com/efuguvariz.vhdl I'm thinking to redesign the block as multiple blocks made of one class registered multiple times. The way vanilla Ores work, for example. It seems more suited when you want to define behaviours and not just simple "graphical" properties.
  13. Hi. I wanted a custom hardness for my blocks. But when I break the block, instant crash. All this blockstates thing is starting to look like a joke for me. Is it just good for anything but textures and models ? This is the problem function, in my custom Block class. I don't get it. Everything I did here is really simple, I can't see why it can't work. @Override public float getBlockHardness(World world, BlockPos pos) { int meta = this.getMetaFromState(world.getBlockState(pos)); switch (meta) { case 0: this.setHardness(3.0F); case 1: this.setHardness(4.5F); default: this.setHardness(1.5F); } return this.blockHardness; }
  14. Hi ! First of all, I use 1.8. When you override getHarvestLevel(), you set the minimum metal level to harvest something from the block. But previous level can still break the block (which don't drop anything but is still broken). I don't want it to happen. I would like to : Ideally, make the level beneath the required very slow to mine. Like breaking a stone with your hands. There should be a higher hardness difference between them. If not possible, forbid the lower levels to break the block at all. Some events could make it, but I wonder if there was a clean way to do it in the class of the block ?
  15. Solved. If anyone has the same problem : the method damageDropped() needs to be coherent with your dropped item. I had a standard damageDropped() returning the metadata (0 or 1). But I only dropped one item for all variants : Cobblestone. So I just set "return 0;" and now it works perfectly fine.
  16. Sure, here is a pastebin of my code : Custom Block itself : http://pastebin.com/C6NG6Nvd ; (I changed the drop to Diamond Block to check, and the problem is still there) A rendering class like explained in BedrockMiner's Tutorials : http://pastebin.com/HM1MAmdE ;
  17. As far as I know variants all call the same methods. Their specific behavior is defined inside methods checking their blockstate's metadata. Anyway, the item that is dropped by the second variant really IS Cobblestone : It's called Cobblestone, it stacks with all other Cobblestones and when placed it's a perfectly normal Cobblestone block. It's just that in inventory, it's texture is the Pink&Black. Therefore, unfortunately, a breakpoint there doesn't reveal anything.
  18. Hi ! During the creation of a custom block, I encountered a problem. The block itself works perfectly fine. But when you smash it in Survival, you're supposed to get Cobblestone like standard stone. It works but the Cobblestone item don't have its texture rendered when it's in item form. I chose Cobblestone with a simple I didn't know I would have to bother with this, as Cobblestone is a standard vanilla block. I have no idea why and how this can happen. Could anyone help me ? I do not see any error on the console. EDIT : Okay, it's even weirder. My custom block has two variants. Only the second one has this problem, the first (the default) is fine.
  19. And there is absolutely no way to create a Block with same ID but different metadata ? I understand new entry in registry => new ID, is that really the only way ? If only we could just add a line in the Enum.. Couldn't addSubstitutionAlias() be used for this purpose ? I never used it, so I don't know, and it looks like something bad, but the road to heaven is paved with bad practices or something like that.
  20. Oh, the fact that there is no "default in case of uninstalled mod" block yeah, I was referring to the fact we can't make a Block with only small property changes just by "extending" and overriding the previous one without any problem (keeping most original properties), or at least not in the vanilla way. If I'm completely wrong don't hesitate to tell me to get out check whatever documentation. I don't want to waste your time.
  21. That's so disappointing. It should be made. The amount of code redundance (for a simple different color wood by example) is huge. Anyway, thank you for you answer.
  22. Exactly. When possible, if possible, that should be avoided by replacing the block with a vanilla one. You can't tell me there is no way to do that. It seems so logical.
  23. Really ? But that's stupid. What's the point of the whole BlockState concepts then if it's not to allow easy use of variants ? And what will happen when I will uninstall the mod ? I was hoping this method would allow easy reverse into the DefaultState that is specified in the BlockPlanks class.
  24. Hi ! I decided yesterday to learn the way Minecraft handles block variants. Wood, wool... As an experiment, I decided to create a new type of Wood Plank, an "hard" wood. It would be harder and have a bricky-woody texture. I wanted to create a custom state with the new ExtendedBlockState.createState() from net.minecraftforge.common.property. But it seems that works to changes states or compare when the state already exists initially in the block, which is obviously not the case here. So I decided to check the metadata. But it wouldn't work because I can't access the META_LOOKUP array of EnumType. So tried another approach. And I ended up with Block HardWood = (new BlockPlanks()).setHardness(1.5F).setResistance(10.0F).setStepSound(Block.soundTypePiston).setUnlocalizedName("hardWood"); GameRegistry.registerBlock(HardWood, "hard_wood"); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(HardWood), 6, new ModelResourceLocation("stratification:hard_wood", "inventory")); But it doesn't work either. I'm sure there is something I miss here.
  25. I will try this as soon as possible. It seems I wasn't looking at the right classes at all. I'm such a noob. Thank you, Ernio.
×
×
  • Create New...

Important Information

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