Skip to content

Commit

Permalink
forge: userdev for client mode now functions
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sanders <zidane@spongepowered.org>
  • Loading branch information
Zidane committed Aug 7, 2021
1 parent 86115d6 commit b657ee9
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 35 deletions.
31 changes: 31 additions & 0 deletions forge/src/main/java/org/spongepowered/forge/ForgeClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge;

import org.spongepowered.common.client.SpongeClient;

public interface ForgeClient extends ForgeEngine, SpongeClient {

}
22 changes: 21 additions & 1 deletion forge/src/main/java/org/spongepowered/forge/SpongeForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.WorldPersistenceHooks;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Client;
import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.common.applaunch.config.core.ConfigHandle;
import org.spongepowered.common.launch.Launch;
import org.spongepowered.common.launch.Lifecycle;
import org.spongepowered.common.network.channel.SpongeChannelManager;
import org.spongepowered.common.network.packet.SpongePacketHandler;
import org.spongepowered.forge.data.SpongeLevelDataPersistence;

@Mod(Constants.MOD_ID)
public final class SpongeForge {
Expand All @@ -55,6 +59,7 @@ public SpongeForge() {

// modBus: add all FML events with it
modBus.addListener(this::onCommonSetup);
modBus.addListener(this::onClientSetup);

// annotation events, for non-FML things
MinecraftForge.EVENT_BUS.register(this);
Expand All @@ -73,10 +78,19 @@ private void onCommonSetup(final FMLCommonSetupEvent event) {

// TODO Add attributes for HumanEntity to relevant event

// common setup
this.logger.info("SpongeForge v{} initialized", Launch.instance().platformPlugin().metadata().version());
}

private void onClientSetup(final FMLClientSetupEvent event) {
final Client minecraft = (Client) event.getMinecraftSupplier().get();
final Lifecycle lifecycle = Launch.instance().lifecycle();
lifecycle.establishGlobalRegistries();
lifecycle.establishDataProviders();
lifecycle.callRegisterDataEvent();
lifecycle.establishClientRegistries(minecraft);
lifecycle.callStartingEngineEvent(minecraft);
}

@SubscribeEvent
public void onServerAboutToStart(final FMLServerAboutToStartEvent event) {
// Save config now that registries have been initialized
Expand All @@ -97,4 +111,10 @@ public void onServerStarted(final FMLServerStartedEvent event) {
lifecycle.callStartedEngineEvent((Server) event.getServer());
}

@SubscribeEvent
public void onGameStopped(final FMLServerStoppedEvent event) {
final Lifecycle lifecycle = Launch.instance().lifecycle();
lifecycle.callStoppingEngineEvent((Server) event.getServer());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge;
package org.spongepowered.forge.data;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.storage.LevelStorageSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge.mixin.core.server.dedicated;
package org.spongepowered.forge.mixin.core.client;

import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.common.launch.Launch;
import org.spongepowered.common.launch.Lifecycle;
import org.spongepowered.forge.mixin.core.server.MinecraftServerMixin_Forge;
import org.spongepowered.common.bridge.client.MinecraftBridge;
import org.spongepowered.common.entity.player.ClientType;
import org.spongepowered.forge.ForgeClient;

@Mixin(DedicatedServer.class)
public abstract class DedicatedServerMixin_Forge extends MinecraftServerMixin_Forge {

@Inject(method = "initServer", at = @At("RETURN"))
private void forge$callLoadedGame(final CallbackInfoReturnable<Boolean> cir) {
final Lifecycle lifecycle = Launch.instance().lifecycle();

lifecycle.callLoadedGameEvent();
}
@Mixin(Minecraft.class)
public abstract class MinecraftMixin_Forge implements ForgeClient, MinecraftBridge {

@Override
protected void loadLevel() {
this.shadow$detectBundledResources();
this.worldManager().loadLevel();
public ClientType bridge$getClientType() {
return ClientType.SPONGE_FORGE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge.mixin.core.minecraftforge.fml;

import net.minecraftforge.fml.BrandingControl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(value = BrandingControl.class, remap = false)
public abstract class BrandingControlMixin_Forge {

/**
* @author Zidane
* @reason This is also not Kansas anymore
*/
@Overwrite
public static String getClientBranding() {
return "forge/spongeforge";
}

/**
* @author Zidane
* @reason What that said above
*/
@Overwrite
public static String getServerBranding() {
return "forge/spongeforge";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,9 @@
public abstract class MinecraftServerMixin_Forge implements ForgeServer {

// @formatter:off
@Shadow protected abstract void shadow$detectBundledResources();
@Shadow protected abstract void loadLevel();
@Shadow @Nullable public abstract ServerLevel shadow$getLevel(ResourceKey<Level> p_71218_1_);
// @formatter:on

/**
* @author Zidane
* @reason Apply our branding
*/
@Overwrite
public String getServerModName() {
return "spongeforge";
}

/**
* @author Zidane
* @reason We store the per-world tick time on the ServerLevel itself to more accurately track this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public abstract class ItemEntityMixin_Forge {

@Inject(method = "<init>(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN"))
private void forge$setLifespanFromConfig(EntityType<? extends ItemEntity> type, Level level, CallbackInfo ci) {
this.lifespan = SpongeGameConfigs.getForWorld(level).get().entity.item.despawnRate;
if (!level.isClientSide) {
this.lifespan = SpongeGameConfigs.getForWorld(level).get().entity.item.despawnRate;
}
}
}
3 changes: 2 additions & 1 deletion forge/src/mixins/resources/mixins.spongeforge.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
"mixins": [
"api.event.EventMixin_Forge",
"api.event.block.ChangeBlockEvent_AllMixin_Forge",
"client.MinecraftMixin_Forge",
"commands.CommandsMixin_Forge",
"minecraftforge.MinecraftForgeMixin_Forge",
"minecraftforge.event.world.BlockEvent_BreakEventMixin_Forge",
"minecraftforge.event.world.BlockEventMixin_Forge",
"minecraftforge.fml.BrandingControlMixin_Forge",
"minecraftforge.fml.FMLModContainerMixin_Forge",
"minecraftforge.fml.ModContainerMixin_Forge",
"server.BootstrapMixin_Forge",
"server.MainMixin_Forge",
"server.MinecraftServerMixin_Forge",
"server.dedicated.DedicatedServerMixin_Forge",
"server.level.ServerLevelMixin_Timings_Forge",
"world.entity.item.ItemEntityMixin_Forge",
"world.entity.vehicle.BoatMixin_Forge",
Expand Down

0 comments on commit b657ee9

Please sign in to comment.