Skip to content

Commit

Permalink
Merge pull request #111 from Goodbird-git/screen-size
Browse files Browse the repository at this point in the history
Implemented the ability to get the screen size from server
  • Loading branch information
KAMKEEL authored Jan 18, 2024
2 parents cdd3f22 + c3b134b commit f3e162d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/noppes/npcs/PacketHandlerPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,9 @@ else if(type == EnumPlayerPacket.SaveBook){
tile.book.func_150996_a(Items.written_book);
}
}
else if(type == EnumPlayerPacket.ScreenSize){
int width = buffer.readInt(), height = buffer.readInt();
PlayerDataController.Instance.getPlayerData(player).screenSize.setSize(width,height);
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/noppes/npcs/client/ClientTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public class ClientTickHandler{
private World prevWorld;
private int prevWidth = 0;
private int prevHeight = 0;
private boolean otherContainer = false;
private int buttonPressed = -1;
private long buttonTime = 0L;
Expand Down Expand Up @@ -55,6 +57,11 @@ public void onClientTick(TickEvent.ClientTickEvent event){
MusicController.Instance.stopMusic();
}
ScriptSoundController.Instance.onUpdate();
if(Minecraft.getMinecraft().thePlayer!=null && (prevWidth!=mc.displayWidth || prevHeight!=mc.displayHeight)){
prevWidth = mc.displayWidth;
prevHeight = mc.displayHeight;
NoppesUtilPlayer.sendData(EnumPlayerPacket.ScreenSize,mc.displayWidth,mc.displayHeight);
}
}

@SubscribeEvent
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/noppes/npcs/constants/EnumPlayerPacket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package noppes.npcs.constants;

public enum EnumPlayerPacket {
FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp
FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp, ScreenSize
}
11 changes: 11 additions & 0 deletions src/main/java/noppes/npcs/controllers/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import noppes.npcs.entity.data.DataTimers;
import noppes.npcs.roles.RoleCompanion;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScreenSize;
import noppes.npcs.util.CustomNPCsThreader;
import noppes.npcs.util.NBTJsonUtil;

Expand Down Expand Up @@ -52,6 +53,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {

public boolean isGUIOpen = false;

public ScreenSize screenSize = new ScreenSize(-1,-1);

@Override
public void saveNBTData(NBTTagCompound nbtTagCompound) {
}
Expand Down Expand Up @@ -136,6 +139,14 @@ public boolean getGUIOpen() {
return this.isGUIOpen;
}

public ScreenSize getScreenSize(){
return screenSize;
}

public void setScreenSize(ScreenSize size){
screenSize = size;
}

public boolean hasCompanion(){
return activeCompanion != null && !activeCompanion.isDead;
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/noppes/npcs/scripted/ScreenSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package noppes.npcs.scripted;

import noppes.npcs.api.IScreenSize;

public class ScreenSize implements IScreenSize {
private int width;
private int height;

public ScreenSize(int width, int height) {
this.width = width;
this.height = height;
}

public void setSize(int width, int height) {
this.width = width;
this.height = height;
}

@Override
public int getWidth() {
return width;
}

@Override
public int getHeight() {
return height;
}

@Override
public int getWidthPercent(double percent) {
return (int) (((double)width)*percent/100);
}

@Override
public int getHeightPercent(double percent) {
return (int) (((double)height)*percent/100);
}
}
6 changes: 6 additions & 0 deletions src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ public ITimers getTimers() {
return PlayerDataController.Instance.getPlayerData(player).timers;
}

@Override
public IScreenSize getScreenSize() {
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
return data.getScreenSize() ;
}

public void updatePlayerInventory() {
((EntityPlayerMP)this.entity).inventoryContainer.detectAndSendChanges();
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
Expand Down

0 comments on commit f3e162d

Please sign in to comment.