Jump to content

[1.11.2] [UNSOLVED] TileEntity getCapability for specific sides


Bektor

Recommended Posts

Hi,

 

I've got the problem that I've got a base class for all energy related tile entities which defines the basic capability handling of

all my tile entities which implement energy.

 

abstract Class A extends TileEntity:

    @Override
    public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
        T cap = this.container.getCapability(capability, facing);
        
        return cap != null ? cap : super.getCapability(capability, facing); 
    }

 

The problem is, one of my tile entities requires the capability to be returned at a specific side and not for every side.

Class B extends abstract class A

 

  • parent class A defines to output capability at all sides
  • subclass B should only output capability at a specific side

 

Which would be the most efficient way of doing this?

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

6 minutes ago, diesieben07 said:

Make a method getExposedSides in your base class, which by default returns EnumSet.allOf(EnumFacing.class). Then you can customize that in subclasses.

If I recall correclty, you wrote once that EnumSet doesn't include the null side.

Wouldn't this lead to problems with for example HWYLA and other mods?

(the HWYLA doc states: Information is obtained using a null facing. Mods that do not handle this correctly are unsupported.)

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

17 minutes ago, Bektor said:

If I recall correclty, you wrote once that EnumSet doesn't include the null side.

Wouldn't this lead to problems with for example HWYLA and other mods?

(the HWYLA doc states: Information is obtained using a null facing. Mods that do not handle this correctly are unsupported.)

So? Just handle null parameter then. By them saying they obtain it using a null facing presumably means they call some methods and or look at block state files with null as a parameter. You can handle null how you want -- pass back information from whatever you consider the main side, or whatever you consider the current side, etc.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

On 10/16/2017 at 5:19 PM, jabelar said:

So? Just handle null parameter then. By them saying they obtain it using a null facing presumably means they call some methods and or look at block state files with null as a parameter. You can handle null how you want -- pass back information from whatever you consider the main side, or whatever you consider the current side, etc.

I've got this implementation right now, thought when I return just EnumSet.of(EnumFacing.DOWN) instead of the default list, it won't work, meaning that for example HWYLA won't display my stored energy for those blocks.

 

    protected EnumSet<EnumFacing> getExposedSides() {
        EnumSet<EnumFacing> facing = EnumSet.allOf(EnumFacing.class);
        return facing;
    }
    
    @Override
    public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
        T cap = this.container.getCapability(capability, facing);
        
        boolean flag = facing == null ? (this.getExposedSides().size() > 0 ? true : false) : this.getExposedSides().contains(facing);
        return cap != null && flag ? cap : super.getCapability(capability, facing); 
    }
    
    @Override
    public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
        boolean flag = facing == null ? (this.getExposedSides().size() > 0 ? true : false) : this.getExposedSides().contains(facing);
        return (flag && this.container.hasCapability(capability, facing)) || 
                super.hasCapability(capability, facing);
    }

To

  • check if the side (facing) is null
  • and the capability isn't null

 

in order to return the capability then won't solve the problem while hasCapability checks

  • if the tileentity has the capability
  • and if facing == null

to then return true.

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

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.