Skip to content

Commit

Permalink
Update NeoForge to 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Apr 27, 2024
1 parent 1eec322 commit 55eac01
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
group=org.popcraft
artifactName=ChunkyBorder
version=1.2
target=1.4.5
target=1.4.7
target_dynmap=3.3
target_bluemap=v2.1.0
target_squaremap=1.1.2
Expand Down
6 changes: 3 additions & 3 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ repositories {
}

dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = "1.20.2")
minecraft(group = "com.mojang", name = "minecraft", version = "1.20.5")
mappings(loom.officialMojangMappings())
neoForge(group = "net.neoforged", name = "neoforge", version = "20.2.88")
neoForge(group = "net.neoforged", name = "neoforge", version = "20.5.5-beta")
modImplementation(group = "org.popcraft", name = "chunky-neoforge", version = "${project.property("target")}")
compileOnly(group = "us.dynmap", name = "DynmapCoreAPI", version = "${project.property("target_dynmap")}")
compileOnly(group = "com.github.BlueMap-Minecraft", name = "BlueMapAPI", version = "${project.property("target_bluemap")}")
Expand All @@ -29,7 +29,7 @@ dependencies {

tasks {
processResources {
filesMatching("META-INF/mods.toml") {
filesMatching("META-INF/neoforge.mods.toml") {
expand(
"id" to rootProject.name,
"version" to project.version,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.popcraft.chunkyborder;

import io.netty.buffer.Unpooled;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLPaths;
Expand All @@ -17,6 +17,7 @@
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import org.joml.Vector3f;
import org.popcraft.chunky.Chunky;
import org.popcraft.chunky.ChunkyProvider;
Expand All @@ -29,10 +30,12 @@
import org.popcraft.chunky.util.Translator;
import org.popcraft.chunkyborder.command.BorderCommand;
import org.popcraft.chunkyborder.integration.DynmapCommonAPIProvider;
import org.popcraft.chunkyborder.packet.BorderPayload;
import org.popcraft.chunkyborder.platform.Config;
import org.popcraft.chunkyborder.platform.MapIntegrationLoader;
import org.popcraft.chunkyborder.shape.BorderShape;
import org.popcraft.chunkyborder.util.BorderColor;
import org.popcraft.chunkyborder.util.ClientBorder;
import org.popcraft.chunkyborder.util.Particles;
import org.popcraft.chunkyborder.util.PluginMessage;

Expand All @@ -41,25 +44,43 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@Mod(ChunkyBorderNeoForge.MOD_ID)
public class ChunkyBorderNeoForge {
public static final String MOD_ID = "chunkyborder";
private static final ResourceLocation PLAY_BORDER_PACKET_ID = new ResourceLocation("chunky", "border");
private static final Map<ResourceLocation, BorderShape> borderShapes = new ConcurrentHashMap<>();
private static Config config;
private ChunkyBorder chunkyBorder;
private BorderCheckTask borderCheckTask;
private boolean initialized;

public ChunkyBorderNeoForge() {
public ChunkyBorderNeoForge(final IEventBus modBus) {
try {
Class.forName("org.dynmap.DynmapCommonAPI");
new DynmapCommonAPIProvider();
} catch (ClassNotFoundException ignored) {
// Dynmap is not installed
}
NeoForge.EVENT_BUS.register(this);
modBus.addListener((Consumer<RegisterPayloadHandlersEvent>) event -> event.registrar(String.valueOf(PluginMessage.VERSION))
.optional()
.playToClient(BorderPayload.ID, CustomPacketPayload.codec(BorderPayload::write, BorderPayload::new), (borderPayload, context) -> {
final ClientBorder clientBorder = borderPayload.getBorder();
if (clientBorder.worldKey() == null) {
return;
}
final ResourceLocation identifier = ResourceLocation.tryParse(clientBorder.worldKey());
if (identifier == null) {
return;
}
final BorderShape borderShape = clientBorder.borderShape();
if (borderShape == null) {
ChunkyBorderNeoForge.borderShapes.remove(identifier);
} else {
ChunkyBorderNeoForge.borderShapes.put(identifier, borderShape);
}
}));
}

@SubscribeEvent
Expand Down Expand Up @@ -135,22 +156,11 @@ public void onServerTick(final TickEvent.ServerTickEvent event) {
}

private void sendBorderPacket(final Collection<ServerPlayer> players, final World world, final Shape shape) {
final FriendlyByteBuf data = new FriendlyByteBuf(Unpooled.buffer())
.writeResourceLocation(PLAY_BORDER_PACKET_ID)
.writeBytes(PluginMessage.writeBorder(world, shape));
for (final ServerPlayer player : players) {
player.connection.send(new ClientboundCustomPayloadPacket(data));
}
}

public static void setBorderShape(final String id, final BorderShape borderShape) {
final ResourceLocation identifier = ResourceLocation.tryParse(id);
if (identifier != null) {
if (borderShape == null) {
ChunkyBorderNeoForge.borderShapes.remove(identifier);
} else {
ChunkyBorderNeoForge.borderShapes.put(identifier, borderShape);
if (!player.connection.hasChannel(BorderPayload.ID)) {
continue;
}
player.connection.send(new ClientboundCustomPayloadPacket(new BorderPayload(world, shape)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.Util;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class LevelRendererMixin {
@Inject(method = "renderWorldBorder", at = @At("HEAD"), cancellable = true)
@SuppressWarnings("java:S3776")
private void renderWorldBorder(final Camera camera, final CallbackInfo ci) {
final BorderShape borderShape = ChunkyBorderNeoForge.getBorderShape(this.level.dimensionTypeId().location());
final BorderShape borderShape = ChunkyBorderNeoForge.getBorderShape(this.level.dimension().location());
if (borderShape == null) {
return;
}
Expand Down Expand Up @@ -87,9 +86,6 @@ private void renderWorldBorder(final Camera camera, final CallbackInfo ci) {
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
RenderSystem.setShaderTexture(0, FORCEFIELD_LOCATION);
RenderSystem.depthMask(Minecraft.useShaderTransparency());
PoseStack poseStack = RenderSystem.getModelViewStack();
poseStack.pushPose();
RenderSystem.applyModelViewMatrix();
final int color = BorderColor.getColor();
final float red = (color >> 16 & 255) / 255.0F;
final float green = (color >> 8 & 255) / 255.0F;
Expand Down Expand Up @@ -207,8 +203,6 @@ private void renderWorldBorder(final Camera camera, final CallbackInfo ci) {
RenderSystem.disablePolygonOffset();
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
poseStack.popPose();
RenderSystem.applyModelViewMatrix();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.depthMask(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.popcraft.chunkyborder.packet;

import io.netty.buffer.ByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import org.jetbrains.annotations.NotNull;
import org.popcraft.chunky.platform.World;
import org.popcraft.chunky.shape.Shape;
import org.popcraft.chunkyborder.util.ClientBorder;
import org.popcraft.chunkyborder.util.PluginMessage;

public class BorderPayload implements CustomPacketPayload {
public static final CustomPacketPayload.Type<BorderPayload> ID = CustomPacketPayload.createType("chunky:border");
private World world;
private Shape shape;
private ClientBorder border;

public BorderPayload(final World world, final Shape shape) {
this.world = world;
this.shape = shape;
}

public BorderPayload(final FriendlyByteBuf buf) {
final ByteBuf unwrapped = buf.unwrap();
final byte[] bytes = new byte[unwrapped.readableBytes()];
unwrapped.readBytes(bytes);
this.border = PluginMessage.readBorder(bytes);
}

public void write(final FriendlyByteBuf buf) {
buf.writeBytes(PluginMessage.writeBorder(world, shape));
}

public ClientBorder getBorder() {
return border;
}

@Override
public CustomPacketPayload.@NotNull Type<BorderPayload> type() {
return ID;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[1,)"
loaderVersion="[3,)"
license="GNU GPLv3"
issueTrackerURL="${github}/issues"
[[mods]]
Expand All @@ -13,13 +13,13 @@ description="${description}"
[[dependencies.chunkyborder]]
modId="neoforge"
mandatory=true
versionRange="[20.2,)"
versionRange="[20.5-beta,)"
ordering="NONE"
side="BOTH"
[[dependencies.chunkyborder]]
modId="minecraft"
mandatory=true
versionRange="[1.20.2,1.21)"
versionRange="[1.20.5,1.21)"
ordering="NONE"
side="BOTH"
[[dependencies.chunkyborder]]
Expand Down

0 comments on commit 55eac01

Please sign in to comment.