Skip to content

Commit

Permalink
Forge 1.20.2
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Sep 26, 2023
1 parent 5422b8c commit 74f7fb3
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ unifiedPublishing {
curseforge {
token = CURSE_API_KEY
id = rootProject.curseforge_id
gameVersions.addAll "Java 17", "1.20.2-Snapshot"
gameVersions.addAll "Java 17", "1.20.2-Snapshot", project.minecraft_version
}
}

Expand Down
4 changes: 2 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ publishing {

unifiedPublishing {
project {
displayName = "[Forge $rootProject.supported_version] v$project.version"
displayName = "[MinecraftForge $rootProject.supported_version] v$project.version"
releaseType = "$rootProject.artifact_type"
changelog = releaseChangelog()
gameVersions = ["1.20", "1.20.1"]
gameVersions = ["1.20.2"]
gameLoaders = ["forge"]
mainPublication renameJarForPublication

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void eventInitScreenEvent(ScreenEvent.Init.Post event) {

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventRenderGameOverlayEvent(CustomizeGuiOverlayEvent.DebugText event) {
if (Minecraft.getInstance().options.renderDebug) {
if (Minecraft.getInstance().gui.getDebugOverlay().showDebugScreen()) {
ClientGuiEvent.DEBUG_TEXT_LEFT.invoker().gatherText(event.getLeft());
ClientGuiEvent.DEBUG_TEXT_RIGHT.invoker().gatherText(event.getRight());
}
Expand Down Expand Up @@ -217,14 +217,14 @@ public static void eventRenderTooltipEvent(RenderTooltipEvent.Color event) {

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Pre event) {
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getScrollDelta()).isFalse()) {
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
event.setCanceled(true);
}
}

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Post event) {
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getScrollDelta());
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY());
}

@SubscribeEvent(priority = EventPriority.HIGH)
Expand Down Expand Up @@ -301,7 +301,7 @@ public static void eventKeyboardKeyReleasedEvent(ScreenEvent.KeyReleased.Post ev

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventInputEvent(InputEvent.MouseScrollingEvent event) {
if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getScrollDelta()).isFalse()) {
if (ClientRawInputEvent.MOUSE_SCROLLED.invoker().mouseScrolled(Minecraft.getInstance(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkDirection;

import java.util.Collections;
import java.util.Set;

@OnlyIn(Dist.CLIENT)
public class ClientNetworkingManager {
public static void initClient() {
NetworkManagerImpl.CHANNEL.addListener(NetworkManagerImpl.createPacketHandler(NetworkEvent.ServerCustomPayloadEvent.class, NetworkManagerImpl.S2C_TRANSFORMERS));
NetworkManagerImpl.CHANNEL.addListener(NetworkManagerImpl.createPacketHandler(NetworkDirection.PLAY_TO_CLIENT, NetworkManagerImpl.S2C_TRANSFORMERS));
MinecraftForge.EVENT_BUS.register(ClientNetworkingManager.class);

NetworkManagerImpl.registerS2CReceiver(NetworkManagerImpl.SYNC_IDS, Collections.emptyList(), (buffer, context) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.event.EventNetworkChannel;
import org.apache.commons.lang3.tuple.Pair;
import net.minecraftforge.network.*;
import org.slf4j.Logger;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.function.Consumer;

Expand All @@ -71,7 +69,7 @@ public static Packet<?> toPacket(NetworkManager.Side side, ResourceLocation id,
FriendlyByteBuf packetBuffer = new FriendlyByteBuf(Unpooled.buffer());
packetBuffer.writeResourceLocation(id);
packetBuffer.writeBytes(buffer);
return (side == NetworkManager.Side.C2S ? NetworkDirection.PLAY_TO_SERVER : NetworkDirection.PLAY_TO_CLIENT).buildPacket(Pair.of(packetBuffer, 0), CHANNEL_ID).getThis();
return (side == NetworkManager.Side.C2S ? NetworkDirection.PLAY_TO_SERVER : NetworkDirection.PLAY_TO_CLIENT).buildPacket(packetBuffer, CHANNEL_ID).getThis();
}

public static void collectPackets(PacketSink sink, NetworkManager.Side side, ResourceLocation id, FriendlyByteBuf buf) {
Expand All @@ -88,7 +86,7 @@ public static void collectPackets(PacketSink sink, NetworkManager.Side side, Res
private static final Logger LOGGER = LogUtils.getLogger();
private static final ResourceLocation CHANNEL_ID = new ResourceLocation("architectury:network");
static final ResourceLocation SYNC_IDS = new ResourceLocation("architectury:sync_ids");
static final EventNetworkChannel CHANNEL = NetworkRegistry.newEventChannel(CHANNEL_ID, () -> "1", version -> true, version -> true);
static final EventNetworkChannel CHANNEL = ChannelBuilder.named(CHANNEL_ID).acceptedVersions((status, version) -> true).optional().eventNetworkChannel();
static final Map<ResourceLocation, NetworkReceiver> S2C = Maps.newHashMap();
static final Map<ResourceLocation, NetworkReceiver> C2S = Maps.newHashMap();
static final Map<ResourceLocation, PacketTransformer> S2C_TRANSFORMERS = Maps.newHashMap();
Expand All @@ -97,7 +95,7 @@ public static void collectPackets(PacketSink sink, NetworkManager.Side side, Res
private static final Multimap<Player, ResourceLocation> clientReceivables = Multimaps.newMultimap(Maps.newHashMap(), Sets::newHashSet);

static {
CHANNEL.addListener(createPacketHandler(NetworkEvent.ClientCustomPayloadEvent.class, C2S_TRANSFORMERS));
CHANNEL.addListener(createPacketHandler(NetworkDirection.PLAY_TO_SERVER, C2S_TRANSFORMERS));

DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> ClientNetworkingManager::initClient);

Expand All @@ -111,10 +109,10 @@ public static void collectPackets(PacketSink sink, NetworkManager.Side side, Res
});
}

static <T extends NetworkEvent> Consumer<T> createPacketHandler(Class<T> clazz, Map<ResourceLocation, PacketTransformer> map) {
static <T extends CustomPayloadEvent> Consumer<T> createPacketHandler(NetworkDirection direction, Map<ResourceLocation, PacketTransformer> map) {
return event -> {
if (event.getClass() != clazz) return;
NetworkEvent.Context context = event.getSource().get();
CustomPayloadEvent.Context context = event.getSource();
if (context.getDirection() != direction) return;
if (context.getPacketHandled()) return;
FriendlyByteBuf buffer = event.getPayload();
if (buffer == null) return;
Expand Down Expand Up @@ -182,7 +180,19 @@ public static boolean canPlayerReceive(ServerPlayer player, ResourceLocation id)
}

public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity) {
return (Packet<ClientGamePacketListener>) NetworkHooks.getEntitySpawningPacket(entity);
try {
// I love forge
Constructor<?> constructor = Class.forName("net.minecraftforge.network.packets.SpawnEntity").getDeclaredConstructor(Entity.class);
constructor.setAccessible(true);
Object message = constructor.newInstance(entity);
Packet<ClientGamePacketListener>[] packet = new Packet[1];
NetworkInitialization.PLAY.send(message, new PacketDistributor.PacketTarget(p -> {
packet[0] = (Packet<ClientGamePacketListener>) p;
}, NetworkDirection.PLAY_TO_CLIENT));
return Objects.requireNonNull(packet[0], "Expected packet to be sent!");
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

static FriendlyByteBuf sendSyncPacket(Map<ResourceLocation, NetworkReceiver> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.network.NetworkHooks;

public class MenuRegistryImpl {
public static void openExtendedMenu(ServerPlayer player, ExtendedMenuProvider provider) {
NetworkHooks.openScreen(player, provider, provider::saveExtraData);
player.openMenu(provider, provider::saveExtraData);
}

public static <T extends AbstractContainerMenu> MenuType<T> of(SimpleMenuTypeFactory<T> factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public static class RegistryBuilderWrapper<T> implements RegistrarBuilder<T> {
private final RegistryProviderImpl provider;
private final net.minecraftforge.registries.RegistryBuilder<?> builder;
private final ResourceLocation registryId;
private boolean saveToDisk = false;
private boolean syncToClients = false;

public RegistryBuilderWrapper(RegistryProviderImpl provider, RegistryBuilder<?> builder, ResourceLocation registryId) {
Expand All @@ -283,7 +282,7 @@ public RegistryBuilderWrapper(RegistryProviderImpl provider, RegistryBuilder<?>
@Override
public Registrar<T> build() {
if (!syncToClients) builder.disableSync();
if (!saveToDisk) builder.disableSaving();
builder.disableSaving();
if (provider.builders == null) {
throw new IllegalStateException("Cannot create registries when registries are already aggregated!");
}
Expand All @@ -301,9 +300,7 @@ public Registrar<T> build() {

@Override
public RegistrarBuilder<T> option(RegistrarOption option) {
if (option == StandardRegistrarOption.SAVE_TO_DISC) {
this.saveToDisk = true;
} else if (option == StandardRegistrarOption.SYNC_TO_CLIENTS) {
if (option == StandardRegistrarOption.SYNC_TO_CLIENTS) {
this.syncToClients = true;
}
return this;
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ side = "BOTH"
[[dependencies.architectury]]
modId = "forge"
mandatory = true
versionRange = "[46,)"
versionRange = "[48,)"
ordering = "NONE"
side = "BOTH"
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false

platforms=fabric
platforms=fabric,forge

minecraft_version=1.20.2-pre4
supported_version=1.20.2-pre4
minecraft_version=1.20.2
supported_version=1.20.2

artifact_type=beta
artifact_type=release

archives_base_name=architectury
archives_base_name_snapshot=architectury-snapshot
base_version=10.0
maven_group=dev.architectury

fabric_loader_version=0.14.22
fabric_api_version=0.88.4+1.20.2
fabric_api_version=0.89.1+1.20.2
mod_menu_version=7.0.0

forge_version=46.0.1
forge_version=48.0.1

curseforge_id=419699
modrinth_id=lhGA9TYQ
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ if (JavaVersion.current().ordinal() + 1 < 17) {

include("common")
include("fabric")
//include("forge")
include("forge")
include("testmod-common")
include("testmod-fabric")
//include("testmod-forge")
include("testmod-forge")

rootProject.name = "architectury"
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public TestEntity(EntityType<? extends Cow> entityType, Level level) {
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
// Custom packets broken in BundlePacket
// return NetworkManager.createAddEntityPacket(this);
return super.getAddEntityPacket();
return NetworkManager.createAddEntityPacket(this);
}
}

0 comments on commit 74f7fb3

Please sign in to comment.