Files
StructureLib/src/main/java/com/gtnewhorizon/structurelib/CommonProxy.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
4.5 KiB
Java
Raw Normal View History

2022-08-08 17:40:12 +08:00
package com.gtnewhorizon.structurelib;
2022-09-02 15:45:13 +08:00
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
2022-08-08 17:40:12 +08:00
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
2022-08-23 12:29:59 +08:00
import net.minecraft.item.ItemStack;
2022-08-08 17:40:12 +08:00
import net.minecraft.server.MinecraftServer;
2022-09-02 15:45:13 +08:00
import net.minecraft.util.IChatComponent;
2022-08-08 17:40:12 +08:00
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
2024-08-07 16:37:30 +08:00
import net.minecraftforge.common.MinecraftForge;
2022-08-08 17:40:12 +08:00
2022-08-24 12:22:02 +08:00
import com.gtnewhorizon.structurelib.net.ErrorHintParticleMessage;
2022-08-08 17:40:12 +08:00
import com.gtnewhorizon.structurelib.net.UpdateHintParticleMessage;
2024-01-09 03:42:10 +00:00
2024-08-07 16:37:30 +08:00
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
2022-08-08 17:40:12 +08:00
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
2024-08-07 16:37:30 +08:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
2022-08-08 17:40:12 +08:00
public class CommonProxy {
2024-08-07 16:37:30 +08:00
public CommonProxy() {
super();
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
}
2022-08-08 17:40:12 +08:00
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {}
public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) {}
public void hintParticle(World w, int x, int y, int z, IIcon[] icons) {}
public void hintParticle(World w, int x, int y, int z, Block block, int meta) {}
public boolean updateHintParticleTint(EntityPlayer player, World w, int x, int y, int z, short[] rgBa) {
if (player instanceof EntityPlayerMP) { // just in case
StructureLib.net.sendTo(
new UpdateHintParticleMessage(x, (short) y, z, rgBa[0], rgBa[1], rgBa[2], rgBa[3]),
(EntityPlayerMP) player);
return true;
} else {
return false;
}
}
public EntityPlayer getCurrentPlayer() {
return null;
}
public boolean isCurrentPlayer(EntityPlayer player) {
return false;
}
public void addClientSideChatMessages(String... messages) {}
public void startHinting(World w) {}
public void endHinting(World w) {}
public void preInit(FMLPreInitializationEvent e) {}
public long getOverworldTime() {
return MinecraftServer.getServer().getEntityWorld().getTotalWorldTime();
}
2022-08-23 12:29:59 +08:00
public void uploadChannels(ItemStack trigger) {}
2022-08-24 11:28:26 +08:00
public boolean markHintParticleError(EntityPlayer player, World w, int x, int y, int z) {
2022-08-24 12:22:02 +08:00
if (player instanceof EntityPlayerMP) { // just in case
StructureLib.net.sendTo(new ErrorHintParticleMessage(x, (short) y, z), (EntityPlayerMP) player);
return true;
} else {
return false;
}
2022-08-24 11:28:26 +08:00
}
2022-09-02 15:45:13 +08:00
2024-08-07 16:37:30 +08:00
public void loadComplete(FMLLoadCompleteEvent e) {
ConfigurationHandler.INSTANCE.loadRegistryOrder();
}
2022-09-02 15:45:13 +08:00
private final Map<EntityPlayerMP, Map<Object, Long>> throttleMap = new WeakHashMap<>();
public void addThrottledChat(Object throttleKey, EntityPlayer player, IChatComponent text, short intervalRequired,
boolean forceUpdateLastSend) {
if (player instanceof EntityPlayerMP) {
Map<Object, Long> submap = throttleMap.computeIfAbsent((EntityPlayerMP) player, p -> new HashMap<>());
addThrottledChat(throttleKey, player, text, intervalRequired, forceUpdateLastSend, submap);
}
}
protected static void addThrottledChat(Object throttleKey, EntityPlayer player, IChatComponent text,
short intervalRequired, boolean forceUpdateLastSend, Map<Object, Long> submap) {
long now = System.currentTimeMillis();
Long old;
if (forceUpdateLastSend) {
old = submap.put(throttleKey, now);
} else {
old = submap.get(throttleKey);
}
if (old == null || now - old >= intervalRequired) {
player.addChatComponentMessage(text);
if (!forceUpdateLastSend) submap.put(throttleKey, now);
}
}
2024-08-07 16:37:30 +08:00
public void displayConfigGUI(String category) {}
public static class ForgeEventHandler {
private int ticksSinceLastPurge;
@SubscribeEvent
public void onServerTickEnd(TickEvent.ServerTickEvent e) {
if (e.phase != TickEvent.Phase.END) return;
if (++ticksSinceLastPurge < 20 * 60 * 10) return;
ticksSinceLastPurge = 0;
MinecraftServer server = MinecraftServer.getServer();
// it's hard to tell why server could be null in a server tick handler, but who knows?
if (server == null) return;
SortedRegistry.cleanup(server);
}
}
2022-08-08 17:40:12 +08:00
}