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);
}
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);
}
}
}
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);
}
}
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);
}
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);
}
}
Aggregations