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