Skip to content

Commit

Permalink
⬆️ migrate to 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Krxwallo committed Jun 24, 2022
1 parent a55dfcb commit d776082
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
20 changes: 15 additions & 5 deletions build.gradle
Expand Up @@ -12,15 +12,15 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'idea'
apply plugin: 'maven-publish'

version = '1.2.4'
version = '1.2.5'
group = 'com.justAm0dd3r.cheat_mode'
archivesBaseName = 'cheat_mode-1.17.X'
archivesBaseName = 'cheat_mode-1.18.X'

java.toolchain.languageVersion = JavaLanguageVersion.of(16)
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
mappings channel: 'official', version: '1.17.1'
mappings channel: 'official', version: '1.18.2'
runs {
client {
workingDirectory project.file('run')
Expand Down Expand Up @@ -91,13 +91,23 @@ repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.17.1-37.0.126'
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
}

jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')


jar {
manifest {
attributes([
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion
])
}
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/com/justAm0dd3r/cheatmode/events/Events.java
@@ -1,7 +1,7 @@
package com.justAm0dd3r.cheatmode.events;

import com.justAm0dd3r.cheatmode.config.Config;
import com.justAm0dd3r.cheatmode.gui.button.CommandButton;
import com.justAm0dd3r.cheatmode.gui.button.DayButton;
import com.justAm0dd3r.cheatmode.gui.button.ItemButton;
import com.justAm0dd3r.cheatmode.gui.button.ToggleButton;
import com.justAm0dd3r.cheatmode.gui.screen.CheatModeScreen;
Expand All @@ -15,8 +15,8 @@
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.client.event.ScreenOpenEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

Expand All @@ -42,11 +42,11 @@ private ServerPlayer getServerPlayer() {
}

@SubscribeEvent
public void onScreenInit(GuiScreenEvent.InitGuiEvent.Post event) {
public void onScreenInit(ScreenEvent.InitScreenEvent.Post event) {
ServerPlayer player = getServerPlayer();
if (player == null | minecraft.player == null) return;

if (event.getGui() instanceof InventoryScreen) {
if (event.getScreen() instanceof InventoryScreen) {
assert Minecraft.getInstance().gameMode != null;
if (player.gameMode.getGameModeForPlayer() != GameType.CREATIVE) {

Expand All @@ -66,15 +66,15 @@ public void onScreenInit(GuiScreenEvent.InitGuiEvent.Post event) {
else {
// Add a button

int guiCenterX = ((InventoryScreen) event.getGui()).getGuiLeft();
int guiCenterY = ((InventoryScreen) event.getGui()).getGuiTop();
int guiCenterX = ((InventoryScreen) event.getScreen()).getGuiLeft();
int guiCenterY = ((InventoryScreen) event.getScreen()).getGuiTop();

event.addWidget(this.button = new ItemButton(guiCenterX + 77, guiCenterY + 30,
event.addListener(this.button = new ItemButton(guiCenterX + 77, guiCenterY + 30,
button -> minecraft.pushGuiLayer(new CheatModeScreen(minecraft.player, player, true))));
}
}
}
else if (event.getGui() instanceof CreativeModeInventoryScreen gui){
else if (event.getScreen() instanceof CreativeModeInventoryScreen gui){
// Creative Inventory
// Add other buttons such as enable fly

Expand All @@ -86,14 +86,13 @@ else if (event.getGui() instanceof CreativeModeInventoryScreen gui){
if (minecraft.player == null) return;
updateSpeed(minecraft.player);
}));*/
event.addWidget(new ToggleButton(gui.width / 2 - 200, gui.height / 6 + 48 - 6 /*- 24*/, 98, 20,
event.addListener(new ToggleButton(gui.width / 2 - 200, gui.height / 6 + 48 - 6 /*- 24*/, 98, 20,
"InstantOpen", Config.COMMON.instantCreativeInventory.get(),
button -> {
Config.COMMON.instantCreativeInventory.set(((ToggleButton) button).getState());
Config.COMMON.instantCreativeInventory.save();
}));
event.addWidget(new CommandButton(gui.width / 2 - 200, gui.height / 6 + 48 - 6 + 24, 98, 20,
"Set Day", "/time set day"));
event.addListener(new DayButton(gui.width / 2 - 200, gui.height / 6 + 48 - 6 + 24, 98, 20, "Set Day"));
}
}

Expand Down Expand Up @@ -146,10 +145,10 @@ public void fovUpdate(FOVUpdateEvent evt) {
}*/

@SubscribeEvent
public void onScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) {
if (event.getGui() instanceof InventoryScreen && button != null) {
public void onScreenDrawPost(ScreenEvent.DrawScreenEvent.Post event) {
if (event.getScreen() instanceof InventoryScreen && button != null) {
if(button.isMouseOver(event.getMouseX(), event.getMouseY())) {
screenRenderToolTip(((InventoryScreen) event.getGui()), new TranslatableComponent("gui.cheat_mode.open_creative_inventory"),
screenRenderToolTip(((InventoryScreen) event.getScreen()), new TranslatableComponent("gui.cheat_mode.open_creative_inventory"),
event.getMouseX(), event.getMouseY());
}
}
Expand All @@ -160,8 +159,8 @@ private void screenRenderToolTip(InventoryScreen screen, TranslatableComponent n
}

@SubscribeEvent
public void onOpenGui(GuiOpenEvent event) {
if (screenOpen && event.getGui() == null) {
public void onOpenGui(ScreenOpenEvent event) {
if (screenOpen && event.getScreen() == null) {
screenOpen = false;
firstTime = true;
ServerPlayer player = getServerPlayer();
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/justAm0dd3r/cheatmode/gui/button/DayButton.java
@@ -0,0 +1,23 @@
package com.justAm0dd3r.cheatmode.gui.button;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.network.chat.TextComponent;

public class DayButton extends Button {
private final Minecraft minecraft = Minecraft.getInstance();

public DayButton(int x, int y, int width, int height, String message) {
super(x, y, width, height, new TextComponent(message), b -> {});
}

@Override
public void onPress() {
if (minecraft.player == null) return;
if (!minecraft.hasSingleplayerServer()) return;
IntegratedServer server = minecraft.getSingleplayerServer();
if (server == null) return;
server.overworld().setDayTime(1000);
}
}
Expand Up @@ -8,8 +8,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;

import javax.annotation.Nonnull;

/**
* Author: justAm0dd3r
*/
Expand All @@ -23,7 +21,7 @@ public ItemButton(int xIn, int yIn, OnPress action) {
}

@Override
public void renderButton(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
public void renderButton(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
renderButton();
super.renderButton(matrixStack, mouseX, mouseY, partialTicks);
}
Expand Down
Expand Up @@ -4,8 +4,6 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.TextComponent;

import javax.annotation.CheckReturnValue;

public class ToggleButton extends Button {
private boolean state;
private final String mainTitle;
Expand All @@ -19,7 +17,6 @@ private static String getText(String mainTitle, boolean state) {
return mainTitle + (state ? ": ON" : ": OFF");
}

@CheckReturnValue
public boolean getState() {
return state;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Expand Up @@ -18,13 +18,13 @@ Allows players to test things out in survival.
[[dependencies.cheat_mode]]
modId="forge"
mandatory=true
versionRange="[37,)"
versionRange="[40,)"
ordering="NONE"
side="BOTH"

[[dependencies.cheat_mode]]
modId="minecraft"
mandatory=true
versionRange="[1.17, 1.18)"
versionRange="[1.18, 1.19)"
ordering="NONE"
side="BOTH"

0 comments on commit d776082

Please sign in to comment.