Cleaned up TotemOfReviving by moving most setup code to the new SideProxy.
This commit is contained in:
@ -1,53 +1,39 @@
|
||||
package dev.micle.totemofreviving;
|
||||
|
||||
import dev.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
||||
import dev.micle.totemofreviving.network.C2SRequestTotemCharge;
|
||||
import dev.micle.totemofreviving.network.C2SRequestTotemTarget;
|
||||
import dev.micle.totemofreviving.setup.Registration;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mod(TotemOfReviving.MOD_ID)
|
||||
public class TotemOfReviving {
|
||||
public static final String MOD_ID = "totemofreviving";
|
||||
public static PlayerList players;
|
||||
|
||||
private static final String PROTOCOL_VERSION = "1";
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation(TotemOfReviving.MOD_ID, "main"),
|
||||
() -> PROTOCOL_VERSION,
|
||||
PROTOCOL_VERSION::equals,
|
||||
PROTOCOL_VERSION::equals
|
||||
);
|
||||
public final class TotemOfReviving {
|
||||
public static final String MOD_ID = "totemofreviving";
|
||||
public static final String MOD_NAME = "Micle's Totem of Reviving";
|
||||
|
||||
public static final String RESOURCE_PREFIX = MOD_ID + ':';
|
||||
|
||||
public static final Random RANDOM = new Random();
|
||||
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
|
||||
|
||||
public static TotemOfReviving INSTANCE;
|
||||
public static SideProxy SIDE_PROXY;
|
||||
|
||||
public TotemOfReviving() {
|
||||
Registration.register();
|
||||
|
||||
int id = 0;
|
||||
INSTANCE.registerMessage(id++,
|
||||
C2SRequestPlayerRevive.class,
|
||||
C2SRequestPlayerRevive::encode,
|
||||
C2SRequestPlayerRevive::decode,
|
||||
C2SRequestPlayerRevive::handle
|
||||
);
|
||||
INSTANCE.registerMessage(id++,
|
||||
C2SRequestTotemTarget.class,
|
||||
C2SRequestTotemTarget::encode,
|
||||
C2SRequestTotemTarget::decode,
|
||||
C2SRequestTotemTarget::handle
|
||||
);
|
||||
INSTANCE.registerMessage(id++,
|
||||
C2SRequestTotemCharge.class,
|
||||
C2SRequestTotemCharge::encode,
|
||||
C2SRequestTotemCharge::decode,
|
||||
C2SRequestTotemCharge::handle
|
||||
);
|
||||
|
||||
// Register ourselves for server and other game events we are interested in
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
INSTANCE = this;
|
||||
SIDE_PROXY = DistExecutor.safeRunForDist(
|
||||
() -> SideProxy.Client::new,
|
||||
() -> SideProxy.Server::new
|
||||
);
|
||||
}
|
||||
|
||||
public static ResourceLocation createResourceLocation(String name) {
|
||||
if (name.contains(":")) {
|
||||
throw new IllegalArgumentException("name containes namespace");
|
||||
}
|
||||
return new ResourceLocation(MOD_ID, name);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user