Jump to content

Recommended Posts

Posted (edited)

My custom furnace uses the input in milliseconds but doesn't make output. Also it doesn't drop container item when destroyed.  (I watched HarryTalks' tutorial)

The code is here:

Block Class

  Reveal hidden contents

TileEntity Class

  Reveal hidden contents

Container class

  Reveal hidden contents

GUI class

  Reveal hidden contents

Recipe class

  Reveal hidden contents

 

Sorry for my bad english

Edited by hyper1423
Solved
Posted (edited)
  On 6/22/2019 at 3:07 PM, diesieben07 said:
  • Code style, issue 4.
  • Problematic code, issue 4, 9 (BlastFurnace#currentFuel).
  • This is why you use constants instead of hard-coding strings everywhere.
     

     

     

Expand  
  Quote

4. Do not use ITileEntityProvider or BlockContainer. These classes are legacy vanilla code. To add a TileEntity to your Block, override hasTileEntity and createTileEntity in your Block class. 

Expand  

Should I override it like this?

  Reveal hidden contents
  Quote

9. Any IForgeRegistryEntry (commonly items and blocks) is singleton-like. That means that there is only once instance of your block class. There is not a new Block instance for every position in the world and there is not a new Item instance for every ItemStack. This means that you cannot store position-related things as instance fields in your block class, etc. You must use a TileEntity resp. the NBT data on ItemStack.

Expand  

Are you saying to remove BlastFurnace.currentFuel?

  Quote

4. Do not abuse inheritance for code-reuse. This often manifests in classes like ItemBase, BaseItem or ItemExampleMod. Using this pattern prevents you from extending other essential classes, such as ItemFood and in that case requires code duplication. Prefer composition or utility methods instead to reuse code.

Expand  

What do you mean? Should I remove BlockBase class and add methods in the BlockBase class in each block classes?

  On 6/22/2019 at 3:07 PM, diesieben07 said:
  • This is why you use constants instead of hard-coding strings everywhere.
Expand  

I changed TileEntity Like This:

  Reveal hidden contents

I made constants and removed hard-coding on readFromNBT and writeToNBT.

Edited by hyper1423
Posted

It seems like you are following HarryTalks’ tutorials. Stop.

His tutorials are terrible as they use outdated code and promote bad practices.

Some tips:

  Reveal hidden contents

 

Posted (edited)
  On 6/23/2019 at 3:49 AM, hyper1423 said:

Should I override it like this?

  Reveal hidden contents
Expand  

No, because the super class does not return useful values. You need to return the correct values.

 

  Quote

Are you saying to remove BlastFurnace.currentFuel?

Expand  

Yes. Blocks cannot store data. Block classes are singleton instances, meaning that the data is shared across all blocks of that type. That's why you have a TileEntity for per-location specific data.

  Quote

What do you mean? Should I remove BlockBase class and add methods in the BlockBase class in each block classes?

Expand  

Yes, essentially. There is already a "base block class" its called Block.

  Quote

I changed TileEntity Like This:

  Reveal hidden contents

I made constants and removed hard-coding on readFromNBT and writeToNBT.

Expand  

"CustomName" is still a hard-coded string. And also a bad name.

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 6/23/2019 at 4:21 AM, hyper1423 said:

Should I rewrite the whole code?

Expand  

Personally, I would say yes.

i.e. All the custom name part are completely not necessary, and the getField/setField with an id is pointless. use normal getters and setters instead.

Some tips:

  Reveal hidden contents

 

Posted

Changing code caused another problem. It does not open GUI.

  Reveal hidden contents

These are the codes:

Block class:

  Reveal hidden contents

TileEntity class:

  Reveal hidden contents

Recipe class:

  Reveal hidden contents

GUI class:

  Reveal hidden contents

And container class:

  Reveal hidden contents

 

Also, when I shift-rightclick on the blast furnace, it just change its direction and no block is added.

  Reveal hidden contents

 

Posted (edited)
  On 6/23/2019 at 11:51 AM, diesieben07 said:
  • This will always return null, since your TE does not expose the ITEM_HANDLER_CAPABILITY.
Expand  

How do I expose ITEM_HANDLER_CAPABILITY? I tried to expose it as the way in the official forge tutorial, but it doesn't work.

 

TileEntity:

  Reveal hidden contents

Block:

  Reveal hidden contents

Other classes are not changed.

Edited by hyper1423
Posted (edited)
  Reveal hidden contents

Here it is.

Edited by hyper1423
Posted
  Reveal hidden contents

 

Posted (edited)
  On 6/29/2019 at 9:50 AM, diesieben07 said:

The version of hasTileEntity you are using is deprecated. Do not just ignore deprecations.

Expand  

Which hasTileEntity do you mean?

Ok, I changed hasTileEntity to the version that is not deprecated.

EDIT: It still doesn't open.

Edited by hyper1423
Posted (edited)

I found that BlastFurnace.hasTileEntity is false and Minecraft does not call BlastFurnace.createTileEntity(World world, IBlockState state). I guess my TileEntity isn't registered correctly.

Edited by hyper1423
Posted

You are supposed to override Block#hasTIleEntity.

  • Like 1

Some tips:

  Reveal hidden contents

 

Posted (edited)

Thank you!!!!!!! It works!!! But it still does not cook item, and use an item in a tick.

EDIT: I fixed it. I changed the code like this:

  Reveal hidden contents

and it works. Thanks to everyone who helped me.

Edited by hyper1423

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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