Search in sources :

Example 1 with MobSpawnerTileEntity

use of net.minecraft.tileentity.MobSpawnerTileEntity in project minecolonies by Minecolonies.

the class ShipBasedRaiderUtils method setupSpawner.

/**
 * Setup a spawner.
 *
 * @param location the location to set it up at.
 * @param world    the world to place it in.
 * @param mob      the mob to spawn.
 * @param event    the event.
 * @param colonyId the colony id.
 */
public static void setupSpawner(final BlockPos location, final World world, final EntityType<?> mob, final IColonyRaidEvent event, final int colonyId) {
    world.removeBlock(location, false);
    world.setBlockAndUpdate(location, Blocks.SPAWNER.defaultBlockState());
    final MobSpawnerTileEntity spawner = new MobSpawnerTileEntity();
    spawner.getSpawner().requiredPlayerRange = SPAWNER_DISTANCE;
    spawner.getSpawner().setEntityId(mob);
    // Sets nbt for mobs to spawn, assumes colony in same dimension as mob.
    spawner.getSpawner().nextSpawnData.getTag().putInt(TAG_EVENT_ID, event.getID());
    spawner.getSpawner().nextSpawnData.getTag().putInt(TAG_COLONY_ID, colonyId);
    event.addSpawner(location);
    world.setBlockEntity(location, spawner);
}
Also used : MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity)

Example 2 with MobSpawnerTileEntity

use of net.minecraft.tileentity.MobSpawnerTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class SpawnerFactory method getSpawnerTile.

public static MobSpawnerTileEntity getSpawnerTile(World world, ResourceLocation entity, BlockPos pos) {
    MobSpawnerTileEntity spawner = (MobSpawnerTileEntity) world.getBlockEntity(pos);
    spawner.getSpawner().setEntityId(ForgeRegistries.ENTITIES.getValue(entity));
    return spawner;
}
Also used : MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity)

Example 3 with MobSpawnerTileEntity

use of net.minecraft.tileentity.MobSpawnerTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class SpawnerFactory method placeSpawner.

/**
 * Places a spawner in the provided world at the provided position. Spawner type (CQR/vanilla) is determined dynamically
 * based upon the requested capabilities.
 *
 * @param entities                 Entities as NBT Tag (From Entity.writeToNBTOptional(COMPOUND) for spawner to spawn
 * @param multiUseSpawner          Determines spawner type. Vanilla = true; CQR = false.
 * @param spawnerSettingsOverrides Settings to be applied if generating vanilla spawner (can be null if CQR spawner)
 * @param world                    World in which to place spawner
 * @param pos                      Position at which to place spawner
 */
public static void placeSpawner(CompoundNBT[] entities, boolean multiUseSpawner, @Nullable CompoundNBT spawnerSettingsOverrides, World world, BlockPos pos) {
    BlockState blockState = multiUseSpawner ? Blocks.SPAWNER.defaultBlockState() : CQRBlocks.SPAWNER.defaultBlockState();
    world.setBlockAndUpdate(pos, blockState);
    TileEntity tileEntity = world.getBlockEntity(pos);
    if (multiUseSpawner) {
        MobSpawnerTileEntity tileEntityMobSpawner = (MobSpawnerTileEntity) tileEntity;
        CompoundNBT compound = tileEntityMobSpawner.save(new CompoundNBT());
        ListNBT spawnPotentials = new ListNBT();
        // Store entity ids into NBT tag
        for (int i = 0; i < entities.length; i++) {
            if (entities[i] != null) {
                {
                    // needed because in earlier versions the uuid and pos were not removed when using a soul bottle/mob to spawner on an
                    // entity
                    entities[i].remove("UUIDLeast");
                    entities[i].remove("UUIDMost");
                    entities[i].remove("Pos");
                    ListNBT passengers = entities[i].getList("Passengers", 10);
                    for (INBT passenger : passengers) {
                        ((CompoundNBT) passenger).remove("UUIDLeast");
                        ((CompoundNBT) passenger).remove("UUIDMost");
                        ((CompoundNBT) passenger).remove("Pos");
                    }
                }
                CompoundNBT spawnPotential = new CompoundNBT();
                spawnPotential.putInt("Weight", 1);
                spawnPotential.put("Entity", entities[i]);
                spawnPotentials.add(spawnPotential);
            }
        }
        compound.put("SpawnPotentials", spawnPotentials);
        compound.remove("SpawnData");
        // Store default settings into NBT
        if (spawnerSettingsOverrides != null) {
            compound.putInt("MinSpawnDelay", spawnerSettingsOverrides.getInt("MinSpawnDelay"));
            compound.putInt("MaxSpawnDelay", spawnerSettingsOverrides.getInt("MaxSpawnDelay"));
            compound.putInt("SpawnCount", spawnerSettingsOverrides.getInt("SpawnCount"));
            compound.putInt("MaxNearbyEntities", spawnerSettingsOverrides.getInt("MaxNearbyEntities"));
            compound.putInt("SpawnRange", spawnerSettingsOverrides.getInt("SpawnRange"));
            compound.putInt("RequiredPlayerRange", spawnerSettingsOverrides.getInt("RequiredPlayerRange"));
        }
        // Read data from modified nbt
        tileEntityMobSpawner.load(blockState, compound);
        tileEntityMobSpawner.setChanged();
    } else {
        TileEntitySpawner tileEntitySpawner = (TileEntitySpawner) tileEntity;
        for (int i = 0; i < entities.length && i < 9; i++) {
            if (entities[i] != null) {
                tileEntitySpawner.inventory.setStackInSlot(i, getSoulBottleItemStackForEntity(entities[i]));
            }
        }
        tileEntitySpawner.setChanged();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) ListNBT(net.minecraft.nbt.ListNBT) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) TileEntitySpawner(team.cqr.cqrepoured.tileentity.TileEntitySpawner)

Example 4 with MobSpawnerTileEntity

use of net.minecraft.tileentity.MobSpawnerTileEntity in project minecolonies by ldtteam.

the class ShipBasedRaiderUtils method setupSpawner.

/**
 * Setup a spawner.
 *
 * @param location the location to set it up at.
 * @param world    the world to place it in.
 * @param mob      the mob to spawn.
 * @param event    the event.
 * @param colonyId the colony id.
 */
public static void setupSpawner(final BlockPos location, final World world, final EntityType<?> mob, final IColonyRaidEvent event, final int colonyId) {
    world.removeBlock(location, false);
    world.setBlockAndUpdate(location, Blocks.SPAWNER.defaultBlockState());
    final MobSpawnerTileEntity spawner = new MobSpawnerTileEntity();
    spawner.getSpawner().requiredPlayerRange = SPAWNER_DISTANCE;
    spawner.getSpawner().setEntityId(mob);
    // Sets nbt for mobs to spawn, assumes colony in same dimension as mob.
    spawner.getSpawner().nextSpawnData.getTag().putInt(TAG_EVENT_ID, event.getID());
    spawner.getSpawner().nextSpawnData.getTag().putInt(TAG_COLONY_ID, colonyId);
    event.addSpawner(location);
    world.setBlockEntity(location, spawner);
}
Also used : MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity)

Example 5 with MobSpawnerTileEntity

use of net.minecraft.tileentity.MobSpawnerTileEntity in project ChaosAwakens by ChaosAwakens.

the class SpawnEggItemMixin method useOn.

@Inject(method = "useOn(Lnet/minecraft/item/ItemUseContext;)Lnet/minecraft/util/ActionResultType;", at = @At("HEAD"), cancellable = true)
public void useOn(ItemUseContext itemUseContext, CallbackInfoReturnable<ActionResultType> cir) {
    World world = itemUseContext.getLevel();
    if (!(world instanceof ServerWorld)) {
        cir.setReturnValue(ActionResultType.SUCCESS);
    } else {
        ItemStack itemstack = itemUseContext.getItemInHand();
        BlockPos blockpos = itemUseContext.getClickedPos();
        Direction direction = itemUseContext.getClickedFace();
        BlockState blockstate = world.getBlockState(blockpos);
        PlayerEntity player = itemUseContext.getPlayer();
        if (blockstate.is(Blocks.SPAWNER)) {
            if ((CAConfig.COMMON.spawnEggsSpawnersSurvival.get() == 0) || (CAConfig.COMMON.spawnEggsSpawnersSurvival.get() == 1 && player.isCreative()) || (CAConfig.COMMON.spawnEggsSpawnersSurvival.get() == 2 && player.isCreative() && itemstack.getItem().getRegistryName().getNamespace().equals("chaosawakens")) || (CAConfig.COMMON.spawnEggsSpawnersSurvival.get() == 2 && !itemstack.getItem().getRegistryName().getNamespace().equals("chaosawakens"))) {
                TileEntity tileentity = world.getBlockEntity(blockpos);
                if (tileentity instanceof MobSpawnerTileEntity) {
                    AbstractSpawner abstractspawner = ((MobSpawnerTileEntity) tileentity).getSpawner();
                    EntityType<?> entitytype1 = this.getType(itemstack.getTag());
                    abstractspawner.setEntityId(entitytype1);
                    tileentity.setChanged();
                    world.sendBlockUpdated(blockpos, blockstate, blockstate, 3);
                    itemstack.shrink(1);
                    cir.setReturnValue(ActionResultType.CONSUME);
                }
            }
        }
        BlockPos blockpos1;
        if (blockstate.getCollisionShape(world, blockpos).isEmpty()) {
            blockpos1 = blockpos;
        } else {
            blockpos1 = blockpos.relative(direction);
        }
        EntityType<?> entitytype = this.getType(itemstack.getTag());
        if (!blockstate.is(Blocks.SPAWNER)) {
            if (entitytype.spawn((ServerWorld) world, itemstack, itemUseContext.getPlayer(), blockpos1, SpawnReason.SPAWN_EGG, true, !Objects.equals(blockpos, blockpos1) && direction == Direction.UP) != null) {
                itemstack.shrink(1);
            }
        }
        cir.setReturnValue(ActionResultType.CONSUME);
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) AbstractSpawner(net.minecraft.world.spawner.AbstractSpawner) BlockPos(net.minecraft.util.math.BlockPos) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

MobSpawnerTileEntity (net.minecraft.tileentity.MobSpawnerTileEntity)10 TileEntity (net.minecraft.tileentity.TileEntity)6 BlockState (net.minecraft.block.BlockState)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 BlockPos (net.minecraft.util.math.BlockPos)3 AbstractSpawner (net.minecraft.world.spawner.AbstractSpawner)3 ItemStack (net.minecraft.item.ItemStack)2 ListNBT (net.minecraft.nbt.ListNBT)2 Direction (net.minecraft.util.Direction)2 WeightedSpawnerEntity (net.minecraft.util.WeightedSpawnerEntity)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 TileEntitySpawner (team.cqr.cqrepoured.tileentity.TileEntitySpawner)2 Block (net.minecraft.block.Block)1 FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)1 Entity (net.minecraft.entity.Entity)1 MobEntity (net.minecraft.entity.MobEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 INBT (net.minecraft.nbt.INBT)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1