mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Make Phantomfaces only actually support the capabilities they advertise
This commit is contained in:
parent
7b4e5f9c46
commit
7ff81ad637
5 changed files with 29 additions and 3 deletions
|
@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
|
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
|
|
||||||
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ISharingEnergyProvider{
|
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ISharingEnergyProvider{
|
||||||
|
@ -44,6 +45,11 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCapabilitySupported(Capability<?> capability){
|
||||||
|
return capability == CapabilityEnergy.ENERGY || capability == TeslaUtil.teslaHolder || capability == TeslaUtil.teslaConsumer || capability == TeslaUtil.teslaProducer;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyToSplitShare(){
|
public int getEnergyToSplitShare(){
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
|
||||||
public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
||||||
|
@ -43,6 +44,11 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCapabilitySupported(Capability<?> capability){
|
||||||
|
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtractItem(int slot, ItemStack stack){
|
public boolean canExtractItem(int slot, ItemStack stack){
|
||||||
return this.isBoundThingInRange();
|
return this.isBoundThingInRange();
|
||||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
|
||||||
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler{
|
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler{
|
||||||
|
@ -37,6 +38,11 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCapabilitySupported(Capability<?> capability){
|
||||||
|
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFluidAmountToSplitShare(){
|
public int getMaxFluidAmountToSplitShare(){
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -61,4 +62,9 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface{
|
||||||
|
|
||||||
super.onUpdateSent();
|
super.onUpdateSent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCapabilitySupported(Capability<?> capability){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile{
|
public abstract class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile{
|
||||||
|
|
||||||
public static final int RANGE = 16;
|
public static final int RANGE = 16;
|
||||||
public BlockPos boundPosition;
|
public BlockPos boundPosition;
|
||||||
|
@ -170,9 +170,11 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
|
||||||
return this.range;
|
return this.range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract boolean isCapabilitySupported(Capability<?> capability);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
|
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
|
||||||
if(this.isBoundThingInRange()){
|
if(this.isBoundThingInRange() && this.isCapabilitySupported(capability)){
|
||||||
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
||||||
if(tile != null){
|
if(tile != null){
|
||||||
return tile.hasCapability(capability, facing);
|
return tile.hasCapability(capability, facing);
|
||||||
|
@ -183,7 +185,7 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
|
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
|
||||||
if(this.isBoundThingInRange()){
|
if(this.isBoundThingInRange() && this.isCapabilitySupported(capability)){
|
||||||
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
TileEntity tile = this.world.getTileEntity(this.getBoundPosition());
|
||||||
if(tile != null){
|
if(tile != null){
|
||||||
return tile.getCapability(capability, facing);
|
return tile.getCapability(capability, facing);
|
||||||
|
|
Loading…
Reference in a new issue