Skip to content

Commit

Permalink
Backport to Minecraft 1.18.2 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hantonik authored Aug 30, 2024
1 parent 076573b commit 2ac4930
Show file tree
Hide file tree
Showing 30 changed files with 191 additions and 199 deletions.
4 changes: 2 additions & 2 deletions Common/src/main/java/hantonik/fbp/FancyBlockParticles.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static void postClientTick(Minecraft client) {

public static void onRenderHud(PoseStack stack, int width) {
if (FancyBlockParticles.CONFIG.global.isEnabled() && FancyBlockParticles.CONFIG.overlay.isFreezeEffectOverlay() && FancyBlockParticles.CONFIG.global.isFreezeEffect() && !Minecraft.getInstance().options.hideGui)
GuiComponent.drawCenteredString(stack, Minecraft.getInstance().font, Component.translatable("gui.fbp.freeze_effect").withStyle(ChatFormatting.BOLD), width / 2, 5, FancyBlockParticles.CONFIG.overlay.getFreezeEffectColor());
GuiComponent.drawCenteredString(stack, Minecraft.getInstance().font, new TranslatableComponent("gui.fbp.freeze_effect").withStyle(ChatFormatting.BOLD), width / 2, 5, FancyBlockParticles.CONFIG.overlay.getFreezeEffectColor());
}

public static void onClientPause(Screen screen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.gui.screens.OptionsScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -24,7 +25,7 @@ protected void init(CallbackInfo callback) {
this.height / 6 + 146 - 6,
150,
20,
Component.translatable("key.fbp.category").append("..."),
new TranslatableComponent("key.fbp.category").append("..."),
button -> this.minecraft.setScreen(new FBPOptionsScreen((OptionsScreen) (Object) this))
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.RenderShape;
Expand All @@ -33,14 +32,16 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Random;

@Mixin(ParticleEngine.class)
public abstract class MixinParticleEngine {
@Shadow
protected ClientLevel level;

@Final
@Shadow
private RandomSource random;
private Random random;

@Shadow
public abstract void add(Particle particle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void tick() {
if (!FancyBlockParticles.CONFIG.global.isFreezeEffect()) {
this.age++;

if (this.y < Minecraft.getInstance().player.getY() - (Minecraft.getInstance().options.renderDistance().get() * 9.0D))
if (this.y < Minecraft.getInstance().player.getY() - (Minecraft.getInstance().options.renderDistance * 9.0D))
this.remove();

if (!this.onGround) {
Expand Down Expand Up @@ -167,10 +167,10 @@ public void tick() {
this.gCol = (float) Mth.clamp(color.y + 0.1D, 0.1D, 1.0D);
this.bCol = (float) Mth.clamp(color.y + 0.5D, 0.5D, 1.0D);

if (Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) > Math.min(FancyBlockParticles.CONFIG.rain.getSimulationDistance(), Minecraft.getInstance().options.simulationDistance().get()) * 16)
if (Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) > Math.min(FancyBlockParticles.CONFIG.rain.getSimulationDistance(), Minecraft.getInstance().options.simulationDistance) * 16)
this.remove();

this.visible = Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) <= Math.min(FancyBlockParticles.CONFIG.rain.getRenderDistance(), Minecraft.getInstance().options.renderDistance().get()) * 16;
this.visible = Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) <= Math.min(FancyBlockParticles.CONFIG.rain.getRenderDistance(), Minecraft.getInstance().options.renderDistance) * 16;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CandleBlock;
Expand All @@ -23,6 +22,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Random;

public class FBPSmokeParticle extends SmokeParticle implements IKillableParticle {
private final Vec3[] rotatedCube;
Expand All @@ -43,7 +43,7 @@ public TextureAtlasSprite get(int age, int lifetime) {
}

@Override
public TextureAtlasSprite get(RandomSource random) {
public TextureAtlasSprite get(Random random) {
return FBPConstants.FBP_PARTICLE_SPRITE.get();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void tick() {
this.remove();

if (!FancyBlockParticles.CONFIG.global.isFreezeEffect()) {
if (this.y < Minecraft.getInstance().player.getY() - (Minecraft.getInstance().options.renderDistance().get() * 16.0D))
if (this.y < Minecraft.getInstance().player.getY() - (Minecraft.getInstance().options.renderDistance * 16.0D))
this.remove();

if (!FancyBlockParticles.CONFIG.snow.isInfiniteDuration() && !FancyBlockParticles.CONFIG.global.isInfiniteDuration())
Expand Down Expand Up @@ -229,10 +229,10 @@ public void tick() {
}
}

if (Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) > Math.min(FancyBlockParticles.CONFIG.snow.getSimulationDistance(), Minecraft.getInstance().options.simulationDistance().get()) * 16)
if (Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) > Math.min(FancyBlockParticles.CONFIG.snow.getSimulationDistance(), Minecraft.getInstance().options.simulationDistance) * 16)
this.remove();

this.visible = Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) <= Math.min(FancyBlockParticles.CONFIG.snow.getRenderDistance(), Minecraft.getInstance().options.renderDistance().get()) * 16;
this.visible = Minecraft.getInstance().cameraEntity.position().distanceTo(new Vec3(this.x, Minecraft.getInstance().cameraEntity.getY(), this.z)) <= Math.min(FancyBlockParticles.CONFIG.snow.getRenderDistance(), Minecraft.getInstance().options.renderDistance) * 16;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Random;

public class FBPWhiteSmokeParticle extends SmokeParticle implements IKillableParticle {
private final Vec3[] rotatedCube;
Expand All @@ -41,7 +41,7 @@ public TextureAtlasSprite get(int age, int lifetime) {
}

@Override
public TextureAtlasSprite get(RandomSource random) {
public TextureAtlasSprite get(Random random) {
return FBPConstants.FBP_PARTICLE_SPRITE.get();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import net.minecraft.world.level.biome.Biome;

public interface IClientHelper {
float getShade(float normalX, float normalY, float normalZ, boolean shade);

default Biome.Precipitation getPrecipitation(Holder<Biome> biome) {
return biome.value().getPrecipitation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.FormattedCharSequence;
import org.lwjgl.glfw.GLFW;

Expand All @@ -35,7 +36,7 @@ public abstract class FBPAbstractOptionsScreen extends Screen {
protected FBPOptionsList list;

public FBPAbstractOptionsScreen(Component title, Screen lastScreen, FBPConfig config) {
super(Component.translatable("key.fbp.category").append(" - ").append(title));
super(new TranslatableComponent("key.fbp.category").append(" - ").append(title));

this.activeConfig = config;
this.config = config.copy();
Expand All @@ -49,35 +50,35 @@ protected void init() {
this.initOptions();
this.addRenderableWidget(this.list);

this.addRenderableWidget(new FBPImageButton(10, 10, 25, 25, FBPOptionsScreen.LOGO_TEXTURE, button -> this.handleComponentClicked(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.curseforge.com/minecraft/mc-mods/fbp-renewed"))), Component.translatable("tooltip.fbp.common.homepage")));
this.addRenderableWidget(new FBPImageButton(this.width - 10 - 25, 10, 25, 25, FBPOptionsScreen.REPORT_TEXTURE, button -> this.handleComponentClicked(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Hantonik/FancyBlockParticles/issues"))), Component.translatable("tooltip.fbp.common.report")));
this.addRenderableWidget(new FBPImageButton(10, 10, 25, 25, FBPOptionsScreen.LOGO_TEXTURE, button -> this.handleComponentClicked(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.curseforge.com/minecraft/mc-mods/fbp-renewed"))), new TranslatableComponent("tooltip.fbp.common.homepage")));
this.addRenderableWidget(new FBPImageButton(this.width - 10 - 25, 10, 25, 25, FBPOptionsScreen.REPORT_TEXTURE, button -> this.handleComponentClicked(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Hantonik/FancyBlockParticles/issues"))), new TranslatableComponent("tooltip.fbp.common.report")));

var titleWidth = this.font.width(this.title.getVisualOrderText());
this.addRenderableWidget(new FBPStringWidget(this.width / 2 - titleWidth / 2, 62 / 2, titleWidth, 9, this.title, this.font));

this.addRenderableWidget(new Button(this.width / 2 - 310 / 2, this.height - 74 / 2 - 20 - 4 / 2, 310, 20, Component.translatable("button.fbp.common.reload"), button -> {
this.addRenderableWidget(new Button(this.width / 2 - 310 / 2, this.height - 74 / 2 - 20 - 4 / 2, 310, 20, new TranslatableComponent("button.fbp.common.reload"), button -> {
FancyBlockParticles.CONFIG.load();
this.config.setConfig(FancyBlockParticles.CONFIG.copy());
this.activeConfig.setConfig(FancyBlockParticles.CONFIG.copy());

this.minecraft.setScreen(new AlertScreen(() -> this.minecraft.setScreen(this), Component.translatable("button.fbp.common.reload"), Component.translatable("screen.fbp.reload_alert")));
this.minecraft.setScreen(new AlertScreen(() -> this.minecraft.setScreen(this), new TranslatableComponent("button.fbp.common.reload"), new TranslatableComponent("screen.fbp.reload_alert")));

this.rebuildWidgets();
}));

this.addRenderableWidget(new Button(this.width / 2 - 150 - 5, this.height - 74 / 2 + 4 / 2, 150, 20, Component.translatable("button.fbp.common.reset"), button -> this.minecraft.setScreen(new ConfirmScreen(confirm -> {
this.addRenderableWidget(new Button(this.width / 2 - 150 - 5, this.height - 74 / 2 + 4 / 2, 150, 20, new TranslatableComponent("button.fbp.common.reset"), button -> this.minecraft.setScreen(new ConfirmScreen(confirm -> {
if (confirm) {
this.resetConfig();

this.rebuildWidgets();
}

this.minecraft.setScreen(this);
}, Component.translatable("button.fbp.common.reset"), Component.translatable("screen.fbp.reset_confirm")))));
}, new TranslatableComponent("button.fbp.common.reset"), new TranslatableComponent("screen.fbp.reset_confirm")))));

this.addRenderableWidget(new Button(this.width / 2 + 5, this.height - 74 / 2 + 4 / 2, 150, 20, Component.translatable("button.fbp.common.done"), button -> this.onDone()));
this.addRenderableWidget(new Button(this.width / 2 + 5, this.height - 74 / 2 + 4 / 2, 150, 20, new TranslatableComponent("button.fbp.common.done"), button -> this.onDone()));

var version = Component.translatable("text.fbp.version", SharedConstants.getCurrentVersion().getName() + "-" + FancyBlockParticles.MOD_VERSION);
var version = new TranslatableComponent("text.fbp.version", SharedConstants.getCurrentVersion().getName() + "-" + FancyBlockParticles.MOD_VERSION);
this.addRenderableWidget(new FBPStringWidget(5, this.height - 3 - this.font.lineHeight, this.font.width(version), 9, version, this.font).alignLeft());

this.children().forEach(widget -> {
Expand Down Expand Up @@ -119,7 +120,7 @@ public void onClose() {
public void render(PoseStack stack, int mouseX, int mouseY, float partialTick) {
this.renderBackground(stack);

this.font.draw(stack, Component.translatable("text.fbp.version", SharedConstants.getCurrentVersion().getName() + "-" + FancyBlockParticles.MOD_VERSION), 5.0F, (float) this.height - 3.0F, 4210752);
this.font.draw(stack, new TranslatableComponent("text.fbp.version", SharedConstants.getCurrentVersion().getName() + "-" + FancyBlockParticles.MOD_VERSION), 5.0F, (float) this.height - 3.0F, 4210752);

super.render(stack, mouseX, mouseY, partialTick);

Expand All @@ -131,6 +132,12 @@ public void renderBackground(PoseStack stack) {
this.renderDirtBackground(0);
}

protected void rebuildWidgets() {
this.clearWidgets();
this.setFocused(null);
this.init();
}

protected void onDone() {
this.activeConfig.setConfig(this.config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.item.BlockItem;
Expand All @@ -28,14 +29,14 @@ public class FBPFastBlacklistScreen extends Screen {
private FBPBlacklistButton particleButton;

public FBPFastBlacklistScreen(BlockPos lookingAtPos) {
super(Component.translatable("screen.fbp.fast_blacklist"));
super(new TranslatableComponent("screen.fbp.fast_blacklist"));

this.state = Minecraft.getInstance().level.getBlockState(lookingAtPos);
this.displayStack = new ItemStack(this.state.getBlock());
}

public FBPFastBlacklistScreen(ItemStack heldItem) {
super(Component.translatable("screen.fbp.fast_blacklist"));
super(new TranslatableComponent("screen.fbp.fast_blacklist"));

this.state = ((BlockItem) heldItem.getItem()).getBlock().defaultBlockState();
this.displayStack = heldItem;
Expand Down Expand Up @@ -106,23 +107,23 @@ public void render(PoseStack stack, int mouseX, int mouseY, float partialTick) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

blit(stack, this.animationButton.x + 30, this.animationButton.y + 30 - 10, 0, 0, 195, 20);
drawCenteredString(stack, this.font, Component.literal("<").withStyle(this.animationButton.active ? ChatFormatting.GREEN : ChatFormatting.RED).append(" ").append(Component.literal(">").withStyle(this.particleButton.active ? ChatFormatting.GREEN : ChatFormatting.RED)), this.animationButton.x + 30 + 100, this.animationButton.y + 30 - 4, 0);
drawCenteredString(stack, this.font, new TextComponent("<").withStyle(this.animationButton.active ? ChatFormatting.GREEN : ChatFormatting.RED).append(" ").append(new TextComponent(">").withStyle(this.particleButton.active ? ChatFormatting.GREEN : ChatFormatting.RED)), this.animationButton.x + 30 + 100, this.animationButton.y + 30 - 4, 0);

drawCenteredString(stack, this.font, this.title.copy().withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), x, 10, 0);

var displayId = Registry.ITEM.getKey(this.displayStack.getItem());
drawCenteredString(stack, this.font, Component.literal(displayId.getNamespace()).withStyle(ChatFormatting.GOLD).append(Component.literal(":").withStyle(ChatFormatting.RED)).append(Component.literal(displayId.getPath()).withStyle(ChatFormatting.GREEN)).withStyle(ChatFormatting.BOLD), x, y - 19, 0);
drawCenteredString(stack, this.font, new TextComponent(displayId.getNamespace()).withStyle(ChatFormatting.GOLD).append(new TextComponent(":").withStyle(ChatFormatting.RED)).append(new TextComponent(displayId.getPath()).withStyle(ChatFormatting.GREEN)).withStyle(ChatFormatting.BOLD), x, y - 19, 0);

if (this.animationButton.isHovered()) {
drawCenteredString(stack, this.font, Component.translatable("tooltip.fbp.animation").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.animationButton.x + 30, this.animationButton.y + 30 - 42, 0);
drawCenteredString(stack, this.font, new TranslatableComponent("tooltip.fbp.animation").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.animationButton.x + 30, this.animationButton.y + 30 - 42, 0);

drawCenteredString(stack, this.font, this.animationButton.isBlackListed() ? Component.translatable("tooltip.fbp.remove").withStyle(ChatFormatting.BOLD, ChatFormatting.RED) : Component.translatable("tooltip.fbp.add").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.animationButton.x + 30, this.animationButton.y + 30 + 35, 0);
drawCenteredString(stack, this.font, this.animationButton.isBlackListed() ? new TranslatableComponent("tooltip.fbp.remove").withStyle(ChatFormatting.BOLD, ChatFormatting.RED) : new TranslatableComponent("tooltip.fbp.add").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.animationButton.x + 30, this.animationButton.y + 30 + 35, 0);
}

if (this.particleButton.isHovered()) {
drawCenteredString(stack, this.font, Component.translatable("tooltip.fbp.particles").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.particleButton.x + 30, this.particleButton.y + 30 - 42, 0);
drawCenteredString(stack, this.font, new TranslatableComponent("tooltip.fbp.particles").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.particleButton.x + 30, this.particleButton.y + 30 - 42, 0);

drawCenteredString(stack, this.font, this.particleButton.isBlackListed() ? Component.translatable("tooltip.fbp.remove").withStyle(ChatFormatting.BOLD, ChatFormatting.RED) : Component.translatable("tooltip.fbp.add").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.particleButton.x + 30, this.particleButton.y + 30 + 35, 0);
drawCenteredString(stack, this.font, this.particleButton.isBlackListed() ? new TranslatableComponent("tooltip.fbp.remove").withStyle(ChatFormatting.BOLD, ChatFormatting.RED) : new TranslatableComponent("tooltip.fbp.add").withStyle(ChatFormatting.BOLD, ChatFormatting.GREEN), this.particleButton.x + 30, this.particleButton.y + 30 + 35, 0);
}

var modelViewStack = RenderSystem.getModelViewStack();
Expand Down
Loading

0 comments on commit 2ac4930

Please sign in to comment.