* Fixed bogus friend list (*I THINK*)

+ Added enableSoundDistance and ytVolume settings in config
* YT player volume now depends on global sound volume
- Removed debug messages
* Updated README
This commit is contained in:
Nicolas BARBOTIN 2018-02-12 01:34:05 +01:00
parent c266b6c1f4
commit 6d6a64e2de
7 changed files with 35 additions and 73 deletions

View File

@ -2,10 +2,9 @@
This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The text below is my "TODO" list. This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The text below is my "TODO" list.
### Bugs to fix ### Bugs to fix
* Bugged friend list
* Multiply volume by game volume (and add a config option to disable distance<->volume thingy)
* Memory leak (screens aren't deleted?!?) * Memory leak (screens aren't deleted?!?)
* GUIs are not closed blocks gets destroyed * GUIs are not closed blocks gets destroyed
* Remove remaining printed debug infos and check for TODOs
### Things before release ### Things before release
* Fix bugs (obviously) * Fix bugs (obviously)

View File

@ -114,6 +114,8 @@ public class WebDisplays {
public int maxScreenY; public int maxScreenY;
public int miniservPort; public int miniservPort;
public long miniservQuota; public long miniservQuota;
public boolean enableSoundDistance;
public float ytVolume;
@Mod.EventHandler @Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent ev) { public void onPreInit(FMLPreInitializationEvent ev) {
@ -133,6 +135,8 @@ public class WebDisplays {
Property maxScreenY = cfg.get("main", "maxScreenSizeY", 16); Property maxScreenY = cfg.get("main", "maxScreenSizeY", 16);
Property loadDistance = cfg.get("client", "loadDistance", 30.0); Property loadDistance = cfg.get("client", "loadDistance", 30.0);
Property unloadDistance = cfg.get("client", "unloadDistance", 32.0); Property unloadDistance = cfg.get("client", "unloadDistance", 32.0);
Property enableSndDist = cfg.get("client", "enableSoundDistance", true);
Property ytVolume = cfg.get("client", "ytVolume", 100.0);
blacklist.setComment("An array of domain names you don't want to load."); blacklist.setComment("An array of domain names you don't want to load.");
padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO); padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO);
@ -148,6 +152,10 @@ public class WebDisplays {
miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)"); miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)");
maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX."); maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX.");
maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY."); maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY.");
enableSndDist.setComment("If true, the volume of YouTube videos will change depending on how far you are");
ytVolume.setComment("Volume for YouTube videos. This will have no effect if enableSoundDistance is set to false");
ytVolume.setMinValue(0.0);
ytVolume.setMaxValue(100.0);
if(unloadDistance.getDouble() < loadDistance.getDouble() + 2.0) if(unloadDistance.getDouble() < loadDistance.getDouble() + 2.0)
unloadDistance.set(loadDistance.getDouble() + 2.0); unloadDistance.set(loadDistance.getDouble() + 2.0);
@ -166,6 +174,8 @@ public class WebDisplays {
this.miniservQuota = miniservQuota.getLong() * 1024L; this.miniservQuota = miniservQuota.getLong() * 1024L;
this.maxScreenX = maxScreenX.getInt(); this.maxScreenX = maxScreenX.getInt();
this.maxScreenY = maxScreenY.getInt(); this.maxScreenY = maxScreenY.getInt();
enableSoundDistance = enableSndDist.getBoolean();
this.ytVolume = (float) ytVolume.getDouble();
CREATIVE_TAB = new WDCreativeTab(); CREATIVE_TAB = new WDCreativeTab();

View File

@ -57,6 +57,7 @@ import net.montoyo.wd.miniserv.client.Client;
import net.montoyo.wd.net.server.SMessagePadCtrl; import net.montoyo.wd.net.server.SMessagePadCtrl;
import net.montoyo.wd.net.server.SMessageScreenCtrl; import net.montoyo.wd.net.server.SMessageScreenCtrl;
import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.*;
import paulscode.sound.SoundSystemConfig;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -477,8 +478,8 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi
if(tes.isLoaded()) { if(tes.isLoaded()) {
if(dist2 > WebDisplays.INSTANCE.unloadDistance2) if(dist2 > WebDisplays.INSTANCE.unloadDistance2)
tes.unload(); tes.unload();
else else if(WebDisplays.INSTANCE.enableSoundDistance)
tes.updateTrackDistance(dist2); tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain());
} else if(dist2 <= WebDisplays.INSTANCE.loadDistance2) } else if(dist2 <= WebDisplays.INSTANCE.loadDistance2)
tes.load(); tes.load();
} }

View File

@ -309,30 +309,15 @@ public class GuiScreenConfig extends WDScreen {
} }
public boolean isFriendCheckbox(CheckBox cb) { public boolean isFriendCheckbox(CheckBox cb) {
for(CheckBox box : friendBoxes) { return Arrays.stream(friendBoxes).anyMatch(fb -> cb == fb);
if(box == cb)
return true;
}
return false;
} }
public boolean isOtherCheckbox(CheckBox cb) { public boolean isOtherCheckbox(CheckBox cb) {
for(CheckBox box : otherBoxes) { return Arrays.stream(otherBoxes).anyMatch(ob -> cb == ob);
if(box == cb)
return true;
}
return false;
} }
public boolean hasFriend(NameUUIDPair f) { public boolean hasFriend(NameUUIDPair f) {
for(NameUUIDPair pair : friends) { return Arrays.stream(friends).anyMatch(f::equals);
if(pair.equals(f))
return true;
}
return false;
} }
@Override @Override

View File

@ -102,8 +102,6 @@ public class TileEntityScreen extends TileEntity {
for(int i = 0; i < upgrades.tagCount(); i++) for(int i = 0; i < upgrades.tagCount(); i++)
ret.upgrades.add(new ItemStack(upgrades.getCompoundTagAt(i))); ret.upgrades.add(new ItemStack(upgrades.getCompoundTagAt(i)));
System.out.println("Read " + ret.upgrades.size() + " upgrades from NBT"); //TODO: Remove me
return ret; return ret;
} }
@ -141,7 +139,6 @@ public class TileEntityScreen extends TileEntity {
for(ItemStack is: upgrades) for(ItemStack is: upgrades)
list.appendTag(is.writeToNBT(new NBTTagCompound())); list.appendTag(is.writeToNBT(new NBTTagCompound()));
System.out.println("Saved " + list.tagCount() + " upgrades"); //TODO: Remove me
tag.setTag("Upgrades", list); tag.setTag("Upgrades", list);
return tag; return tag;
} }
@ -482,9 +479,6 @@ public class TileEntityScreen extends TileEntity {
} }
if(scr.browser != null) { if(scr.browser != null) {
if(event != CMessageScreenUpdate.MOUSE_MOVE)
System.out.println(String.format("handleMouseEvent2 %d @ %d, %d", event, vec == null ? -1 : vec.x, vec == null ? -1 : vec.y));
if(event == CMessageScreenUpdate.MOUSE_CLICK) { if(event == CMessageScreenUpdate.MOUSE_CLICK) {
scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target scr.browser.injectMouseMove(vec.x, vec.y, 0, false); //Move to target
scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press scr.browser.injectMouseButton(vec.x, vec.y, 0, 1, true, 1); //Press
@ -645,7 +639,8 @@ public class TileEntityScreen extends TileEntity {
return renderBB; return renderBB;
} }
public void updateTrackDistance(double d) { //FIXME: Not called if enableSoundDistance is false
public void updateTrackDistance(double d, float masterVolume) {
boolean needsComputation = true; boolean needsComputation = true;
int intPart = 0; //Need to initialize those because the compiler is stupid int intPart = 0; //Need to initialize those because the compiler is stupid
int fracPart = 0; int fracPart = 0;
@ -656,19 +651,19 @@ public class TileEntityScreen extends TileEntity {
float dist = (float) Math.sqrt(d); float dist = (float) Math.sqrt(d);
float vol; float vol;
if(dist <= 10.f) if(dist <= 10.0f)
vol = 100.f; vol = masterVolume * WebDisplays.INSTANCE.ytVolume;
else if(dist >= 30.f) else if(dist >= 30.0f)
vol = 0.f; vol = 0.0f;
else else
vol = (1.f - (dist - 10.f) / 20.f) * 100.f; vol = (1.0f - (dist - 10.0f) / 20.0f) * masterVolume * WebDisplays.INSTANCE.ytVolume;
if(Math.abs(ytVolume - vol) < 0.5f) if(Math.abs(ytVolume - vol) < 0.5f)
return; //Delta is too small return; //Delta is too small
ytVolume = vol; ytVolume = vol;
intPart = (int) vol; //Manually convert to string, probably faster in that case... intPart = (int) vol; //Manually convert to string, probably faster in that case...
fracPart = ((int) (vol * 100.f)) - intPart * 100; fracPart = ((int) (vol * 100.0f)) - intPart * 100;
needsComputation = false; needsComputation = false;
} }
@ -705,10 +700,8 @@ public class TileEntityScreen extends TileEntity {
public void invalidate() { public void invalidate() {
super.invalidate(); super.invalidate();
if(world.isRemote) { if(world.isRemote)
Log.info("===> TES(INVALIDATE) %s", pos.toString());
onChunkUnload(); onChunkUnload();
}
} }
public void addFriend(EntityPlayerMP ply, BlockSide side, NameUUIDPair pair) { public void addFriend(EntityPlayerMP ply, BlockSide side, NameUUIDPair pair) {

View File

@ -4,7 +4,6 @@
package net.montoyo.wd.net.client; package net.montoyo.wd.net.client;
import com.mojang.authlib.GameProfile;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@ -20,17 +19,6 @@ public class CMessageACResult implements IMessage, Runnable {
public CMessageACResult() { public CMessageACResult() {
} }
public CMessageACResult(GameProfile gp) {
result = new NameUUIDPair[] { new NameUUIDPair(gp) };
}
public CMessageACResult(GameProfile[] gps) {
result = new NameUUIDPair[gps.length];
for(int i = 0; i < gps.length; i++)
result[i] = new NameUUIDPair(gps[i]);
}
public CMessageACResult(NameUUIDPair[] pairs) { public CMessageACResult(NameUUIDPair[] pairs) {
result = pairs; result = pairs;
} }

View File

@ -19,6 +19,7 @@ import net.montoyo.wd.net.client.CMessageACResult;
import net.montoyo.wd.utilities.NameUUIDPair; import net.montoyo.wd.utilities.NameUUIDPair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
@Message(messageId = 5, side = Side.SERVER) @Message(messageId = 5, side = Side.SERVER)
public class SMessageACQuery implements IMessage, Runnable { public class SMessageACQuery implements IMessage, Runnable {
@ -39,9 +40,6 @@ public class SMessageACQuery implements IMessage, Runnable {
public void fromBytes(ByteBuf buf) { public void fromBytes(ByteBuf buf) {
beginning = ByteBufUtils.readUTF8String(buf); beginning = ByteBufUtils.readUTF8String(buf);
matchExact = buf.readBoolean(); matchExact = buf.readBoolean();
if(!matchExact)
beginning = beginning.toLowerCase();
} }
@Override @Override
@ -53,28 +51,16 @@ public class SMessageACQuery implements IMessage, Runnable {
@Override @Override
public void run() { public void run() {
GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles(); GameProfile[] profiles = WebDisplays.PROXY.getOnlineGameProfiles();
NameUUIDPair[] result;
if(matchExact) { if(matchExact)
for(GameProfile gp : profiles) { result = Arrays.stream(profiles).filter(gp -> gp.getName().equalsIgnoreCase(beginning)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
if(gp.getName().equals(beginning)) { else {
WebDisplays.NET_HANDLER.sendTo(new CMessageACResult(gp), player); final String lBeg = beginning.toLowerCase();
return; result = Arrays.stream(profiles).filter(gp -> gp.getName().toLowerCase().startsWith(lBeg)).map(NameUUIDPair::new).toArray(NameUUIDPair[]::new);
}
WebDisplays.NET_HANDLER.sendTo(new CMessageACResult(new NameUUIDPair[0]), player);
}
} else {
ArrayList<NameUUIDPair> results = new ArrayList<>();
for(GameProfile gp : profiles) {
if(gp.getName().toLowerCase().startsWith(beginning)) {
results.add(new NameUUIDPair(gp));
break;
}
}
WebDisplays.NET_HANDLER.sendTo(new CMessageACResult(results.toArray(new NameUUIDPair[0])), player);
} }
WebDisplays.NET_HANDLER.sendTo(new CMessageACResult(result), player);
} }
public static class Handler implements IMessageHandler<SMessageACQuery, IMessage> { public static class Handler implements IMessageHandler<SMessageACQuery, IMessage> {