use of net.fabricmc.api.Environment in project MCDoom by AzureDoom.
the class EntityPacketOnClient method onPacket.
@Environment(EnvType.CLIENT)
public static void onPacket(PacketContext context, PacketByteBuf byteBuf) {
EntityType<?> type = Registry.ENTITY_TYPE.get(byteBuf.readVarInt());
UUID entityUUID = byteBuf.readUuid();
int entityID = byteBuf.readVarInt();
double x = byteBuf.readDouble();
double y = byteBuf.readDouble();
double z = byteBuf.readDouble();
float pitch = (byteBuf.readByte() * 360) / 256.0F;
float yaw = (byteBuf.readByte() * 360) / 256.0F;
context.getTaskQueue().execute(() -> {
@SuppressWarnings("resource") ClientWorld world = MinecraftClient.getInstance().world;
Entity entity = type.create(world);
if (entity != null) {
entity.updatePosition(x, y, z);
entity.updateTrackedPosition(x, y, z);
entity.setPitch(pitch);
entity.setYaw(yaw);
entity.setId(entityID);
entity.setUuid(entityUUID);
world.addEntity(entityID, entity);
}
});
}
use of net.fabricmc.api.Environment in project Blockus by Brandcraf06.
the class SpeedBlockItem method appendTooltip.
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
super.appendTooltip(stack, world, tooltip, context);
this.getBlock().appendTooltip(stack, world, tooltip, context);
tooltip.add((new TranslatableText(Blockus.MOD_ID + ".blockitem.givespeed")).formatted(Formatting.DARK_PURPLE));
}
use of net.fabricmc.api.Environment in project Primeval by devs-immortal.
the class PrimevalFluids method setupFluidRendering.
/*
* Fluid rendering setup from Spectrum,
* Made by DaFaqs, credit to him for this
* method
*/
@Environment(EnvType.CLIENT)
private static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath());
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
final Sprite[] fluidSprites = { null, null };
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void reload(ResourceManager manager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
@Override
public Identifier getFabricId() {
return listenerId;
}
});
// The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
final FluidRenderHandler renderHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
return fluidSprites;
}
@Override
public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
return color;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
// FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler); // Temp removed because of flowing shenanigans
}
use of net.fabricmc.api.Environment in project Primeval by devs-immortal.
the class ClayMoldItem method appendTooltip.
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
NbtCompound nbt = stack.getOrCreateNbt();
NbtCompound fluidNbt = nbt.getCompound("Fluid");
int fluidAmount = fluidNbt.getInt("Amount");
if (fluidAmount > 0) {
tooltip.add((new TranslatableText("text.primeval.fluid.contains", fluidAmount, new TranslatableText("block." + fluidNbt.getString("fluid").replace(':', '.')))).formatted(Formatting.GRAY));
}
tooltip.add((new TranslatableText("⚖ ").append(this.weight.getText()).append(" ⤧ ").append(this.size.getText())).formatted(Formatting.GRAY));
}
use of net.fabricmc.api.Environment in project StationAPI by ModificationStation.
the class MixinSoundHelper method loadModAudio.
@Environment(EnvType.CLIENT)
private static void loadModAudio(SoundMap array, String channel) {
try {
for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
ModMetadata stationMod = modContainer.getMetadata();
Path basePath = Paths.get("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel);
if (MixinSoundHelper.class.getResource(basePath.toString().replace("\\", "/")) != null) {
RecursiveReader recursiveReader = new RecursiveReader("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel, (filepath) -> filepath.endsWith(".ogg") || filepath.endsWith(".mp3") || filepath.endsWith(".wav"));
for (URL audioUrl : recursiveReader.read()) {
String audioID = audioUrl.toString().replace("\\", "/").split("/stationapi/sounds/" + channel)[1].replaceFirst("/", "");
((CustomSoundMap) array).putSound(stationMod.getId() + ":" + audioID, audioUrl);
}
}
}
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
Aggregations