Search in sources :

Example 1 with TileEntitySpawner

use of team.cqr.cqrepoured.tileentity.TileEntitySpawner in project ChocolateQuestRepoured by TeamChocoQuest.

the class BlockSpawner method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, BlockState state) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity instanceof TileEntitySpawner) {
        IItemHandler itemHandler = ((TileEntitySpawner) tileEntity).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        for (int i = 0; i < itemHandler.getSlots(); i++) {
            ItemStack stack = itemHandler.getStackInSlot(i);
            if (!stack.isEmpty()) {
                ItemEntity item = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack);
                world.spawnEntity(item);
            }
        }
    }
    super.breakBlock(world, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) IItemHandler(net.minecraftforge.items.IItemHandler) TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileEntitySpawner

use of team.cqr.cqrepoured.tileentity.TileEntitySpawner in project ChocolateQuestRepoured by TeamChocoQuest.

the class CastleRoomDecoratedBase method addSpawners.

protected void addSpawners(World world, BlockStateGenArray genArray, DungeonRandomizedCastle dungeon, GearedMobFactory mobFactory) {
    List<BlockPos> spawnPositions = this.getDecorationLayer(0);
    spawnPositions.removeAll(this.usedDecoPositions);
    int spawnerCount = dungeon.randomizeRoomSpawnerCount(this.random);
    for (int i = 0; (i < spawnerCount && !spawnPositions.isEmpty()); i++) {
        BlockPos pos = spawnPositions.get(this.random.nextInt(spawnPositions.size()));
        Entity mobEntity = mobFactory.getGearedEntityByFloor(this.floor, world);
        Block spawnerBlock = CQRBlocks.SPAWNER;
        IBlockState state = spawnerBlock.getDefaultState();
        TileEntitySpawner spawner = (TileEntitySpawner) spawnerBlock.createTileEntity(world, state);
        if (spawner != null) {
            spawner.inventory.setStackInSlot(0, SpawnerFactory.getSoulBottleItemStackForEntity(mobEntity));
            NBTTagCompound spawnerCompound = spawner.writeToNBT(new NBTTagCompound());
            genArray.addBlockState(pos, state, spawnerCompound, BlockStateGenArray.GenerationPhase.POST, BlockStateGenArray.EnumPriority.MEDIUM);
            this.usedDecoPositions.add(pos);
            spawnPositions.remove(pos);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner)

Example 3 with TileEntitySpawner

use of team.cqr.cqrepoured.tileentity.TileEntitySpawner in project ChocolateQuestRepoured by TeamChocoQuest.

the class WallPieceWall method placeSpawner.

private void placeSpawner(BlockPos spawnerPos, ISeedReader iSeedReader) {
    Entity spawnerEnt = EntityList.createEntityByIDFromName(new ResourceLocation(CQRConfig.wall.mob), iSeedReader.getLevel());
    if (spawnerEnt instanceof LivingEntity) {
        Difficulty difficulty = iSeedReader.getDifficulty();
        this.equipWeaponBasedOnDifficulty((LivingEntity) spawnerEnt, difficulty);
        this.equipArmorBasedOnDifficulty((LivingEntity) spawnerEnt, difficulty);
        if (spawnerEnt instanceof AbstractEntityCQR) {
            ((AbstractEntityCQR) spawnerEnt).setHealingPotions(1);
        }
        BlockState state2 = CQRBlocks.SPAWNER.defaultBlockState();
        TileEntitySpawner tileSpawner = (TileEntitySpawner) CQRBlocks.SPAWNER.createTileEntity(state2, iSeedReader);
        tileSpawner.inventory.setStackInSlot(0, SpawnerFactory.getSoulBottleItemStackForEntity(spawnerEnt));
        // partBuilder.add(new PreparableSpawnerInfo(spawnerPos, tileSpawner.save(new CompoundNBT())));
        this.placeBlock(iSeedReader, state2, spawnerPos.getX(), spawnerPos.getY(), spawnerPos.getZ(), this.boundingBox);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) Difficulty(net.minecraft.world.Difficulty) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner)

Example 4 with TileEntitySpawner

use of team.cqr.cqrepoured.tileentity.TileEntitySpawner in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemMobToSpawner method onBlockDestroyed.

@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
    if (state.getBlock() == CQRBlocks.SPAWNER && !worldIn.isRemote) {
        TileEntitySpawner spawner = (TileEntitySpawner) worldIn.getTileEntity(pos);
        spawner.forceTurnBackIntoEntity();
    }
    return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}
Also used : TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner)

Example 5 with TileEntitySpawner

use of team.cqr.cqrepoured.tileentity.TileEntitySpawner in project ChocolateQuestRepoured by TeamChocoQuest.

the class SpawnerFactory method convertCQSpawnerToVanillaSpawner.

/*
	 * CQR/Vanilla Conversion
	 */
/**
 * Converts the CQR spawner at the provided World/BlockPos to a vanilla spawner
 *
 * @param spawnerSettings
 */
public static void convertCQSpawnerToVanillaSpawner(World world, BlockPos pos, @Nullable CompoundNBT spawnerSettings) {
    TileEntity tile = world.getBlockEntity(pos);
    if (tile instanceof TileEntitySpawner) {
        TileEntitySpawner spawner = (TileEntitySpawner) tile;
        // Entity[] entities = new Entity[spawner.inventory.getSlots()];
        CompoundNBT[] entities = new CompoundNBT[spawner.inventory.getSlots()];
        for (int i = 0; i < entities.length; i++) {
            // getStackInSlot(i);
            ItemStack stack = spawner.inventory.extractItem(i, spawner.inventory.getStackInSlot(i).getCount(), false);
            if (!stack.isEmpty()) {
                try {
                    CompoundNBT tag = stack.getOrCreateTag();
                    // NBTTagCompound entityTag = (NBTTagCompound)tag.getTag("EntityIn");
                    entities[i] = tag.getCompound("EntityIn");
                /*
						 * entities[i] = createEntityFromNBTWithoutSpawningIt(entityTag, world);
						 * 
						 * entities[i].setUniqueId(MathHelper.getRandomUUID(rand));
						 */
                } catch (NullPointerException ignored) {
                }
            } else {
                entities[i] = null;
            }
        }
        world.destroyBlock(pos, false);
        placeSpawner(entities, true, spawnerSettings, world, pos);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileEntitySpawner (team.cqr.cqrepoured.tileentity.TileEntitySpawner)8 BlockState (net.minecraft.block.BlockState)4 TileEntity (net.minecraft.tileentity.TileEntity)4 Entity (net.minecraft.entity.Entity)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 MobSpawnerTileEntity (net.minecraft.tileentity.MobSpawnerTileEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 ItemStack (net.minecraft.item.ItemStack)2 Block (net.minecraft.block.Block)1 DoorBlock (net.minecraft.block.DoorBlock)1 LeverBlock (net.minecraft.block.LeverBlock)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 INBT (net.minecraft.nbt.INBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Difficulty (net.minecraft.world.Difficulty)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 AbstractEntityCQR (team.cqr.cqrepoured.entity.bases.AbstractEntityCQR)1 GeneratableBlockInfo (team.cqr.cqrepoured.world.structure.generation.generation.generatable.GeneratableBlockInfo)1