Skip to content

Commit f34a673

Browse files
committed
Add PSD screen functionality (baseline)
1 parent f300af1 commit f34a673

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.robotgryphon.compactmachines.client.gui;
2+
3+
import com.mojang.blaze3d.matrix.MatrixStack;
4+
import com.mojang.blaze3d.systems.RenderSystem;
5+
import com.robotgryphon.compactmachines.CompactMachines;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.gui.screen.Screen;
8+
import net.minecraft.util.ResourceLocation;
9+
import net.minecraft.util.text.TranslationTextComponent;
10+
11+
public class PersonalShrinkingDeviceScreen extends Screen {
12+
private final ResourceLocation GUI = new ResourceLocation(CompactMachines.MOD_ID, "textures/gui/psd_screen.png");
13+
private static final int WIDTH = 256;
14+
private static final int HEIGHT = 201;
15+
16+
protected PersonalShrinkingDeviceScreen() {
17+
super(new TranslationTextComponent(CompactMachines.MOD_ID + ".gui.psd.title"));
18+
}
19+
20+
@Override
21+
public boolean mouseClicked(double mouseX, double mouseY, int button) {
22+
return false;
23+
}
24+
25+
@Override
26+
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
27+
this.renderBackground(matrixStack);
28+
29+
RenderSystem.color4f(1, 1, 1, 1);
30+
int relX = (this.width - WIDTH) / 2;
31+
int relY = (this.height - HEIGHT) / 2;
32+
33+
matrixStack.push();
34+
matrixStack.translate(relX, relY, 0);
35+
36+
this.minecraft.getTextureManager().bindTexture(GUI);
37+
this.blit(matrixStack, 0, 0, 0, 0, WIDTH, HEIGHT);
38+
39+
matrixStack.pop();
40+
super.render(matrixStack, mouseX, mouseY, partialTicks);
41+
}
42+
43+
@Override
44+
public boolean isPauseScreen() {
45+
return false;
46+
}
47+
48+
public static void show() {
49+
Minecraft.getInstance().displayGuiScreen(new PersonalShrinkingDeviceScreen());
50+
}
51+
}

src/main/java/com/robotgryphon/compactmachines/item/ItemPersonalShrinkingDevice.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package com.robotgryphon.compactmachines.item;
22

33
import com.robotgryphon.compactmachines.CompactMachines;
4+
import com.robotgryphon.compactmachines.client.gui.PersonalShrinkingDeviceScreen;
45
import com.robotgryphon.compactmachines.core.Registration;
56
import com.robotgryphon.compactmachines.util.CompactMachineUtil;
67
import com.robotgryphon.compactmachines.util.PlayerUtil;
8+
import net.minecraft.client.entity.player.ClientPlayerEntity;
79
import net.minecraft.client.gui.screen.Screen;
810
import net.minecraft.client.util.ITooltipFlag;
911
import net.minecraft.entity.player.PlayerEntity;
1012
import net.minecraft.entity.player.ServerPlayerEntity;
1113
import net.minecraft.item.Item;
1214
import net.minecraft.item.ItemStack;
15+
import net.minecraft.item.ItemUseContext;
1316
import net.minecraft.util.ActionResult;
17+
import net.minecraft.util.ActionResultType;
1418
import net.minecraft.util.Hand;
1519
import net.minecraft.util.text.IFormattableTextComponent;
1620
import net.minecraft.util.text.ITextComponent;
1721
import net.minecraft.util.text.TextFormatting;
1822
import net.minecraft.util.text.TranslationTextComponent;
1923
import net.minecraft.world.World;
2024
import net.minecraft.world.server.ServerWorld;
25+
import net.minecraftforge.fml.client.gui.GuiUtils;
26+
import net.minecraftforge.fml.network.NetworkHooks;
2127

2228
import javax.annotation.Nullable;
2329
import java.util.List;
@@ -58,12 +64,13 @@ public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player
5864
return ActionResult.resultFail(stack);
5965
}
6066

61-
// TODO: Machine enter/exit dimension
62-
// if(world.provider.getDimension() != ConfigurationHandler.Settings.dimensionId) {
63-
// // player.openGui(compactmachines.instance, GuiIds.PSD_GUIDE.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
64-
// return new ActionResult(ActionResultType.SUCCESS, stack);
65-
// }
66-
//
67+
// If we aren't in the compact dimension, allow PSD guide usage
68+
// Prevents misfiring if a player is trying to leave a machine or set their spawn
69+
if(world.isRemote && world.getDimensionKey() != Registration.COMPACT_DIMENSION) {
70+
PersonalShrinkingDeviceScreen.show();
71+
return ActionResult.resultSuccess(stack);
72+
}
73+
6774
if (world instanceof ServerWorld && player instanceof ServerPlayerEntity) {
6875
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
6976

src/main/java/com/robotgryphon/compactmachines/reference/Resources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public class Resources {
77
public static final class Gui {
88
protected static final String path = "textures/gui/";
99

10-
public static final ResourceLocation PSD_SCREEN = new ResourceLocation(CompactMachines.MOD_ID, path + "psdscreen.png");
10+
public static final ResourceLocation PSD_SCREEN = new ResourceLocation(CompactMachines.MOD_ID, path + "psd_screen.png");
1111
}
1212
}

src/main/resources/assets/compactmachines/textures/gui/psdscreen.png renamed to src/main/resources/assets/compactmachines/textures/gui/psd_screen.png

File renamed without changes.

0 commit comments

Comments
 (0)