Posted October 16, 20178 yr 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.
October 16, 20178 yr Author 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 October 16, 20178 yr by Bektor Developer of Primeval Forest.
October 16, 20178 yr 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/
October 16, 20178 yr Author 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 October 18, 20178 yr by Bektor Developer of Primeval Forest.
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.