Skip to content

Commit db319b6

Browse files
Merge pull request #24 from XTerPL/XTer-3
Tons of small things
2 parents dadd24c + 5bffa65 commit db319b6

21 files changed

+362
-58
lines changed

src/main/java/io/github/techstreet/dfscript/event/RecieveSoundEvent.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
package io.github.techstreet.dfscript.event;
22

33
import io.github.techstreet.dfscript.event.system.CancellableEvent;
4+
import net.minecraft.client.sound.SoundInstance;
5+
import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket;
6+
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
47
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
8+
import net.minecraft.sound.SoundEvent;
9+
import net.minecraft.util.Identifier;
510

611
public class RecieveSoundEvent implements CancellableEvent {
712
private boolean cancelled = false;
8-
private final PlaySoundS2CPacket packet;
913

10-
public RecieveSoundEvent(PlaySoundS2CPacket packet) {
11-
this.packet = packet;
14+
private final Identifier soundId;
15+
private final float volume, pitch;
16+
17+
public RecieveSoundEvent(Identifier soundId, float volume, float pitch) {
18+
this.soundId = soundId;
19+
this.volume = volume;
20+
this.pitch = pitch;
21+
}
22+
23+
public Identifier getSoundId() {
24+
return soundId;
25+
}
26+
public float getVolume() {
27+
return volume;
1228
}
1329

14-
public PlaySoundS2CPacket getPacket() {
15-
return packet;
30+
public float getPitch() {
31+
return pitch;
1632
}
1733

1834
@Override

src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
import java.net.InetSocketAddress;
1616
import net.minecraft.client.network.ClientPlayNetworkHandler;
1717
import net.minecraft.network.ClientConnection;
18-
import net.minecraft.network.packet.s2c.play.DisconnectS2CPacket;
19-
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
20-
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
21-
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
22-
import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
18+
import net.minecraft.network.packet.s2c.play.*;
2319
import org.spongepowered.asm.mixin.Mixin;
2420
import org.spongepowered.asm.mixin.injection.At;
2521
import org.spongepowered.asm.mixin.injection.Inject;
@@ -94,7 +90,7 @@ private void onDisconnect(DisconnectS2CPacket packet, CallbackInfo ci) {
9490
EventManager.getInstance().dispatch(event);
9591
}
9692

97-
@Inject(method = "onPlaySound", at = @At("HEAD"), cancellable = true)
93+
/*@Inject(method = "onPlaySound", at = @At("HEAD"), cancellable = true)
9894
private void onPlaySound(PlaySoundS2CPacket packet, CallbackInfo ci) {
9995
RecieveSoundEvent event = new RecieveSoundEvent(packet);
10096
EventManager.getInstance().dispatch(event);
@@ -103,4 +99,24 @@ private void onPlaySound(PlaySoundS2CPacket packet, CallbackInfo ci) {
10399
ci.cancel();
104100
}
105101
}
102+
103+
@Inject(method = "onPlaySoundFromEntity", at = @At("HEAD"), cancellable = true)
104+
private void onPlaySoundFromEntity(PlaySoundFromEntityS2CPacket packet, CallbackInfo ci) {
105+
RecieveSoundEvent event = new RecieveSoundEvent(packet);
106+
EventManager.getInstance().dispatch(event);
107+
108+
if (event.isCancelled()) {
109+
ci.cancel();
110+
}
111+
}
112+
113+
@Inject(method = "onPlaySoundId", at = @At("HEAD"), cancellable = true)
114+
private void onPlaySoundId(PlaySoundIdS2CPacket packet, CallbackInfo ci) {
115+
RecieveSoundEvent event = new RecieveSoundEvent(packet);
116+
EventManager.getInstance().dispatch(event);
117+
118+
if (event.isCancelled()) {
119+
ci.cancel();
120+
}
121+
}*/
106122
}

src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import io.github.techstreet.dfscript.event.system.EventManager;
66
import net.minecraft.client.network.ClientPlayerEntity;
77
import net.minecraft.text.Text;
8+
import org.jetbrains.annotations.Nullable;
89
import org.spongepowered.asm.mixin.Mixin;
910
import org.spongepowered.asm.mixin.injection.At;
1011
import org.spongepowered.asm.mixin.injection.Inject;
1112
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1214

1315
@Mixin(ClientPlayerEntity.class)
1416
public class MLocalPlayer {
@@ -22,6 +24,24 @@ private void chat(String message, Text preview, CallbackInfo ci) {
2224
}
2325
}
2426

27+
@Inject(method = "sendCommand", at = @At("HEAD"), cancellable = true)
28+
private void command(String command, CallbackInfoReturnable<Boolean> ci) {
29+
SendChatEvent event = new SendChatEvent(command);
30+
EventManager.getInstance().dispatch(event);
31+
if (event.isCancelled()) {
32+
ci.cancel();
33+
}
34+
}
35+
36+
@Inject(method = "sendCommandInternal", at = @At("HEAD"), cancellable = true)
37+
private void commandInterval(String command, @Nullable Text preview, CallbackInfo ci) {
38+
SendChatEvent event = new SendChatEvent(command);
39+
EventManager.getInstance().dispatch(event);
40+
if (event.isCancelled()) {
41+
ci.cancel();
42+
}
43+
}
44+
2545
@Inject(method = "tick", at = @At("HEAD"))
2646
private void tick(CallbackInfo ci) {
2747
EventManager.getInstance().dispatch(new TickEvent());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.techstreet.dfscript.mixin.sound;
2+
3+
import io.github.techstreet.dfscript.event.RecieveSoundEvent;
4+
import io.github.techstreet.dfscript.event.system.EventManager;
5+
import io.github.techstreet.dfscript.util.chat.ChatUtil;
6+
import net.minecraft.client.sound.Sound;
7+
import net.minecraft.client.sound.SoundInstance;
8+
import net.minecraft.client.sound.SoundSystem;
9+
import net.minecraft.client.sound.WeightedSoundSet;
10+
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
11+
import net.minecraft.sound.SoundCategory;
12+
import net.minecraft.util.Identifier;
13+
import net.minecraft.util.math.MathHelper;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.gen.Invoker;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.Inject;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
21+
22+
@Mixin(SoundSystem.class)
23+
public abstract class MSoundSystem {
24+
25+
@Shadow
26+
public abstract float getAdjustedVolume(SoundInstance sound);
27+
@Shadow
28+
public abstract float getAdjustedPitch(SoundInstance sound);
29+
@Shadow
30+
public abstract float getSoundVolume(SoundCategory category);
31+
@Inject(method = "play", at = @At(value="INVOKE_ASSIGN", target="Lnet/minecraft/client/sound/SoundSystem;getAdjustedPitch(Lnet/minecraft/client/sound/SoundInstance;)F"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
32+
public void play(SoundInstance sound, CallbackInfo ci, WeightedSoundSet weightedSoundSet, Identifier identifier, Sound sound2, float f, float g, SoundCategory soundCategory, float h, float i) {
33+
RecieveSoundEvent event = new RecieveSoundEvent(sound.getId(), h, i);
34+
EventManager.getInstance().dispatch(event);
35+
36+
if (event.isCancelled()) {
37+
ci.cancel();
38+
}
39+
}
40+
}

src/main/java/io/github/techstreet/dfscript/screen/CScreen.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,15 @@ public double translateMouseY(double mouseY) {
114114
mouseY += height/2f;
115115
return mouseY;
116116
}
117+
118+
@Override
119+
public boolean shouldCloseOnEsc() {
120+
for(CWidget widget : widgets) {
121+
if(!widget.enableClosingOnEsc()) {
122+
return false;
123+
}
124+
}
125+
126+
return super.shouldCloseOnEsc();
127+
}
117128
}

src/main/java/io/github/techstreet/dfscript/screen/widget/CKeyField.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.techstreet.dfscript.DFScript;
44
import io.github.techstreet.dfscript.util.RenderUtil;
5+
import io.github.techstreet.dfscript.util.chat.ChatUtil;
56
import net.minecraft.client.font.TextRenderer;
67
import net.minecraft.client.gui.DrawableHelper;
78
import net.minecraft.client.util.InputUtil;
@@ -16,6 +17,8 @@ public class CKeyField implements CWidget {
1617

1718
boolean selected;
1819
boolean editable;
20+
21+
boolean blockEsc = false;
1922
public int textColor = 0xFFFFFFFF;
2023
InputUtil.Key key;
2124
Runnable changedListener;
@@ -38,7 +41,14 @@ public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
3841
stack.push();
3942
stack.translate(x, y, 0);
4043

41-
DrawableHelper.fill(stack, 0, 0, width, height, 0xFF888888);
44+
int outlineColor = 0xFF888888;
45+
46+
if(editable && selected)
47+
{
48+
outlineColor = 0xFFFFFF00;
49+
}
50+
51+
DrawableHelper.fill(stack, 0, 0, width, height, outlineColor);
4252
DrawableHelper.fill(stack, 1, 1, width - 1, height - 1, 0xFF000000);
4353

4454
Vector4f begin = new Vector4f(0, 0, 1, 1);
@@ -61,12 +71,16 @@ public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
6171

6272
stack.push();
6373

64-
String line = null;
74+
String line;
6575
int color = textColor;
6676

6777
if(key != null) {
6878
line = key.getLocalizedText().getString();
6979
}
80+
else
81+
{
82+
line = "None";
83+
}
7084

7185
if(editable && selected) {
7286
color = 0xFFFF00;
@@ -89,23 +103,26 @@ public boolean mouseClicked(double x, double y, int button) {
89103
if (button == 0) {
90104
if (x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height) {
91105
this.selected = true;
106+
blockEsc = true;
92107
}
93108
else {
94109
this.selected = false;
110+
blockEsc = false;
95111
}
96112
}
97113
}
98114
else {
99115
this.selected = false;
116+
blockEsc = false;
100117
}
101118
return false;
102119
}
103120

104121
@Override
105-
public void keyPressed(int keyCode, int scanCode, int modifiers) { // wth github is having a seizure and is forcing me to make this comment what
122+
public void keyPressed(int keyCode, int scanCode, int modifiers) {
106123
if(editable && selected) {
107124
if(keyCode != -1) {
108-
if(keyCode == 10) {
125+
if(keyCode == 256) {
109126
key = null;
110127
}
111128
else
@@ -117,6 +134,10 @@ public void keyPressed(int keyCode, int scanCode, int modifiers) { // wth github
117134
}
118135

119136
selected = false;
137+
blockEsc = true;
138+
}
139+
else {
140+
blockEsc = false;
120141
}
121142
}
122143

@@ -136,5 +157,9 @@ public InputUtil.Key getKey() {
136157
public void setKey(InputUtil.Key k) {
137158
key = k;
138159
}
139-
}
140160

161+
@Override
162+
public boolean enableClosingOnEsc() {
163+
return !blockEsc;
164+
}
165+
}

src/main/java/io/github/techstreet/dfscript/screen/widget/CPlainPanel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ public CWidget[] getChildren() {
110110
return children.toArray(new CWidget[0]);
111111
}
112112

113+
@Override
114+
public boolean enableClosingOnEsc() {
115+
for(CWidget widget : children) {
116+
if(!widget.enableClosingOnEsc())
117+
{
118+
return false;
119+
}
120+
}
121+
122+
return CWidget.super.enableClosingOnEsc();
123+
}
113124
}

src/main/java/io/github/techstreet/dfscript/screen/widget/CScrollPanel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,16 @@ public void setScroll(int s) {
157157
public void remove(CWidget w) {
158158
children.remove(w);
159159
}
160+
161+
@Override
162+
public boolean enableClosingOnEsc() {
163+
for(CWidget widget : children) {
164+
if(!widget.enableClosingOnEsc())
165+
{
166+
return false;
167+
}
168+
}
169+
170+
return CWidget.super.enableClosingOnEsc();
171+
}
160172
}

src/main/java/io/github/techstreet/dfscript/screen/widget/CTexturedButton.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class CTexturedButton extends CButton {
88

9-
private final String texture;
9+
private String texture;
1010
private final float ux;
1111
private final float uy;
1212
private final float uw;
@@ -25,6 +25,10 @@ public CTexturedButton(int x, int y, int width, int height, String texture, Runn
2525
this.hoverUy = hoverUy;
2626
}
2727

28+
public void setTexture(String newTexture) {
29+
texture = newTexture;
30+
}
31+
2832
@Override
2933
public void render(MatrixStack stack, int mouseX, int mouseY, float tickDelta) {
3034
stack.push();

src/main/java/io/github/techstreet/dfscript/screen/widget/CWidget.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ default void renderOverlay(MatrixStack stack, int mouseX, int mouseY, float tick
2525
}
2626

2727
Rectangle getBounds();
28+
29+
default boolean enableClosingOnEsc(){
30+
return true;
31+
}
2832
}

0 commit comments

Comments
 (0)