Skip to content

Commit

Permalink
Backport to Minecraft 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hantonik committed Feb 21, 2024
1 parent 0a6d2b6 commit 4b27338
Show file tree
Hide file tree
Showing 116 changed files with 1,204 additions and 5,776 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
mkdir artifacts
cp Fabric/build/libs/*.jar artifacts
cp Forge/build/libs/*.jar artifacts
cp NeoForge/build/libs/*.jar artifacts
- name: 'Upload artifacts'
uses: actions/upload-artifact@v3
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
mkdir artifacts
cp Fabric/build/libs/*.jar artifacts
cp Forge/build/libs/*.jar artifacts
cp NeoForge/build/libs/*.jar artifacts
- name: 'Upload artifacts'
uses: actions/upload-artifact@v3
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
mkdir artifacts
cp Fabric/build/libs/*.jar artifacts
cp Forge/build/libs/*.jar artifacts
cp NeoForge/build/libs/*.jar artifacts
- name: 'Upload artifacts'
uses: actions/upload-artifact@v3
Expand Down
6 changes: 1 addition & 5 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ loom {
}

repositories {
maven { url 'https://maven.minecraftforge.net/' }
maven { url 'https://maven.parchmentmc.org' }
}

Expand All @@ -58,15 +57,12 @@ dependencies {

mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.20.3:$mappings_version@zip") // Waiting for 1.20.4
parchment("org.parchmentmc.data:parchment-$mc_version:$mappings_version@zip")
}

modImplementation "net.fabricmc:fabric-loader:$loader_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version+$mc_version"

modCompileOnly "com.github.glitchfiend:SereneSeasons-fabric:$mc_version-$sereneseasons_version"
modCompileOnly "com.github.glitchfiend:GlitchCore-fabric:$mc_version-$glitchcore_version"

compileOnly "org.projectlombok:lombok:$lombok_version"
annotationProcessor "org.projectlombok:lombok:$lombok_version"
}
Expand Down
9 changes: 5 additions & 4 deletions Fabric/src/main/java/hantonik/fbp/FancyBlockParticles.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hantonik.fbp;

import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.logging.LogUtils;
import hantonik.fbp.config.FBPConfig;
import hantonik.fbp.init.FBPKeyMappings;
Expand All @@ -14,11 +15,11 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.particle.ParticleEngine;
import net.minecraft.client.particle.ParticleRenderType;
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 @@ -88,8 +89,8 @@ private void postClientTick(Minecraft client) {
FancyBlockParticles.CONFIG.setFrozen(!FancyBlockParticles.CONFIG.isFrozen());
}

public void onRenderHud(GuiGraphics graphics, float partialTick) {
public void onRenderHud(PoseStack stack, float partialTick) {
if (FancyBlockParticles.CONFIG.isEnabled() && FancyBlockParticles.CONFIG.isFrozen())
graphics.drawCenteredString(Minecraft.getInstance().font, Component.translatable("screen.fbp.freeze"), graphics.guiWidth() / 2, 5, 0x0080FF);
GuiComponent.drawCenteredString(stack, Minecraft.getInstance().font, new TranslatableComponent("screen.fbp.freeze"), Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2, 5, 0x0080FF);
}
}
10 changes: 5 additions & 5 deletions Fabric/src/main/java/hantonik/fbp/config/FBPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.Util;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -315,15 +315,15 @@ public void reload() {
this.disabledParticles = Util.make(Lists.newArrayList(), disabled -> {
if (json.has("disabledParticles")) {
for (var entry : GsonHelper.getAsJsonArray(json, "disabledParticles"))
disabled.add(BuiltInRegistries.BLOCK.get(new ResourceLocation(entry.getAsString())));
disabled.add(Registry.BLOCK.get(new ResourceLocation(entry.getAsString())));
} else
disabled.addAll(DEFAULT_DISABLED_PARTICLES);
});

this.disabledAnimations = Util.make(Lists.newArrayList(), disabled -> {
if (json.has("disabledAnimations")) {
for (var entry : GsonHelper.getAsJsonArray(json, "disabledAnimations"))
disabled.add(BuiltInRegistries.BLOCK.get(new ResourceLocation(entry.getAsString())));
disabled.add(Registry.BLOCK.get(new ResourceLocation(entry.getAsString())));
} else
disabled.addAll(DEFAULT_DISABLED_ANIMATIONS);
});
Expand Down Expand Up @@ -377,12 +377,12 @@ public void save() {

json.add("disabledParticles", Util.make(new JsonArray(), disabled -> {
for (var entry : this.disabledParticles)
disabled.add(BuiltInRegistries.BLOCK.getKey(entry).toString());
disabled.add(Registry.BLOCK.getKey(entry).toString());
}));

json.add("disabledAnimations", Util.make(new JsonArray(), disabled -> {
for (var entry : this.disabledAnimations)
disabled.add(BuiltInRegistries.BLOCK.getKey(entry).toString());
disabled.add(Registry.BLOCK.getKey(entry).toString());
}));

GSON.toJson(json, writer);
Expand Down
45 changes: 27 additions & 18 deletions Fabric/src/main/java/hantonik/fbp/mixins/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.Tesselator;
import hantonik.fbp.FancyBlockParticles;
import hantonik.fbp.particle.FBPRainParticle;
import hantonik.fbp.particle.FBPSnowParticle;
import hantonik.fbp.util.FBPConstants;
import hantonik.fbp.util.FBPUtils;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
Expand Down Expand Up @@ -59,26 +59,27 @@ private void tickRain(Camera camera, CallbackInfo callback) {
var x = this.minecraft.player.getX() + xd + radius * Math.cos(angle);
var z = this.minecraft.player.getZ() + zd + radius * Math.sin(angle);

if (this.minecraft.player.distanceToSqr(x, this.minecraft.player.getY(), z) > this.minecraft.options.renderDistance().get() * 32.0D)
if (this.minecraft.player.distanceToSqr(x, this.minecraft.player.getY(), z) > this.minecraft.options.renderDistance * 32.0D)
continue;

var pos = BlockPos.containing(x, this.minecraft.player.getY(), z);
var pos = new BlockPos(x, this.minecraft.player.getY(), z);
var biome = this.level.getBiome(pos).value();
var surfaceHeight = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos).getY();

var y = (int) (this.minecraft.player.getY() + 15.0D + FBPConstants.RANDOM.nextDouble() * 10.0D + (this.minecraft.player.getDeltaMovement().y * 6.0D));

if (y <= surfaceHeight + 2)
y = surfaceHeight + 10;

var precipitation = FBPUtils.getPrecipitationAtLevelRenderer(this.level.getBiome(pos), pos);

if (precipitation == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else if (precipitation == Biome.Precipitation.SNOW) {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
if (biome.getPrecipitation() != Biome.Precipitation.NONE) {
if (biome.warmEnoughToRain(pos)) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
}
}
}
Expand All @@ -90,17 +91,25 @@ private void addParticle(ClientLevel instance, ParticleOptions particleData, dou
instance.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
}

@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;", shift = At.Shift.AFTER), method = "renderSnowAndRain", cancellable = true)
private void renderSnowAndRain(LightTexture lightTexture, float partialTick, double camX, double camY, double camZ, CallbackInfo callback, @Local Biome.Precipitation precipitation) {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitation()Lnet/minecraft/world/level/biome/Biome$Precipitation;"), method = "renderSnowAndRain", cancellable = true)
private void renderSnowAndRain(LightTexture lightTexture, float partialTick, double camX, double camY, double camZ, CallbackInfo callback, @Local BlockPos.MutableBlockPos mutableBlockPos, @Local(ordinal = 4) int i1) {
if (FancyBlockParticles.CONFIG.isEnabled()) {
if (precipitation == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
callback.cancel();
var biome = this.level.getBiome(mutableBlockPos).value();
var rain = biome.warmEnoughToRain(mutableBlockPos);

if (biome.getPrecipitation() != Biome.Precipitation.NONE) {
if (rain && FancyBlockParticles.CONFIG.isFancyRain())
callback.cancel();

if (precipitation == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
callback.cancel();
if ((!rain || biome.coldEnoughToSnow(mutableBlockPos)) && FancyBlockParticles.CONFIG.isFancySnow())
callback.cancel();
}
}

if (callback.isCancelled()) {
if (i1 >= 0)
Tesselator.getInstance().end();

RenderSystem.enableCull();
RenderSystem.disableBlend();
lightTexture.turnOffLightLayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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.block.LiquidBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -30,14 +29,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 effect);
Expand Down Expand Up @@ -82,7 +83,7 @@ public void destroy(BlockPos pos, BlockState state, CallbackInfo callback) {

callback.cancel();

if (!state.isAir() && state.shouldSpawnTerrainParticles()) {
if (!state.isAir()) {
var shape = state.getShape(this.level, pos);
var sprite = Minecraft.getInstance().getBlockRenderer().getBlockModelShaper().getParticleIcon(state);

Expand Down
Loading

0 comments on commit 4b27338

Please sign in to comment.