Last active
August 1, 2017 09:47
-
-
Save Xalcon/9a6473329b50965674b4c59f7886ec07 to your computer and use it in GitHub Desktop.
Adds the lingering potions as a bauble to Baubles (Needs capability feature! https://github.com/Xalcon/Baubles/tree/feature/bauble_capability)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package baubles.common; | |
import baubles.api.BaubleType; | |
import baubles.api.IBauble; | |
import baubles.api.cap.BaubleItem; | |
import baubles.api.cap.BaublesCapabilities; | |
import baubles.common.Baubles; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.init.Items; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.potion.PotionEffect; | |
import net.minecraft.potion.PotionUtils; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.common.capabilities.Capability; | |
import net.minecraftforge.common.capabilities.ICapabilityProvider; | |
import net.minecraftforge.event.AttachCapabilitiesEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
import javax.annotation.Nonnull; | |
import javax.annotation.Nullable; | |
@Mod.EventBusSubscriber(modid = Baubles.MODID) | |
public class PotionBaubles | |
{ | |
private final static ResourceLocation capabilityResourceLocation = new ResourceLocation(Baubles.MODID, "potion_cap"); | |
@SubscribeEvent | |
public static void potionCapabilityAttach(AttachCapabilitiesEvent<ItemStack> event) | |
{ | |
ItemStack stack = event.getObject(); | |
if(stack.getItem() != Items.LINGERING_POTION) | |
return; | |
event.addCapability(capabilityResourceLocation, new ICapabilityProvider() { | |
private IBauble bauble = new BaubleItem(BaubleType.CHARM) | |
{ | |
@Override | |
public void onWornTick(ItemStack itemstack, EntityLivingBase player) | |
{ | |
if(player.ticksExisted % 20 ==0 ) | |
{ | |
for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack)) | |
{ | |
if (!potioneffect.getPotion().isInstant()) | |
{ | |
player.addPotionEffect(new PotionEffect(new PotionEffect(potioneffect.getPotion(), | |
30, potioneffect.getAmplifier(), true, false))); | |
} | |
} | |
} | |
} | |
}; | |
@Override | |
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) | |
{ | |
return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE; | |
} | |
@Nullable | |
@Override | |
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) | |
{ | |
return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE | |
? BaublesCapabilities.CAPABILITY_ITEM_BAUBLE.cast(bauble) | |
: null; | |
} | |
} ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment