Skip to content

Instantly share code, notes, and snippets.

@loordgek
Created November 8, 2017 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loordgek/bb6b9822d9ddadac09ac9af6e5c96de0 to your computer and use it in GitHub Desktop.
Save loordgek/bb6b9822d9ddadac09ac9af6e5c96de0 to your computer and use it in GitHub Desktop.
package loordgek.itemhandlerv2.test;
import loordgek.itemhandlerv2.CapbilityItemHandler;
import loordgek.itemhandlerv2.wrappers.InvWrapper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class CapPlayerProvider implements ICapabilityProvider {
private final EntityPlayer player;
private InvWrapper playerinv;
public CapPlayerProvider(EntityPlayer player) {
this.player = player;
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
if (playerinv == null){
playerinv = new InvWrapper(player.inventory);
}
return capability == CapbilityItemHandler.ITEM_HANDLER_CAPABILITY;
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (playerinv == null){
playerinv = new InvWrapper(player.inventory);
}
return capability == CapbilityItemHandler.ITEM_HANDLER_CAPABILITY ? CapbilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerinv) : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment