use of net.minecraft.entity.EntityType in project Client by MatHax.
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 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);
}
}
use of net.minecraft.entity.EntityType in project endergetic by team-abnormals.
the class PuffBugBottleItem method use.
@Override
public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
if (worldIn.isClientSide) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
} else {
RayTraceResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
} else {
BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) raytraceresult;
BlockPos blockpos = blockraytraceresult.getBlockPos();
if (!(worldIn.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock)) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
} else if (worldIn.mayInteract(playerIn, blockpos) && playerIn.mayUseItemAt(blockpos, blockraytraceresult.getDirection(), itemstack)) {
EntityType<?> entitytype = EEEntities.PUFF_BUG.get();
if (entitytype.spawn((ServerWorld) worldIn, itemstack, playerIn, blockpos, SpawnReason.SPAWN_EGG, false, false) == null) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
} else {
if (!playerIn.abilities.instabuild) {
this.emptyBottle(playerIn, handIn);
}
playerIn.awardStat(Stats.ITEM_USED.get(this));
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}
} else {
return new ActionResult<>(ActionResultType.FAIL, itemstack);
}
}
}
}
use of net.minecraft.entity.EntityType in project ImmersivePortalsMod by qouteall.
the class MyNetworkClient method processStcSpawnEntity.
private static void processStcSpawnEntity(PacketContext context, PacketByteBuf buf) {
String entityTypeString = buf.readString();
int entityId = buf.readInt();
int dimId = buf.readInt();
DimensionType dimensionType = DimensionType.byRawId(dimId);
CompoundTag compoundTag = buf.readCompoundTag();
if (dimensionType == null) {
Helper.err(String.format("Invalid dimension for spawning entity %s %s %s", dimId, entityTypeString, compoundTag));
}
Optional<EntityType<?>> entityType = EntityType.get(entityTypeString);
if (!entityType.isPresent()) {
Helper.err("unknown entity type " + entityTypeString);
return;
}
MinecraftClient.getInstance().execute(() -> {
ClientWorld world = CGlobal.clientWorldLoader.getOrCreateFakedWorld(dimensionType);
if (world.getEntityById(entityId) != null) {
Helper.err(String.format("duplicate entity %s %s %s", ((Integer) entityId).toString(), entityType.get(), compoundTag));
return;
}
Entity entity = entityType.get().create(world);
entity.fromTag(compoundTag);
entity.setEntityId(entityId);
entity.updateTrackedPosition(entity.x, entity.y, entity.z);
world.addEntity(entityId, entity);
return;
});
}
use of net.minecraft.entity.EntityType in project bioplethora by AquexTheSeal.
the class BioplethoraSpawnEggItem method initUnaddedEggs.
public static void initUnaddedEggs() {
final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {
@Override
public ItemStack execute(IBlockSource source, ItemStack stack) {
Direction direction = source.getBlockState().getValue(DispenserBlock.FACING);
EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
entitytype.spawn(source.getLevel(), stack, null, source.getPos().relative(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
stack.shrink(1);
return stack;
}
};
for (final SpawnEggItem egg : UNADDED_EGGS) {
EGGS.put(egg.getType(null), egg);
DispenserBlock.registerBehavior(egg, defaultDispenseItemBehavior);
}
UNADDED_EGGS.clear();
}
Aggregations