2022-08-08 17:40:12 +08:00
|
|
|
package com.gtnewhorizon.structurelib;
|
|
|
|
|
|
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;
|
|
|
|
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
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;
|
|
|
|
|
|
|
|
|
|
public class CommonProxy {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-08 17:40:12 +08:00
|
|
|
}
|