use of net.minecraft.entity.EntityType in project Fragile-Glass by fredtargaryen.
the class KeyParser method getAllEntityTypesForString.
// /////////////////////////////////
// METHODS FOR PARSING ENTITYTYPES//
// /////////////////////////////////
public static Collection<EntityType<?>> getAllEntityTypesForString(String value) throws Exception {
Collection<EntityType<?>> entityTypes = new ArrayList<>();
if (value.charAt(0) == '#') {
// values[0] is a tag representing multiple entities
entityTypes = EntityTypeTags.getCollection().get(// Hopefully replaces GetOrCreate
new ResourceLocation(value.substring(1))).getAllElements();
} else {
// value is a single entity
entityTypes = new ArrayList<>();
// Check the first value is a ResourceLocation in the Forge EntityType registry, i.e. refers to a valid entity
EntityType entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(value));
if (entry == null) {
throw new Exception("There is no entity type with the resource location " + value + ".");
} else {
entityTypes.add(entry);
}
}
return entityTypes;
}
use of net.minecraft.entity.EntityType in project Structurize by ldtteam.
the class Blueprint method transformEntityInfoWithSettings.
/**
* Transform an entity and rotate it.
*
* @param entityInfo the entity nbt.
* @param world the world.
* @param pos the position.
* @param rotation the wanted rotation.
* @param mirror the mirror.
* @return the updated nbt.
*/
private CompoundNBT transformEntityInfoWithSettings(final CompoundNBT entityInfo, final World world, final BlockPos pos, final Rotation rotation, final Mirror mirror) {
final Optional<EntityType<?>> type = EntityType.by(entityInfo);
if (type.isPresent()) {
final Entity finalEntity = type.get().create(world);
if (finalEntity != null) {
try {
finalEntity.deserializeNBT(entityInfo);
final Vector3d entityVec = Blueprint.transformedVector3d(rotation, mirror, finalEntity.position()).add(Vector3d.atLowerCornerOf(pos));
finalEntity.yRotO = (float) (finalEntity.mirror(mirror) - NINETY_DEGREES);
final double rotationYaw = finalEntity.mirror(mirror) + ((double) finalEntity.mirror(mirror) - (double) finalEntity.rotate(rotation));
if (finalEntity instanceof HangingEntity) {
finalEntity.setPos(entityVec.x, entityVec.y, entityVec.z);
} else {
finalEntity.moveTo(entityVec.x, entityVec.y, entityVec.z, (float) rotationYaw, finalEntity.xRot);
}
return finalEntity.serializeNBT();
} catch (final Exception ex) {
Log.getLogger().error("Entity: " + type.get().getDescriptionId() + " failed to load. ", ex);
return null;
}
}
}
return null;
}
use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.
the class ChampionEggItem method onItemUse.
@Nonnull
@Override
public ActionResultType onItemUse(ItemUseContext context) {
World world = context.getWorld();
if (!world.isRemote() && world instanceof ServerWorld) {
ItemStack itemstack = context.getItem();
BlockPos blockpos = context.getPos();
Direction direction = context.getFace();
BlockState blockstate = world.getBlockState(blockpos);
BlockPos blockpos1;
if (blockstate.getCollisionShape(world, blockpos).isEmpty()) {
blockpos1 = blockpos;
} else {
blockpos1 = blockpos.offset(direction);
}
Optional<EntityType<?>> entitytype = getType(itemstack);
entitytype.ifPresent(type -> {
Entity entity = type.create((ServerWorld) world, itemstack.getTag(), null, context.getPlayer(), blockpos1, SpawnReason.SPAWN_EGG, true, !Objects.equals(blockpos, blockpos1) && direction == Direction.UP);
if (entity instanceof LivingEntity) {
ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> read(champion, itemstack));
world.addEntity(entity);
itemstack.shrink(1);
}
});
}
return ActionResultType.SUCCESS;
}
use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.
the class ChampionEggItem method getDisplayName.
@Nonnull
@Override
public ITextComponent getDisplayName(@Nonnull ItemStack stack) {
int tier = 0;
Optional<EntityType<?>> type = getType(stack);
if (stack.hasTag()) {
CompoundNBT tag = stack.getChildTag(CHAMPION_TAG);
if (tag != null) {
tier = tag.getInt(TIER_TAG);
}
}
IFormattableTextComponent root = new TranslationTextComponent("rank.champions.title." + tier);
root.appendString(" ");
root.append(type.map(EntityType::getName).orElse(EntityType.ZOMBIE.getName()));
root.appendString(" ");
root.append(new TranslationTextComponent(this.getTranslationKey(stack)));
return root;
}
use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.
the class Champions method setup.
private void setup(final FMLCommonSetupEvent evt) {
ChampionCapability.register();
NetworkHandler.register();
AffixManager.register();
evt.enqueueWork(() -> {
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation(Champions.MODID, "entity_champion"), EntityIsChampion.type);
DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() {
@Nonnull
@Override
public ItemStack dispenseStack(IBlockSource source, @Nonnull ItemStack stack) {
Direction direction = source.getBlockState().get(DispenserBlock.FACING);
Optional<EntityType<?>> entitytype = ChampionEggItem.getType(stack);
entitytype.ifPresent(type -> {
Entity entity = type.create(source.getWorld(), stack.getTag(), null, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, true, direction != Direction.UP);
if (entity instanceof LivingEntity) {
ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> ChampionEggItem.read(champion, stack));
source.getWorld().addEntity(entity);
stack.shrink(1);
}
});
return stack;
}
};
DispenserBlock.registerDispenseBehavior(ChampionsRegistry.EGG, dispenseBehavior);
ArgumentTypes.register(Champions.MODID + ":affix", AffixArgument.class, new ArgumentSerializer<>(AffixArgument::affix));
});
}
Aggregations