Skip to content

Commit

Permalink
Update to 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jul 8, 2024
1 parent 0c1711d commit 59444c9
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 57 deletions.
15 changes: 11 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'idea'
id 'eclipse'

id 'fabric-loom' version '0.13-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'

id 'com.modrinth.minotaur' version '2.+'
Expand Down Expand Up @@ -78,7 +78,12 @@ sourceSets { main { resources { srcDirs += dataOutput } } }

/* Resource Processing */

import groovy.json.*

import com.modrinth.minotaur.dependencies.DependencyType
import com.modrinth.minotaur.dependencies.ModDependency
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

processResources {
// populate fabric.mod.json with defined version property
inputs.property 'version', version
Expand Down Expand Up @@ -124,7 +129,6 @@ def VER_NAME = "[$project.major_version] $project.mod_name $project.version_id"
def CHANGELOG = new File("./gradle", "CHANGELOG.md").text
def SUPPORTED_VERSIONS = Arrays.asList(project.supported_versions.split(','))

import org.kohsuke.github.*
task github(dependsOn: build) {
onlyIf { ENV.GITHUB_TOKEN }
doLast {
Expand All @@ -140,7 +144,10 @@ task github(dependsOn: build) {
}
}

import com.modrinth.minotaur.dependencies.*

import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub

if (ENV.MODRINTH_TOKEN) modrinth {
token = ENV.MODRINTH_TOKEN
projectId = project.modrinth_id
Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ maven_group = me.andante.noclip

mod_id = noclip
mod_name = noclip
version_id = 1.1.5
version_id = 1.2.0

release_type = release
github_repository = andantet/noclip-fabric

modrinth_id = yDx6WroB
curseforge_id = 653377

major_version = 1.19.4
github_branch = 1.19.4
supported_versions = 1.19.4
major_version = 1.20.6
github_branch = 1.20.6
supported_versions = 1.20.6

# Versions
ver_minecraft = 1.19.4
ver_loader = 0.14.17
ver_yarn = 1
ver_minecraft = 1.20.6
ver_loader = 0.15.11
ver_yarn = 3

ver_fabric = 0.75.3+1.19.4
ver_cloth_config = 10.0.95
ver_mod_menu = 6.1.0-rc.1
ver_fabric = 0.100.4+1.20.6
ver_cloth_config = 14.0.126
ver_mod_menu = 10.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 0 additions & 2 deletions src/main/java/me/andante/noclip/api/NoClip.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.andante.noclip.api;

import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -10,5 +9,4 @@ public interface NoClip {
Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

String NBT_KEY = NoClip.MOD_ID + ":clipping";
Identifier PACKET_ID = new Identifier(NoClip.MOD_ID, "update");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.Window;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.Collection;
import java.util.function.Predicate;

import static net.minecraft.util.math.MathHelper.*;
import static net.minecraft.util.math.MathHelper.abs;
import static net.minecraft.util.math.MathHelper.clamp;
import static net.minecraft.util.math.MathHelper.sin;

/**
* Responsible for rendering an indicator on the hud of the player's current clipping state.
* <p>The current instance used by the client can be obtained by {@link NoClipClientImpl#NOCLIP_HUD_RENDERER}.</p>
*/
@Environment(EnvType.CLIENT)
public class NoClipHudRenderer extends DrawableHelper implements HudRenderCallback {
public class NoClipHudRenderer implements HudRenderCallback {
public static final Identifier TEXTURE = new Identifier(NoClip.MOD_ID, "textures/gui/noclip.png");

private long fade = -1;
Expand All @@ -36,7 +38,7 @@ public class NoClipHudRenderer extends DrawableHelper implements HudRenderCallba
public NoClipHudRenderer() {}

@Override
public void onHudRender(MatrixStack matrices, float tickDelta) {
public void onHudRender(DrawContext context, float tickDelta) {
if (!NoClipManager.INSTANCE.isClipping() || !NoClipClient.getConfig().display.hudIcon) {
this.fade = -1;
return;
Expand All @@ -50,30 +52,25 @@ public void onHudRender(MatrixStack matrices, float tickDelta) {
Collection<StatusEffectInstance> effects = client.player.getStatusEffects();
boolean hasStatusEffect = effects.stream().anyMatch(StatusEffectInstance::shouldShowIcon);
boolean hasNonBeneficialEffect = effects.stream()
.filter(StatusEffectInstance::shouldShowIcon)
.map(StatusEffectInstance::getEffectType)
.anyMatch(Predicate.not(StatusEffect::isBeneficial));
.filter(StatusEffectInstance::shouldShowIcon)
.map(StatusEffectInstance::getEffectType)
.map(RegistryEntry::value)
.anyMatch(Predicate.not(StatusEffect::isBeneficial));

// render
RenderSystem.setShaderTexture(0, TEXTURE);
RenderSystem.enableBlend();

long ms = Util.getMeasuringTimeMs();
float interval = 1000f;
if (this.fade == -1) this.fade = ms + (long) interval;
float alpha = abs(sin((ms - this.fade) / interval)) + 0.2F;
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, clamp(alpha, 0.0F, 1.0F));

if (client.options.debugEnabled) {
this.renderIcon(matrices, scaledWidth - 18 - (client.textRenderer.getWidth(this.activeDebugLine) + 4), client.textRenderer.fontHeight + 1);
} else this.renderIcon(matrices, scaledWidth - 18 - 2, (2 + (hasStatusEffect ? 25 + (hasNonBeneficialEffect ? 25 + 1 : 0) : 0)));

RenderSystem.disableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
if (client.inGameHud.getDebugHud().shouldShowDebugHud()) {
this.renderIcon(context, scaledWidth - 18 - (client.textRenderer.getWidth(this.activeDebugLine) + 4), client.textRenderer.fontHeight + 1);
} else this.renderIcon(context, scaledWidth - 18 - 2, (2 + (hasStatusEffect ? 25 + (hasNonBeneficialEffect ? 25 + 1 : 0) : 0)));
}

public void renderIcon(MatrixStack matrices, int x, int y) {
drawTexture(matrices, x, y, 0, 0, 18, 18, 18, 18);
public void renderIcon(DrawContext context, int x, int y) {
context.drawTexture(TEXTURE, x, y, 0, 0, 18, 18, 18, 18);
}

public void setActiveDebugLine(String activeDebugLine) {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/me/andante/noclip/impl/ClippingUpdatePacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.andante.noclip.impl;

import me.andante.noclip.api.NoClip;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public record ClippingUpdatePacket(boolean clipping) implements CustomPayload {
public static final PacketCodec<PacketByteBuf, ClippingUpdatePacket> CODEC = CustomPayload.codecOf(ClippingUpdatePacket::write, ClippingUpdatePacket::new);
public static final Id<ClippingUpdatePacket> ID = new CustomPayload.Id<>(new Identifier(NoClip.MOD_ID, "update"));

private ClippingUpdatePacket(PacketByteBuf buf) {
this(buf.readBoolean());
}

private void write(PacketByteBuf buf) {
buf.writeBoolean(this.clipping);
}

@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}
17 changes: 9 additions & 8 deletions src/main/java/me/andante/noclip/impl/NoClipImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import me.andante.noclip.api.NoClip;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -19,7 +18,10 @@ public void onInitialize() {
LOGGER.info("Initializing {}", MOD_NAME);

// networking
ServerPlayNetworking.registerGlobalReceiver(PACKET_ID, this::receiveUpdate);
PayloadTypeRegistry.playC2S().register(ClippingUpdatePacket.ID, ClippingUpdatePacket.CODEC);
PayloadTypeRegistry.playS2C().register(ClippingUpdatePacket.ID, ClippingUpdatePacket.CODEC);

ServerPlayNetworking.registerGlobalReceiver(ClippingUpdatePacket.ID, this::receiveUpdate);
ServerPlayConnectionEvents.JOIN.register(this::onPlayerJoin);

// death
Expand All @@ -30,17 +32,16 @@ public void onInitialize() {
* Updates the client player on server join.
*/
private void onPlayerJoin(ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) {
PacketByteBuf buf = PacketByteBufs.create();
ClippingEntity clippingPlayer = ClippingEntity.cast(handler.player);
buf.writeBoolean(clippingPlayer.isClipping());
ServerPlayNetworking.send(handler.player, PACKET_ID, buf);
ServerPlayNetworking.send(handler.player, new ClippingUpdatePacket(clippingPlayer.isClipping()));
}

/**
* Receives a clipping update from the client.
*/
private void receiveUpdate(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) {
boolean clipping = buf.readBoolean();
private void receiveUpdate(ClippingUpdatePacket packet, ServerPlayNetworking.Context context) {
ServerPlayerEntity player = context.player();
boolean clipping = packet.clipping();
ClippingEntity clippingPlayer = ClippingEntity.cast(player);
clippingPlayer.setClipping(clipping);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.andante.noclip.api.client.command.NoClipClientCommand;
import me.andante.noclip.api.client.keybinding.NoClipKeyBindings;
import me.andante.noclip.api.client.render.NoClipHudRenderer;
import me.andante.noclip.impl.ClippingUpdatePacket;
import me.andante.noclip.impl.client.keybinding.NoClipKeyBindingsImpl;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
Expand All @@ -20,15 +21,14 @@
public final class NoClipClientImpl implements NoClipClient, ClientModInitializer {
public static final NoClipHudRenderer NOCLIP_HUD_RENDERER = new NoClipHudRenderer();

@SuppressWarnings("UnstableApiUsage")
@Override
public void onInitializeClient() {
LOGGER.info("Initializing {}-CLIENT", MOD_NAME);

Reflection.initialize(NoClipClient.class, NoClipKeyBindings.class, NoClipManager.class);

// networking
ClientPlayNetworking.registerGlobalReceiver(PACKET_ID, NoClipManagerImpl::onServerUpdate);
ClientPlayNetworking.registerGlobalReceiver(ClippingUpdatePacket.ID, NoClipManagerImpl::onServerUpdate);
ClientPlayConnectionEvents.DISCONNECT.register(NoClipManagerImpl::onDisconnect);

// keybinding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package me.andante.noclip.impl.client;

import me.andante.noclip.api.NoClip;
import me.andante.noclip.api.client.NoClipClient;
import me.andante.noclip.api.client.NoClipManager;
import me.andante.noclip.api.client.keybinding.NoClipKeyBindings;
import me.andante.noclip.impl.ClippingEntity;
import me.andante.noclip.impl.ClippingUpdatePacket;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;

@Environment(EnvType.CLIENT)
public final class NoClipManagerImpl implements NoClipManager {
Expand Down Expand Up @@ -53,9 +50,7 @@ public void updateClipping(boolean sendToServer) {
}

if (sendToServer) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeBoolean(clipping);
ClientPlayNetworking.send(NoClip.PACKET_ID, buf);
ClientPlayNetworking.send(new ClippingUpdatePacket(clipping));
}
}

Expand All @@ -64,9 +59,9 @@ public void updateClipping(boolean sendToServer) {
/**
* Receives a clipping update from the server.
*/
public static void onServerUpdate(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) {
public static void onServerUpdate(ClippingUpdatePacket packet, ClientPlayNetworking.Context context) {
if (NoClipClient.getConfig().keyBehaviors.noClip.toggles()) {
boolean clipping = buf.readBoolean();
boolean clipping = packet.clipping();

NoClipManager clipManager = NoClipManager.INSTANCE;
clipManager.setCanClip(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void onInit(World world, BlockPos pos, float yaw, GameProfile profile, C
private void onTickAfterNoClip(CallbackInfo ci) {
if (this.isClipping()) {
this.noClip = true;
this.onGround = false;
this.setOnGround(false);
this.fallDistance = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MouseMixin {
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true
)
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci, double scroll, int delta) {
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci, boolean discreteMouseScroll, double sensitivity, double e, double f, int deltaHorizontal, int deltaVertical, int delta) {
if (!NoClipKeyBindings.ACTIVATE_FLIGHT_SPEED_SCROLL.isPressed()) return;

NoClipConfig config = NoClipClient.getConfig();
Expand Down

0 comments on commit 59444c9

Please sign in to comment.