Search in sources :

Example 1 with ItemStackList

use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.

the class MessageToggleChaosGem method handleMessage.

@Override
public IMessage handleMessage(MessageContext context) {
    if (context.side != Side.SERVER)
        return null;
    EntityPlayer player = context.getServerHandler().player;
    Predicate<ItemStack> predicate = s -> s.getItem() instanceof ItemChaosGem;
    ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
    stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
    for (ItemStack stack : stacks) {
        if (stack.getItem() instanceof ItemChaosGem) {
            ItemChaosGem item = (ItemChaosGem) stack.getItem();
            item.setEnabled(stack, !item.isEnabled(stack));
            if (item.isEnabled(stack))
                item.applyEffects(stack, player);
            else
                item.removeEffects(stack, player);
            if (!all)
                return null;
        }
    }
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) Predicate(com.google.common.base.Predicate) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) Message(net.silentchaos512.gems.network.Message) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) BaublesCompat(net.silentchaos512.gems.compat.BaublesCompat) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemChaosGem(net.silentchaos512.gems.item.ItemChaosGem) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemStackList

use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.

the class RecipeMixedMaterialItem method getMaterials.

protected ItemStackList getMaterials(InventoryCrafting inv) {
    ItemStackList list = ItemStackList.create();
    for (int i = 0; i < inv.getSizeInventory(); ++i) {
        ItemStack stack = inv.getStackInSlot(i);
        ToolPart part = ToolPartRegistry.fromStack(stack);
        if (part != null && !part.isBlacklisted(stack) && part instanceof ToolPartMain) {
            list.add(stack);
        }
    }
    return list;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemStackList

use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.

the class RecipeMixedMaterialItem method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    if (!partTiersMatch(inv)) {
        return StackHelper.empty();
    }
    ItemStack rod = getRod(inv);
    ItemStack frame = getFrame(inv);
    ItemStackList materials = getMaterials(inv);
    ItemStack[] array = materials.toArray(new ItemStack[materials.size()]);
    if (toolItem instanceof ITool)
        return ((ITool) toolItem).constructTool(rod, array);
    if (toolItem instanceof IArmor)
        return ((IArmor) toolItem).constructArmor(frame, array);
    return StackHelper.empty();
}
Also used : ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 4 with ItemStackList

use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.

the class NodeEffect method applyToEntity.

public boolean applyToEntity(EntityLivingBase entity, Random random, boolean allowSounds) {
    if (random.nextFloat() > successChance || !needsEffect(entity)) {
        return false;
    }
    if (this == ATTACK) {
        if (!entity.world.isRemote)
            entity.attackEntityFrom(ModDamageSource.NODE_ATTACK, (float) (4.0f + 0.75f * random.nextGaussian()));
        return true;
    } else if (this == REPAIR) {
        // Repair damaged items.
        if (!(entity instanceof EntityPlayer))
            return false;
        EntityPlayer player = (EntityPlayer) entity;
        int amount = (int) (10 + 2 * random.nextGaussian());
        ItemStack stackToRepair = null;
        // Select a random item.
        ItemStackList items = PlayerHelper.getNonEmptyStacks(player);
        items.removeIf(stack -> !canRepair(stack));
        if (items.size() > 0) {
            stackToRepair = items.get(random.nextInt(items.size()));
        }
        if (stackToRepair != null) {
            ItemHelper.attemptDamageItem(stackToRepair, (int) -amount, random, player);
            if (allowSounds)
                entity.world.playSound(null, entity.getPosition(), SoundEvents.BLOCK_ANVIL_USE, SoundCategory.BLOCKS, 0.5f, 2.0f + (float) (0.2 * random.nextGaussian()));
            return true;
        }
        return false;
    } else if (this == SATURATION) {
        // Saturation. Not using the potion effect, just restore some hunger directly.
        if (!(entity instanceof EntityPlayer))
            return false;
        EntityPlayer player = (EntityPlayer) entity;
        player.getFoodStats().addStats(2, 0.1f);
        if (allowSounds)
            entity.world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.BLOCKS, 0.5f, 1.2f + (float) (0.05 * random.nextGaussian()));
        return true;
    } else if (this instanceof NodeEffectPotion) {
        // General potion effect handler.
        NodeEffectPotion effect = (NodeEffectPotion) this;
        int duration = effect.durationMin + random.nextInt(effect.durationMax - effect.durationMin + 1);
        entity.addPotionEffect(new PotionEffect(effect.potion, duration, effect.amplifier));
        return true;
    }
    SilentGems.logHelper.warning("Potentially unknown node effect: " + key);
    return false;
}
Also used : ModDamageSource(net.silentchaos512.gems.util.ModDamageSource) SoundEvents(net.minecraft.init.SoundEvents) GemsConfig(net.silentchaos512.gems.config.GemsConfig) Random(java.util.Random) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) DamageSource(net.minecraft.util.DamageSource) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) PotionEffect(net.minecraft.potion.PotionEffect) List(java.util.List) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SilentGems(net.silentchaos512.gems.SilentGems) SoundCategory(net.minecraft.util.SoundCategory) MobEffects(net.minecraft.init.MobEffects) ItemHelper(net.silentchaos512.lib.util.ItemHelper) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) PotionEffect(net.minecraft.potion.PotionEffect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ItemStackList

use of net.silentchaos512.lib.collection.ItemStackList in project SilentGems by SilentChaos512.

the class MessageKeyReturnHome method handleMessage.

@Override
public IMessage handleMessage(MessageContext ctx) {
    if (ctx.side != Side.SERVER)
        return null;
    Predicate<ItemStack> predicate = s -> s.getItem() == ModItems.returnHomeCharm;
    EntityPlayer player = ctx.getServerHandler().player;
    ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
    stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
    if (stacks.isEmpty())
        return null;
    ModItems.returnHomeCharm.tryTeleportPlayer(stacks.get(0), player);
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) ModItems(net.silentchaos512.gems.init.ModItems) Predicate(com.google.common.base.Predicate) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) Message(net.silentchaos512.gems.network.Message) PlayerHelper(net.silentchaos512.lib.util.PlayerHelper) BaublesCompat(net.silentchaos512.gems.compat.BaublesCompat) ItemStackList(net.silentchaos512.lib.collection.ItemStackList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)6 ItemStackList (net.silentchaos512.lib.collection.ItemStackList)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 PlayerHelper (net.silentchaos512.lib.util.PlayerHelper)3 Predicate (com.google.common.base.Predicate)2 IMessage (net.minecraftforge.fml.common.network.simpleimpl.IMessage)2 MessageContext (net.minecraftforge.fml.common.network.simpleimpl.MessageContext)2 Side (net.minecraftforge.fml.relauncher.Side)2 BaublesCompat (net.silentchaos512.gems.compat.BaublesCompat)2 Message (net.silentchaos512.gems.network.Message)2 IBaublesItemHandler (baubles.api.cap.IBaublesItemHandler)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 MobEffects (net.minecraft.init.MobEffects)1 SoundEvents (net.minecraft.init.SoundEvents)1 PotionEffect (net.minecraft.potion.PotionEffect)1 DamageSource (net.minecraft.util.DamageSource)1 SoundCategory (net.minecraft.util.SoundCategory)1