Search in sources :

Example 11 with CapturedMob

use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.

the class SoulBinderRecipeCategory method setRecipe.

@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull SoulBinderRecipeCategory.SoulBinderRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) {
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    IGuiIngredientGroup<EnergyIngredient> group = recipeLayout.getIngredientsGroup(EnergyIngredient.class);
    guiItemStacks.init(0, true, 37 - xOff, 33 - yOff);
    guiItemStacks.init(1, true, 58 - xOff, 33 - yOff);
    guiItemStacks.init(2, false, 111 - xOff, 33 - yOff);
    guiItemStacks.init(3, false, 133 - xOff, 33 - yOff);
    group.init(xOff, true, EnergyIngredientRenderer.INSTANCE, 5, 35, 60, 10, 0, 0);
    guiItemStacks.set(ingredients);
    IFocus<?> focus = recipeLayout.getFocus();
    if (focus != null && focus.getMode() == Mode.INPUT && focus.getValue() instanceof ItemStack && ((ItemStack) focus.getValue()).getItem() == itemSoulVial.getItemNN() && CapturedMob.containsSoul(((ItemStack) focus.getValue())) && ingredients.getOutputs(ItemStack.class).get(1).size() > 1) {
        // we are focused on a filled soul vial on the input side and the output has a list
        final CapturedMob vialMob = CapturedMob.create(((ItemStack) focus.getValue()));
        if (vialMob != null) {
            List<ItemStack> newOutputs = new ArrayList<>();
            for (ItemStack output : ingredients.getOutputs(ItemStack.class).get(1)) {
                if (output != null && vialMob.isSameType(CapturedMob.create(output))) {
                    newOutputs.add(output);
                }
            }
            guiItemStacks.set(3, newOutputs);
        }
    }
    if (focus != null && focus.getMode() == Mode.OUTPUT && focus.getValue() instanceof ItemStack && CapturedMob.containsSoul(((ItemStack) focus.getValue())) && ingredients.getInputs(ItemStack.class).get(0).size() > 1 && ingredients.getOutputs(ItemStack.class).get(1).size() > 1) {
        // we are focused on a output item and the both sides have a list
        final CapturedMob resultMob = CapturedMob.create(((ItemStack) focus.getValue()));
        if (resultMob != null) {
            List<ItemStack> newInputs = new ArrayList<>();
            for (ItemStack input : ingredients.getInputs(ItemStack.class).get(0)) {
                if (input != null && resultMob.isSameType(CapturedMob.create(input))) {
                    newInputs.add(input);
                }
            }
            guiItemStacks.set(0, newInputs);
            guiItemStacks.set(3, ((ItemStack) focus.getValue()));
        }
    }
    group.set(ingredients);
}
Also used : EnergyIngredient(crazypants.enderio.base.integration.jei.energy.EnergyIngredient) CapturedMob(crazypants.enderio.util.CapturedMob) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 12 with CapturedMob

use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.

the class AbstractSoulBinderRecipe method isValidInput.

@Override
public boolean isValidInput(@Nonnull MachineRecipeInput input) {
    if (Prep.isInvalid(input.item)) {
        return false;
    }
    int slot = input.slotNumber;
    ItemStack item = input.item;
    if (slot == 0) {
        CapturedMob mobType = CapturedMob.create(item);
        return mobType != null && item.getItem() == itemSoulVial.getItem() && isValidInputSoul(mobType);
    }
    if (slot == 1) {
        return isValidInputItem(item);
    }
    return false;
}
Also used : CapturedMob(crazypants.enderio.util.CapturedMob) ItemStack(net.minecraft.item.ItemStack)

Example 13 with CapturedMob

use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.

the class ItemSoulVial method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack item, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
    if (entity.world.isRemote) {
        return false;
    }
    boolean isCreative = player.capabilities.isCreativeMode;
    if (CapturedMob.containsSoul(item) && !isCreative) {
        return false;
    }
    // first check if that entity can be picked up at all
    CapturedMob capturedMob = CapturedMob.create(entity);
    if (capturedMob == null) {
        if (entity instanceof EntityPlayer) {
            player.sendMessage(Lang.SOUL_VIAL_DENIED_PLAYER.toChatServer());
        } else if (CapturedMob.isBlacklisted(entity)) {
            player.sendMessage(Lang.SOUL_VIAL_DENIED_AALISTED.toChatServer());
        }
        return false;
    }
    // then check for reasons this specific one cannot
    if (entity instanceof IEntityOwnable && ((IEntityOwnable) entity).getOwnerId() != null && !player.equals(((IEntityOwnable) entity).getOwner()) && !PermissionAPI.hasPermission(player.getGameProfile(), permissionPickupOwned, new TargetContext(player, entity))) {
        player.sendMessage(Lang.SOUL_VIAL_DENIED_OWNED_PET.toChatServer());
        return false;
    }
    if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPickup, new TargetContext(player, entity))) {
        player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
        return false;
    }
    ItemStack capturedMobVessel = capturedMob.toStack(this, 1, 1);
    player.swingArm(hand);
    if (!isCreative) {
        entity.setDead();
        if (entity.isDead) {
            // So we do not shrink the stack when it is 1.
            if (item.getCount() > 1) {
                item.shrink(1);
                // Since this stack still exists, add the new vial to the first location, or drop
                if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
                    player.dropItem(capturedMobVessel, false);
                }
            } else {
                // Otherwise, just replace the stack
                player.setHeldItem(hand, capturedMobVessel);
            }
            player.inventoryContainer.detectAndSendChanges();
            return true;
        }
    } else {
        if (!player.inventory.addItemStackToInventory(capturedMobVessel)) {
            player.dropItem(capturedMobVessel, false);
        }
        player.inventoryContainer.detectAndSendChanges();
        return true;
    }
    return false;
}
Also used : CapturedMob(crazypants.enderio.util.CapturedMob) TargetContext(net.minecraftforge.server.permission.context.TargetContext) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IEntityOwnable(net.minecraft.entity.IEntityOwnable) ItemStack(net.minecraft.item.ItemStack)

Example 14 with CapturedMob

use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.

the class BrokenSpawnerHandler method onBreakEvent.

@SubscribeEvent
public static void onBreakEvent(BlockEvent.BreakEvent evt) {
    if (evt.getState().getBlock() instanceof BlockMobSpawner) {
        if (evt.getPlayer() != null && !evt.getPlayer().capabilities.isCreativeMode && !evt.getPlayer().world.isRemote && !evt.isCanceled()) {
            TileEntity tile = evt.getPlayer().world.getTileEntity(NullHelper.notnullF(evt.getPos(), "BlockEvent.BreakEvent.getPos()"));
            if (tile instanceof TileEntityMobSpawner) {
                if (Math.random() > BrokenSpawnerConfig.brokenSpawnerDropChance.get()) {
                    return;
                }
                ItemStack equipped = evt.getPlayer().getHeldItemMainhand();
                if (Prep.isValid(equipped) && BrokenSpawnerConfig.brokenSpawnerToolBlacklist.get().contains(equipped)) {
                    return;
                }
                TileEntityMobSpawner spawner = (TileEntityMobSpawner) tile;
                MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
                ResourceLocation entityName = getEntityName(logic);
                if (entityName != null && !isBlackListed(entityName)) {
                    final CapturedMob capturedMob = CapturedMob.create(entityName);
                    if (capturedMob != null) {
                        ItemStack drop = capturedMob.toStack(ModObject.itemBrokenSpawner.getItemNN(), 0, 1);
                        dropCache.put(evt.getPos().toImmutable(), drop);
                        for (int i = (int) (Math.random() * 7); i > 0; i--) {
                            setSpawnDelay(logic);
                            logic.updateSpawner();
                        }
                    } else {
                        dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
                    }
                }
            }
        } else {
            dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MobSpawnerBaseLogic(net.minecraft.tileentity.MobSpawnerBaseLogic) BlockMobSpawner(net.minecraft.block.BlockMobSpawner) CapturedMob(crazypants.enderio.util.CapturedMob) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with CapturedMob

use of crazypants.enderio.util.CapturedMob in project EnderIO by SleepyTrousers.

the class BrokenSpawnerHandler method onHarvestDropsEvent.

@SubscribeEvent
public static void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent evt) {
    if (!evt.isCanceled() && evt.getState().getBlock() instanceof BlockMobSpawner) {
        if (dropCache.containsKey(evt.getPos())) {
            ItemStack stack = dropCache.get(evt.getPos());
            if (Prep.isValid(stack)) {
                evt.getDrops().add(stack);
                dropCache.put(evt.getPos().toImmutable(), Prep.getEmpty());
            }
        } else {
            // invalidated already, but we might be able to recover it.
            try {
                for (Object object : evt.getWorld().loadedTileEntityList) {
                    if (object instanceof TileEntityMobSpawner) {
                        TileEntityMobSpawner spawner = (TileEntityMobSpawner) object;
                        BlockPos p = spawner.getPos();
                        if (spawner.getWorld() == evt.getWorld() && p.equals(evt.getPos())) {
                            // Bingo!
                            MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
                            ResourceLocation entityName = getEntityName(logic);
                            if (entityName != null && !isBlackListed(entityName)) {
                                final CapturedMob capturedMob = CapturedMob.create(entityName);
                                if (capturedMob != null) {
                                    evt.getDrops().add(capturedMob.toStack(ModObject.itemBrokenSpawner.getItemNN(), 0, 1));
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
            // Risky recovery failed. Happens.
            }
        }
    }
}
Also used : MobSpawnerBaseLogic(net.minecraft.tileentity.MobSpawnerBaseLogic) BlockMobSpawner(net.minecraft.block.BlockMobSpawner) CapturedMob(crazypants.enderio.util.CapturedMob) ResourceLocation(net.minecraft.util.ResourceLocation) ModObject(crazypants.enderio.base.init.ModObject) BlockPos(net.minecraft.util.math.BlockPos) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CapturedMob (crazypants.enderio.util.CapturedMob)15 ItemStack (net.minecraft.item.ItemStack)9 ResourceLocation (net.minecraft.util.ResourceLocation)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 Nonnull (javax.annotation.Nonnull)3 BlockMobSpawner (net.minecraft.block.BlockMobSpawner)2 MobSpawnerBaseLogic (net.minecraft.tileentity.MobSpawnerBaseLogic)2 TileEntityMobSpawner (net.minecraft.tileentity.TileEntityMobSpawner)2 DyeColor (com.enderio.core.common.util.DyeColor)1 InvalidRecipeConfigException (crazypants.enderio.base.config.recipes.InvalidRecipeConfigException)1 ModObject (crazypants.enderio.base.init.ModObject)1 EnergyIngredient (crazypants.enderio.base.integration.jei.energy.EnergyIngredient)1 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)1 ArrayList (java.util.ArrayList)1 IGuiItemStackGroup (mezz.jei.api.gui.IGuiItemStackGroup)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 IEntityOwnable (net.minecraft.entity.IEntityOwnable)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1