Search in sources :

Example 6 with NonNullList

use of net.minecraft.util.NonNullList in project Skree by Skelril.

the class GoldRushListener method onPlayerInteractEvent.

@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    GoldRushInstance inst = optInst.get();
    BlockSnapshot snapshot = event.getTargetBlock();
    BlockState state = snapshot.getState();
    if (!snapshot.getLocation().isPresent()) {
        return;
    }
    Location<World> targetBlock = snapshot.getLocation().get();
    if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
        Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
        if (!optTileEnt.isPresent()) {
            return;
        }
        TileEntity tileEntity = optTileEnt.get();
        Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
        if (!optTexts.isPresent()) {
            return;
        }
        List<Text> texts = optTexts.get();
        boolean unlocked = false;
        String text = texts.get(1).toPlain().toLowerCase();
        NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
        for (int i = 0; i < itemStacks.size(); ++i) {
            ItemStack is = itemStacks.get(i);
            if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
                continue;
            }
            if (text.contains("blue")) {
                if (is.getItemDamage() != 1) {
                    continue;
                }
            } else if (text.contains("red")) {
                if (is.getItemDamage() != 0) {
                    continue;
                }
            } else {
                continue;
            }
            unlocked = true;
            itemStacks.set(i, ItemStack.EMPTY);
            break;
        }
        if (unlocked) {
            tf(player).inventoryContainer.detectAndSendChanges();
            texts.set(2, Text.of("Locked"));
            texts.set(3, Text.of("- Unlocked -"));
            tileEntity.offer(Keys.SIGN_LINES, texts);
        }
    } else if (state.getType() == BlockTypes.LEVER) {
        Task.builder().execute(() -> {
            if (inst.checkLevers()) {
                inst.completeGame();
            }
        }).delayTicks(1).submit(SkreePlugin.inst());
    } else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
        event.setUseItemResult(Tristate.FALSE);
        event.setUseBlockResult(Tristate.FALSE);
        player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
        inst.payPlayer(player);
    } else if (!inst.isLocked()) {
        if (state.getType() == BlockTypes.STONE_BUTTON) {
            inst.tryToStart();
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 7 with NonNullList

use of net.minecraft.util.NonNullList in project ForestryMC by ForestryMC.

the class ItemStackUtil method containsSets.

/**
 * Counts how many full sets are contained in the passed stock
 */
public static int containsSets(NonNullList<ItemStack> set, NonNullList<ItemStack> stock, NonNullList<String> oreDicts, boolean craftingTools) {
    int totalSets = 0;
    Pair<NonNullList<ItemStack>, NonNullList<String>> condensedRequired = ItemStackUtil.condenseStacks(set, oreDicts);
    NonNullList<String> condensedRequiredDicts = condensedRequired.getRight();
    NonNullList<ItemStack> condensedRequiredStacks = condensedRequired.getLeft();
    NonNullList<ItemStack> condensedOfferedStacks = ItemStackUtil.condenseStacks(stock);
    for (int y = 0; y < condensedRequiredStacks.size(); y++) {
        ItemStack req = condensedRequiredStacks.get(y);
        String offerDict = condensedRequiredDicts.get(y);
        int reqCount = 0;
        for (int i = 0; i < condensedOfferedStacks.size(); i++) {
            ItemStack offer = condensedOfferedStacks.get(i);
            if (isCraftingEquivalent(req, offer, offerDict, craftingTools)) {
                int stackCount = (int) Math.floor(offer.getCount() / req.getCount());
                reqCount = Math.max(reqCount, stackCount);
            }
        }
        if (reqCount == 0) {
            return 0;
        } else if (totalSets == 0) {
            totalSets = reqCount;
        } else if (totalSets > reqCount) {
            totalSets = reqCount;
        }
    }
    return totalSets;
}
Also used : NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack)

Example 8 with NonNullList

use of net.minecraft.util.NonNullList in project ForestryMC by ForestryMC.

the class TileCocoon method onBlockTick.

public void onBlockTick() {
    maturationTime++;
    IButterflyGenome caterpillarGenome = caterpillar.getGenome();
    int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
    if (maturationTime >= caterpillarMatureTime) {
        if (age < 2) {
            age++;
            maturationTime = 0;
            IBlockState blockState = world.getBlockState(pos);
            world.notifyBlockUpdate(pos, blockState, blockState, 0);
        } else if (caterpillar.canTakeFlight(world, getPos().getX(), getPos().getY(), getPos().getZ())) {
            NonNullList<ItemStack> cocoonDrops = caterpillar.getCocoonDrop(this);
            for (ItemStack drop : cocoonDrops) {
                ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
            }
            world.setBlockToAir(getPos());
            attemptButterflySpawn(world, caterpillar, getPos());
        }
    }
}
Also used : IButterflyGenome(forestry.api.lepidopterology.IButterflyGenome) IBlockState(net.minecraft.block.state.IBlockState) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack)

Example 9 with NonNullList

use of net.minecraft.util.NonNullList in project Cavern2 by kegare.

the class MiningAssistEventHooks method onBlockBreak.

@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    EntityPlayer player = event.getPlayer();
    if (player == null || player instanceof FakePlayer) {
        return;
    }
    BlockPos pos = event.getPos();
    MiningAssistUnit assist = MiningAssistUnit.get(player);
    if (assist.addExperience(pos, event.getExpToDrop())) {
        event.setExpToDrop(0);
    }
    if (breaking) {
        return;
    }
    if (!(player instanceof EntityPlayerMP)) {
        return;
    }
    IBlockState state = event.getState();
    if (!isActive(player, state)) {
        return;
    }
    MiningAssist type = MiningAssist.byPlayer(player);
    MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
    if (snapshot.isEmpty()) {
        return;
    }
    PlayerInteractionManager im = ((EntityPlayerMP) player).interactionManager;
    assist.captureDrops(MiningAssistConfig.collectDrops);
    assist.captureExperiences(MiningAssistConfig.collectExps);
    breaking = true;
    for (BlockPos target : snapshot.getTargets()) {
        if (snapshot.validTarget(target) && !harvestBlock(im, target)) {
            break;
        }
    }
    breaking = false;
    Map<BlockPos, NonNullList<ItemStack>> drops = assist.captureDrops(false);
    if (drops != null && !drops.isEmpty()) {
        for (NonNullList<ItemStack> items : drops.values()) {
            for (ItemStack stack : items) {
                Block.spawnAsEntity(world, pos, stack);
            }
        }
    }
    Map<BlockPos, Integer> experiences = assist.captureExperiences(false);
    if (experiences != null && !experiences.isEmpty() && !im.isCreative() && world.getGameRules().getBoolean("doTileDrops")) {
        int exp = experiences.values().stream().mapToInt(Integer::intValue).sum();
        while (exp > 0) {
            int i = EntityXPOrb.getXPSplit(exp);
            exp -= i;
            world.spawnEntity(new EntityXPOrb(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, i));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) MiningAssist(cavern.miningassist.MiningAssist) FakePlayer(net.minecraftforge.common.util.FakePlayer) MiningSnapshot(cavern.miningassist.MiningSnapshot) NonNullList(net.minecraft.util.NonNullList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) ItemStack(net.minecraft.item.ItemStack) MiningAssistUnit(cavern.miningassist.MiningAssistUnit) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with NonNullList

use of net.minecraft.util.NonNullList in project Binnie by ForestryMC.

the class ItemSerum method getSubItems.

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
    if (this.isInCreativeTab(tab)) {
        for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
            Map<IChromosomeType, List<IAllele>> chromosomeMap = Binnie.GENETICS.getChromosomeMap(root);
            if (chromosomeMap != null) {
                for (Map.Entry<IChromosomeType, List<IAllele>> entry : chromosomeMap.entrySet()) {
                    IChromosomeType chromosome = entry.getKey();
                    for (final IAllele allele : entry.getValue()) {
                        Gene gene = Gene.create(allele, chromosome, root);
                        IGeneItem geneItem = new GeneItem(gene);
                        ItemStack stack = new ItemStack(this);
                        geneItem.writeToItem(stack);
                        items.add(stack);
                    }
                }
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IGeneItem(binnie.genetics.genetics.IGeneItem) Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) GeneItem(binnie.genetics.genetics.GeneItem) IGeneItem(binnie.genetics.genetics.IGeneItem) List(java.util.List) NonNullList(net.minecraft.util.NonNullList) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

Aggregations

NonNullList (net.minecraft.util.NonNullList)42 ItemStack (net.minecraft.item.ItemStack)37 List (java.util.List)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Item (net.minecraft.item.Item)8 TileEntity (net.minecraft.tileentity.TileEntity)8 BlockPos (net.minecraft.util.math.BlockPos)7 ArrayList (java.util.ArrayList)6 Collectors (java.util.stream.Collectors)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 CreativeTabs (net.minecraft.creativetab.CreativeTabs)5 World (net.minecraft.world.World)5 Block (net.minecraft.block.Block)4 IBlockState (net.minecraft.block.state.IBlockState)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4