类net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData源码实例Demo

下面列出了怎么用net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: patchwork-api   文件: FMLPlayMessages.java
public static void encode(SpawnEntity msg, PacketByteBuf buf) {
	buf.writeVarInt(msg.typeId);
	buf.writeInt(msg.entityId);
	buf.writeUuid(msg.uuid);
	buf.writeDouble(msg.posX);
	buf.writeDouble(msg.posY);
	buf.writeDouble(msg.posZ);
	buf.writeByte(msg.pitch);
	buf.writeByte(msg.yaw);
	buf.writeByte(msg.headYaw);
	buf.writeShort(msg.velX);
	buf.writeShort(msg.velY);
	buf.writeShort(msg.velZ);

	if (msg.entity instanceof IEntityAdditionalSpawnData) {
		((IEntityAdditionalSpawnData) msg.entity).writeSpawnData(buf);
	}
}
 
源代码2 项目: patchwork-api   文件: FMLPlayMessages.java
public static void handle(SpawnEntity msg, PacketContext context) {
	PatchworkNetworking.enqueueWork(context.getTaskQueue(), () -> {
		EntityType<?> type = Registry.ENTITY_TYPE.get(msg.typeId);

		if (type.equals(Registry.ENTITY_TYPE.get(Registry.ENTITY_TYPE.getDefaultId()))) {
			throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
		}

		ClientWorld world = MinecraftClient.getInstance().world;

		Entity entity = ((ClientEntitySpawner<?>) type).customClientSpawn(msg, world);

		if (entity == null) {
			return;
		}

		entity.updateTrackedPosition(msg.posX, msg.posY, msg.posZ);
		entity.updatePositionAndAngles(msg.posX, msg.posY, msg.posZ, (msg.yaw * 360) / 256.0F, (msg.pitch * 360) / 256.0F);
		entity.setHeadYaw((msg.headYaw * 360) / 256.0F);
		entity.setYaw((msg.headYaw * 360) / 256.0F);

		entity.setEntityId(msg.entityId);
		entity.setUuid(msg.uuid);
		world.addEntity(msg.entityId, entity);
		entity.setVelocity(msg.velX / 8000.0, msg.velY / 8000.0, msg.velZ / 8000.0);

		if (entity instanceof IEntityAdditionalSpawnData) {
			((IEntityAdditionalSpawnData) entity).readSpawnData(msg.buf);
		}
	});
}
 
 类方法
 同包方法