use of net.minecraft.entity.EntityType in project FastAsyncWorldEdit by IntellectualSites.
the class FabricWorld method createEntity.
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
final Optional<EntityType<?>> entityType = EntityType.get(entity.getType().getId());
if (!entityType.isPresent())
return null;
net.minecraft.entity.Entity createdEntity = entityType.get().create(world);
if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) {
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(entity.getNbtData());
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
createdEntity.fromTag(tag);
}
createdEntity.setPositionAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.spawnEntity(createdEntity);
return new FabricEntity(createdEntity);
} else {
return null;
}
}
use of net.minecraft.entity.EntityType in project meteor-client by MeteorDevelopment.
the class EntityTypeListSetting method parseImpl.
@Override
protected Object2BooleanMap<EntityType<?>> parseImpl(String str) {
String[] values = str.split(",");
Object2BooleanMap<EntityType<?>> entities = new Object2BooleanOpenHashMap<>(values.length);
try {
for (String value : values) {
EntityType<?> entity = parseId(Registry.ENTITY_TYPE, value);
if (entity != null)
entities.put(entity, true);
}
} catch (Exception ignored) {
}
return entities;
}
use of net.minecraft.entity.EntityType in project Arclight by IzzelAliz.
the class AbstractSpawnerMixin method tick.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
if (!this.isActivated()) {
this.prevMobRotation = this.mobRotation;
} else {
World world = this.getWorld();
BlockPos blockpos = this.getSpawnerPosition();
if (world.isRemote) {
double d3 = (double) blockpos.getX() + (double) world.rand.nextFloat();
double d4 = (double) blockpos.getY() + (double) world.rand.nextFloat();
double d5 = (double) blockpos.getZ() + (double) world.rand.nextFloat();
world.addParticle(ParticleTypes.SMOKE, d3, d4, d5, 0.0D, 0.0D, 0.0D);
world.addParticle(ParticleTypes.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D);
if (this.spawnDelay > 0) {
--this.spawnDelay;
}
this.prevMobRotation = this.mobRotation;
this.mobRotation = (this.mobRotation + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D;
} else {
if (this.spawnDelay == -1) {
this.resetTimer();
}
if (this.spawnDelay > 0) {
--this.spawnDelay;
return;
}
boolean flag = false;
for (int i = 0; i < this.spawnCount; ++i) {
CompoundNBT compoundnbt = this.spawnData.getNbt();
Optional<EntityType<?>> optional = EntityType.readEntityType(compoundnbt);
if (!optional.isPresent()) {
this.resetTimer();
return;
}
ListNBT listnbt = compoundnbt.getList("Pos", 6);
int j = listnbt.size();
double d0 = j >= 1 ? listnbt.getDouble(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
double d1 = j >= 2 ? listnbt.getDouble(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1);
double d2 = j >= 3 ? listnbt.getDouble(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
if (world.hasNoCollisions(optional.get().getBoundingBoxWithSizeApplied(d0, d1, d2)) && EntitySpawnPlacementRegistry.func_223515_a(optional.get(), world.getWorld(), SpawnReason.SPAWNER, new BlockPos(d0, d1, d2), world.getRandom())) {
Entity entity = EntityType.loadEntityAndExecute(compoundnbt, world, (p_221408_6_) -> {
p_221408_6_.setLocationAndAngles(d0, d1, d2, p_221408_6_.rotationYaw, p_221408_6_.rotationPitch);
return p_221408_6_;
});
if (entity == null) {
this.resetTimer();
return;
}
int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (double) (blockpos.getX() + 1), (double) (blockpos.getY() + 1), (double) (blockpos.getZ() + 1))).grow((double) this.spawnRange)).size();
if (k >= this.maxNearbyEntities) {
this.resetTimer();
return;
}
entity.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), world.rand.nextFloat() * 360.0F, 0.0F);
if (entity instanceof MobEntity) {
MobEntity mobentity = (MobEntity) entity;
if (!ForgeEventFactory.canEntitySpawnSpawner(mobentity, world, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), (AbstractSpawner) (Object) this)) {
continue;
}
if (this.spawnData.getNbt().size() == 1 && this.spawnData.getNbt().contains("id", 8)) {
((MobEntity) entity).onInitialSpawn(world, world.getDifficultyForLocation(new BlockPos(entity)), SpawnReason.SPAWNER, (ILivingEntityData) null, (CompoundNBT) null);
}
if (((WorldBridge) mobentity.world).bridge$spigotConfig().nerfSpawnerMobs) {
((MobEntityBridge) mobentity).bridge$setAware(false);
}
}
if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockpos).isCancelled()) {
Entity vehicle = entity.getRidingEntity();
if (vehicle != null) {
vehicle.removed = true;
}
for (final Entity passenger : entity.getRecursivePassengers()) {
passenger.removed = true;
}
}
this.func_221409_a(entity);
world.playEvent(2004, blockpos, 0);
if (entity instanceof MobEntity) {
((MobEntity) entity).spawnExplosionParticle();
}
flag = true;
}
}
if (flag) {
this.resetTimer();
}
}
}
}
use of net.minecraft.entity.EntityType in project Fragile-Glass by fredtargaryen.
the class ExportAllCommand method execute.
private static int execute(CommandSource source, String manager) {
DataManager dm = CommandsBase.getDataManager(manager);
if (dm == null) {
return 1;
}
StringBuilder sb = new StringBuilder();
if (manager.equals("blocks")) {
dm.getKeys().forEach(state -> {
try {
List<FragilityData> fdList = (List<FragilityData>) dm.getData(state);
fdList.forEach(fragilityData -> {
sb.append(dm.stringifyBehaviours(state, null, false));
sb.append("\n");
});
} catch (NullPointerException npe) {
source.sendFeedback(new StringTextComponent("No existing block state data for " + KeyParser.cleanBlockStateString(state.toString())), false);
}
});
} else if (manager.equals("entities")) {
dm.getKeys().forEach(type -> {
try {
sb.append(dm.stringifyBehaviours(type, null, false));
sb.append("\n");
} catch (NullPointerException npe) {
source.sendFeedback(new StringTextComponent("No existing entity data for " + ((EntityType) type).getRegistryName()), false);
}
});
} else {
// "tileentities"
dm.getKeys().forEach(type -> {
try {
List<FragilityData> fdList = (List<FragilityData>) dm.getData(type);
fdList.forEach(fragilityData -> {
sb.append(dm.stringifyBehaviours(type, null, false));
sb.append("\n");
});
} catch (NullPointerException npe) {
source.sendFeedback(new StringTextComponent("No existing tile entity data for " + ((TileEntityType) type).getRegistryName()), false);
}
});
}
try {
dm.export(sb.toString());
source.sendFeedback(new StringTextComponent("File exported successfully!"), true);
return 0;
} catch (IOException ioe) {
source.sendFeedback(new StringTextComponent("File failed to export."), true);
return 1;
}
}
use of net.minecraft.entity.EntityType in project Mekanism by mekanism.
the class SpawnHelper method onBiomeLoad.
public static void onBiomeLoad(BiomeLoadingEvent event) {
// Add spawns to any biomes that have mob spawns for the "parent" types of our mobs
MobSpawnInfoBuilder spawns = event.getSpawns();
List<MobSpawnInfo.Spawners> monsterSpawns = spawns.getSpawner(EntityClassification.MONSTER);
if (!monsterSpawns.isEmpty()) {
// Fail quick if no monsters can spawn in this biome anyway
ResourceLocation biomeName = event.getName();
getSpawnConfigs().filter(spawnConfig -> spawnConfig.shouldSpawn.get() && !spawnConfig.biomeBlackList.get().contains(biomeName)).forEach(spawnConfig -> {
EntityType<?> parent = spawnConfig.parentTypeProvider.getEntityType();
monsterSpawns.stream().filter(monsterSpawn -> monsterSpawn.type == parent).findFirst().ifPresent(parentEntry -> {
// If the adult mob can spawn in this biome let the baby mob spawn in it
// Note: We adjust the mob's spawning based on the adult's spawn rates
MobSpawnInfo.Spawners spawner = getSpawner(spawnConfig, parentEntry);
spawns.addSpawn(EntityClassification.MONSTER, spawner);
MobSpawnInfo.SpawnCosts parentCost = spawns.getCost(parent);
if (parentCost == null) {
Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount);
} else {
double spawnCostPerEntity = parentCost.getCharge() * spawnConfig.spawnCostPerEntityPercentage.get();
double maxSpawnCost = parentCost.getEnergyBudget() * spawnConfig.maxSpawnCostPercentage.get();
spawns.addMobCharge(spawner.type, spawnCostPerEntity, maxSpawnCost);
Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}, spawnCostPerEntity: {}, maxSpawnCost: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount, spawnCostPerEntity, maxSpawnCost);
}
});
});
}
}
Aggregations