Skip to content

Commit

Permalink
Merge pull request #43 from XTerPL/1.20.2
Browse files Browse the repository at this point in the history
Boolean Values + 1.20.2
  • Loading branch information
TechStreetDev authored Dec 31, 2023
2 parents ecd0786 + c78045f commit 8f9aa3b
Show file tree
Hide file tree
Showing 83 changed files with 1,170 additions and 270 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20
yarn_mappings=1.20.1+build.1
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.15.3
# Mod Properties
mod_version=1.0-SNAPSHOT
maven_group=io.github.techstreet.dfscript
archives_base_name=DFScript
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.83.0+1.20.1
fabric_version=0.91.2+1.20.2
2 changes: 1 addition & 1 deletion src/main/java/io/github/techstreet/dfscript/DFScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void onInitialize() {
// allows FileDialog class to open without a HeadlessException
System.setProperty("java.awt.headless", "false");

PLAYER_UUID = MC.getSession().getUuid();
PLAYER_UUID = MC.getSession().getUuidOrNull().toString();
PLAYER_NAME = MC.getSession().getUsername();

MOD_VERSION = FabricLoader.getInstance().getModContainer(MOD_ID).get().getMetadata().getVersion().getFriendlyString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.techstreet.dfscript.event;

import io.github.techstreet.dfscript.event.system.Event;
import net.minecraft.network.packet.s2c.play.DisconnectS2CPacket;
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket;

public class ServerLeaveEvent implements Event {
private final DisconnectS2CPacket packet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.techstreet.dfscript.loader.Loadable;
import io.github.techstreet.dfscript.script.util.AuthcodeResponse;
import io.github.techstreet.dfscript.script.util.ServercodeResponse;
import net.minecraft.client.util.Session;
import net.minecraft.client.session.Session;
import org.apache.commons.codec.digest.DigestUtils;

import java.io.BufferedReader;
Expand Down Expand Up @@ -78,7 +78,7 @@ public static void regen() {
// Authorization step two - Fake server connect
try {
Session session = DFScript.MC.getSession();
DFScript.MC.getSessionService().joinServer(session.getProfile(), session.getAccessToken(), commonSecret);
DFScript.MC.getSessionService().joinServer(session.getUuidOrNull(), session.getAccessToken(), commonSecret);
} catch (AuthenticationException e) {
// DFScript.LOGGER.error(e.getMessage());
// e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.techstreet.dfscript.mixin.game;

import com.mojang.blaze3d.systems.RenderSystem;
import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.event.*;
import io.github.techstreet.dfscript.event.system.EventManager;
import io.github.techstreet.dfscript.util.hypercube.HypercubeRank;
import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientCommonNetworkHandler.class)
public class MClientCommonNetworkHandler {
@Inject(method = "onDisconnect", at = @At("RETURN"), cancellable = true)
private void onDisconnect(DisconnectS2CPacket packet, CallbackInfo ci) {
ServerLeaveEvent event = new ServerLeaveEvent(packet);
EventManager.getInstance().dispatch(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.network.packet.s2c.common.*;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -80,11 +81,11 @@ private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
// EventManager.getInstance().dispatch(event);
}

@Inject(method = "onDisconnect", at = @At("RETURN"), cancellable = true)
/* @Inject(method = "onDisconnect", at = @At("RETURN"), cancellable = true)
private void onDisconnect(DisconnectS2CPacket packet, CallbackInfo ci) {
ServerLeaveEvent event = new ServerLeaveEvent(packet);
EventManager.getInstance().dispatch(event);
}
}*/

@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void chat(String content, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@

@Mixin(InGameHud.class)
public class MInGameHUD {

@Inject(at = @At("HEAD"), method = "renderScoreboardSidebar", cancellable = true)
private void renderScoreboardSidebar(CallbackInfo info) {
MinecraftClient client = DFScript.MC;
if (client.options.debugEnabled) {
info.cancel();
}
}

@Inject(at = @At("HEAD"), method = "render")
private void render(DrawContext context, float tickDelta, CallbackInfo ci) {
OverlayManager.getInstance().render(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MultiplayerScreen.class)
public class MMultiplayerScreen extends Screen {
@Unique
private final Identifier identifier_main = new Identifier(DFScript.MOD_ID + ":scripts.png");
@Unique
private final Identifier identifier_main_highlight = new Identifier(DFScript.MOD_ID + ":scripts_highlight.png");

protected MMultiplayerScreen(Text title) {
super(title);
}

@Inject(at = @At("HEAD"), method = "init", cancellable = true)
private void init(CallbackInfo ci) {
this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, 0, 0, 20, identifier_main, 20, 40, (button) -> {
this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, identifier_main, identifier_main_highlight, (button) -> {
ScriptListScreen screen = new ScriptListScreen(false);
DFScript.MC.setScreen(screen);
}));
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ protected CScreen(int width, int height) {

@Override
public void render(@NotNull DrawContext context, int mouseX, int mouseY, float tickDelta) {
renderBackground(context);
//renderBackground(context, mouseX, mouseY, tickDelta);
super.render(context, mouseX, mouseY, tickDelta);
context.getMatrices().push();
MinecraftClient mc = DFScript.MC;

MatrixStack stack = context.getMatrices();

assert mc.currentScreen != null;
stack.translate(mc.currentScreen.width/2f, mc.currentScreen.height/2f, 0);

// float scaleFactor = (float) mc.getWindow().getScaleFactor();
Expand All @@ -58,7 +60,6 @@ public void render(@NotNull DrawContext context, int mouseX, int mouseY, float t
cWidget.renderOverlay(context, mouseX, mouseY, tickDelta);
}
stack.pop();
super.render(context, mouseX, mouseY, tickDelta);
}

@Override
Expand Down Expand Up @@ -100,20 +101,21 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) {
mouseX = translateMouseX(mouseX);
mouseY = translateMouseY(mouseY);

for (CWidget cWidget : widgets) {
cWidget.mouseScrolled(mouseX, mouseY, amount);
cWidget.mouseScrolled(mouseX, mouseY, vertical, horizontal);
}
return super.mouseScrolled(mouseX, mouseY, amount);
return super.mouseScrolled(mouseX, mouseY, horizontal, vertical);
}

public double translateMouseX(double mouseX) {
MinecraftClient mc = DFScript.MC;
// float s = (float) mc.getWindow().getScaleFactor();
float scaleFactor = 2;
assert mc.currentScreen != null;
mouseX += -mc.currentScreen.width/2f;
mouseX /= scaleFactor;
mouseX += width/2f;
Expand All @@ -124,6 +126,7 @@ public double translateMouseY(double mouseY) {
MinecraftClient mc = DFScript.MC;
// float scaleFactor = (float) mc.getWindow().getScaleFactor();
float scaleFactor = 2;
assert mc.currentScreen != null;
mouseY += -mc.currentScreen.height/2f;
mouseY /= scaleFactor;
mouseY += height/2f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,22 @@ public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int
functionArgumentIcon.setCustomName(Text.literal("Function Argument")
.fillStyle(Style.EMPTY.withItalic(false)));

ItemStack trueIcon = new ItemStack(Items.LIME_DYE);
trueIcon.setCustomName(Text.literal("True")
.fillStyle(Style.EMPTY.withItalic(false)));

ItemStack falseIcon = new ItemStack(Items.RED_DYE);
falseIcon.setCustomName(Text.literal("False")
.fillStyle(Style.EMPTY.withItalic(false)));

CItem addNumber = new CItem(2, 40, numberIcon);
CItem addText = new CItem(12, 40, textIcon);
CItem addVariable = new CItem(22, 40, variableIcon);
CItem addClientValue = new CItem(32, 40, clientValueIcon);
CItem addConfigValue = new CItem(42, 40, configValueIcon);
CItem addFunctionArgument = new CItem(52, 40, functionArgumentIcon);
CItem addTrue = new CItem(22, 40, trueIcon);
CItem addFalse = new CItem(32, 40, falseIcon);
CItem addVariable = new CItem(42, 40, variableIcon);
CItem addClientValue = new CItem(52, 40, clientValueIcon);
CItem addConfigValue = new CItem(62, 40, configValueIcon);
CItem addFunctionArgument = new CItem(72, 40, functionArgumentIcon);

input.setChangedListener(() -> input.textColor = 0xFFFFFF);

Expand Down Expand Up @@ -102,9 +111,23 @@ public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int
DFScript.MC.setScreen(new ScriptAddFunctionArgValueScreen(action, script, index, header, overwrite));
});

addTrue.setClickListener((btn) -> {
if(overwrite != null) action.getArguments().remove(index);
action.getArguments().add(index, new ScriptBoolArgument(true));
close();
});

addFalse.setClickListener((btn) -> {
if(overwrite != null) action.getArguments().remove(index);
action.getArguments().add(index, new ScriptBoolArgument(false));
close();
});

widgets.add(input);
widgets.add(addNumber);
widgets.add(addText);
widgets.add(addTrue);
widgets.add(addFalse);
widgets.add(addVariable);
widgets.add(addClientValue);
widgets.add(addConfigValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public ScriptAddPartScreen(Script script, ScriptSnippet snippet, int insertIndex
for(ScriptActionCategoryExtra extra : category.getExtras(script)) {
CItem item = new CItem(x, y, extra.getIcon());
item.setClickListener((btn) -> {
snippet.add(insertIndex, extra.getPart());
DFScript.MC.setScreen(new ScriptEditScreen(script));
extra.click(script, snippet, insertIndex);
});
widgets.add(item);
x += 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public ScriptAddSettingScreen(Script script, int pos) {
int y = 3;

for(ScriptOptionEnum option : ScriptOptionEnum.values()) {
if(option.isDeprecated()) continue;

CItem citem = new CItem(x, y, option.getIcon());

if(option.getExtraTypes() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta)
}

if(noNull) {
CTexturedButton button = new CTexturedButton(width - 10, 3, 8, 8, DFScript.MOD_ID + ":on_button.png", () -> {
CTexturedButton button = new CTexturedButton(width - 10, 3, 8, 8, DFScript.MOD_ID + ":on_button.png", DFScript.MOD_ID + ":on_button_highlight.png", () -> {
try {
script.addOption(pos, new ScriptNamedOption(ScriptOption.instantiate(option, subtypes), script.getUnnamedOption()));
} catch (Exception e) {
ChatUtil.error(String.valueOf(e.getCause()));
}

DFScript.MC.setScreen(new ScriptSettingsScreen(script, true));
}, 0,0,1,0.5f,0,0.5f);
});

widgets.add(button);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.techstreet.dfscript.screen.script;

import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.screen.CScreen;
import io.github.techstreet.dfscript.screen.widget.CItem;
import io.github.techstreet.dfscript.script.Script;
import io.github.techstreet.dfscript.script.ScriptPart;
import io.github.techstreet.dfscript.script.ScriptSnippet;
import io.github.techstreet.dfscript.script.action.ScriptActionCategory;
import io.github.techstreet.dfscript.script.conditions.ScriptBuiltinCondition;
import io.github.techstreet.dfscript.script.conditions.ScriptCondition;
import io.github.techstreet.dfscript.script.conditions.ScriptConditionType;

import java.util.function.Consumer;
import java.util.function.Function;

public class ScriptConditionCategoryScreen extends CScreen {

private static final int size;

static {
size = (int) (Math.ceil(Math.sqrt(ScriptActionCategory.values().length)) * 10)+4;
}

private final Script script;

private final ScriptSnippet snippet;

private final int insertIndex;

private final Function<ScriptCondition, ScriptPart> partCreator;

public ScriptConditionCategoryScreen(Script script, ScriptSnippet snippet, int insertIndex, Function<ScriptCondition, ScriptPart> partCreator) {
super(size, size);
this.script = script;
this.snippet = snippet;
this.insertIndex = insertIndex;
this.partCreator = partCreator;

int x = 3;
int y = 3;

for (ScriptActionCategory category : ScriptActionCategory.values()) {
CItem actionItem = new CItem(x, y, category.getIcon());
widgets.add(actionItem);

actionItem.setClickListener(btn -> DFScript.MC.setScreen(new ScriptConditionSelectScreen(script, snippet, insertIndex, partCreator, category)));

x += 10;
if (x >= size - 10) {
x = 3;
y += 10;
}
}
}

@Override
public void close() {
DFScript.MC.setScreen(new ScriptAddPartScreen(script, snippet, insertIndex, ScriptActionCategory.CONDITIONS));
}
}
Loading

0 comments on commit 8f9aa3b

Please sign in to comment.