use of net.minecraft.entity.EntityType in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createStcSpawnEntity.
// NOTE my packet is redirected but I cannot get the packet handler info here
public static CustomPayloadS2CPacket createStcSpawnEntity(Entity entity) {
EntityType entityType = entity.getType();
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(EntityType.getId(entityType).toString());
buf.writeInt(entity.getEntityId());
buf.writeInt(entity.dimension.getRawId());
CompoundTag tag = new CompoundTag();
entity.toTag(tag);
buf.writeCompoundTag(tag);
return new CustomPayloadS2CPacket(id_stcSpawnEntity, buf);
}
use of net.minecraft.entity.EntityType in project FastAsyncWorldEdit by IntellectualSites.
the class ForgeWorld method createEntity.
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
final Optional<EntityType<?>> entityType = EntityType.byKey(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) {
CompoundNBT tag = NBTConverter.toNative(entity.getNbtData());
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
createdEntity.read(tag);
}
createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
world.addEntity(createdEntity);
return new ForgeEntity(createdEntity);
} else {
return null;
}
}
use of net.minecraft.entity.EntityType in project minecolonies by ldtteam.
the class AbstractShipRaidEvent method onUpdate.
@Override
public void onUpdate() {
status = EventStatus.PROGRESSING;
colony.getRaiderManager().setNightsSinceLastRaid(0);
if (spawners.size() <= 0 && raiders.size() == 0 && respawns.isEmpty()) {
status = EventStatus.WAITING;
return;
}
updateRaidBar();
if (!respawns.isEmpty()) {
for (final Tuple<EntityType<?>, BlockPos> entry : respawns) {
final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(entry.getB(), colony, MAX_LANDING_DISTANCE, spawnPoint, MIN_CENTER_DISTANCE, 10);
if (spawnPos != null) {
RaiderMobUtils.spawn(entry.getA(), 1, spawnPos, colony.getWorld(), colony, id);
}
}
respawns.clear();
return;
}
spawners.removeIf(spawner -> colony.getWorld() != null && WorldUtil.isBlockLoaded(colony.getWorld(), spawner) && colony.getWorld().getBlockState(spawner).getBlock() != Blocks.SPAWNER);
// Spawns landing troops.
if (raiders.size() < spawners.size() * 2) {
BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(spawnPoint, colony, MAX_LANDING_DISTANCE, spawnPoint, MIN_CENTER_DISTANCE, 10);
if (spawnPos != null) {
// Find nice position on the ship
if (spawnPos.distSqr(spawnPoint) < 25) {
spawnPos = ShipBasedRaiderUtils.findSpawnPosOnShip(spawnPos, colony.getWorld(), 3);
}
RaiderMobUtils.spawn(getNormalRaiderType(), shipSize.normal, spawnPos, colony.getWorld(), colony, id);
RaiderMobUtils.spawn(getArcherRaiderType(), shipSize.archer, spawnPos, colony.getWorld(), colony, id);
RaiderMobUtils.spawn(getBossRaiderType(), shipSize.boss, spawnPos, colony.getWorld(), colony, id);
}
}
// Mark entities when spies exist
if (colony.getRaiderManager().areSpiesEnabled()) {
for (final Entity entity : getEntities()) {
if (entity instanceof LivingEntity) {
((LivingEntity) entity).addEffect(new EffectInstance(Effects.GLOWING, 550));
}
}
}
}
use of net.minecraft.entity.EntityType in project minecolonies by ldtteam.
the class HordeRaidEvent method onUpdate.
@Override
public void onUpdate() {
if (status == EventStatus.PREPARING) {
prepareEvent();
}
updateRaidBar();
colony.getRaiderManager().setNightsSinceLastRaid(0);
if (horde.hordeSize <= 0) {
status = EventStatus.DONE;
}
if (!respawns.isEmpty()) {
for (final Tuple<EntityType<?>, BlockPos> entry : respawns) {
final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(entry.getB(), colony, MAX_RESPAWN_DEVIATION, spawnPoint, MIN_CENTER_DISTANCE, 10);
if (spawnPos != null) {
RaiderMobUtils.spawn(entry.getA(), 1, spawnPos, colony.getWorld(), colony, id);
}
}
respawns.clear();
return;
}
if (boss.size() + archers.size() + normal.size() < horde.numberOfBosses + horde.numberOfRaiders + horde.numberOfArchers) {
final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(spawnPoint, colony, MAX_RESPAWN_DEVIATION, spawnPoint, MIN_CENTER_DISTANCE, 10);
if (spawnPos != null) {
spawnHorde(spawnPos, colony, id, horde.numberOfBosses - boss.size(), horde.numberOfArchers - archers.size(), horde.numberOfRaiders - normal.size());
}
}
if (horde.numberOfBosses + horde.numberOfRaiders + horde.numberOfArchers < Math.round(horde.initialSize * 0.05)) {
status = EventStatus.DONE;
}
for (final Entity entity : getEntities()) {
if (!entity.isAlive() || !WorldUtil.isEntityBlockLoaded(colony.getWorld(), new BlockPos(entity.position()))) {
entity.remove();
respawns.add(new Tuple<>(entity.getType(), new BlockPos(entity.position())));
continue;
}
if (colony.getRaiderManager().areSpiesEnabled()) {
((LivingEntity) entity).addEffect(new EffectInstance(Effects.GLOWING, 550));
}
}
}
use of net.minecraft.entity.EntityType in project Werewolves by TeamLapen.
the class ModEntityEventHandler method makeWerewolfFriendly.
/**
* copy from {@link de.teamlapen.vampirism.entity.ModEntityEventHandler#makeVampireFriendly(String, MobEntity, Class, Class, int, BiFunction, Predicate)}
*/
public static <T extends MobEntity, S extends LivingEntity, Q extends NearestAttackableTargetGoal<S>> void makeWerewolfFriendly(String name, T entity, Class<Q> targetClass, Class<S> targetEntityClass, int attackPriority, BiFunction<T, Predicate<LivingEntity>, Q> replacement, Predicate<EntityType<? extends T>> typeCheck) {
try {
Goal target = null;
for (PrioritizedGoal t : entity.targetSelector.availableGoals) {
Goal g = t.getGoal();
if (targetClass.equals(g.getClass()) && t.getPriority() == attackPriority && targetEntityClass.equals(((NearestAttackableTargetGoal<?>) g).targetType)) {
target = g;
break;
}
}
if (target != null) {
entity.targetSelector.removeGoal(target);
EntityType<? extends T> type = (EntityType<? extends T>) entity.getType();
if (typeCheck.test(type)) {
Predicate<LivingEntity> newPredicate = nonWerewolfCheck;
if (((Q) target).targetConditions.selector != null) {
newPredicate = newPredicate.and(((NearestAttackableTargetGoal<?>) target).targetConditions.selector);
}
entity.targetSelector.addGoal(attackPriority, replacement.apply(entity, newPredicate));
}
} else {
if (entityAIReplacementWarnMap.getOrDefault(name, true)) {
LOGGER.warn("Could not replace {} attack target task for {}", name, entity.getType().getDescription());
entityAIReplacementWarnMap.put(name, false);
}
}
} catch (Exception e) {
LOGGER.error("Could not replace " + name + " attack target task for " + entity.getType().getDescription(), e);
}
}
Aggregations