diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/example/CheeseEvent.java | 14 | ||||
-rw-r--r-- | src/main/java/com/example/CrashCommand.java | 27 | ||||
-rw-r--r-- | src/main/java/com/example/ExampleMod.java | 27 | ||||
-rw-r--r-- | src/main/java/com/example/MyGuiScreen.java | 82 | ||||
-rw-r--r-- | src/main/resources/assets/examplemod/textures/gui/background.png | bin | 0 -> 467 bytes |
5 files changed, 147 insertions, 3 deletions
diff --git a/src/main/java/com/example/CheeseEvent.java b/src/main/java/com/example/CheeseEvent.java new file mode 100644 index 0000000..4b8ddbe --- /dev/null +++ b/src/main/java/com/example/CheeseEvent.java @@ -0,0 +1,14 @@ +package com.example; + +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +// If you don't want your event to be cancellable, remove this annotation +@Cancelable +public class CheeseEvent extends Event { + public final int totalCheeseCount; + + public CheeseEvent(int totalCheeseCount) { + this.totalCheeseCount = totalCheeseCount; + } +} diff --git a/src/main/java/com/example/CrashCommand.java b/src/main/java/com/example/CrashCommand.java new file mode 100644 index 0000000..516708d --- /dev/null +++ b/src/main/java/com/example/CrashCommand.java @@ -0,0 +1,27 @@ +package com.example; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; + +public class CrashCommand extends CommandBase { + @Override + public String getCommandName() { + return "crashme"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return ""; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + ExampleMod.screenToOpenNextTick = new MyGuiScreen(); + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/src/main/java/com/example/ExampleMod.java b/src/main/java/com/example/ExampleMod.java index c18b591..166c371 100644 --- a/src/main/java/com/example/ExampleMod.java +++ b/src/main/java/com/example/ExampleMod.java @@ -1,13 +1,34 @@ package com.example; -import net.minecraft.init.Blocks; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; -@Mod(modid = "examplemod", useMetadata=true) +@Mod(modid = "examplemod", useMetadata = true) public class ExampleMod { @Mod.EventHandler public void init(FMLInitializationEvent event) { - System.out.println("Dirt: " + Blocks.dirt.getUnlocalizedName()); + MinecraftForge.EVENT_BUS.register(this); + ClientCommandHandler.instance.registerCommand(new CrashCommand()); + } + + public static GuiScreen screenToOpenNextTick = null; + + public static final int MOUSE_LEFT = 0; + public static final int MOUSE_RIGHT = 1; + public static final int MOUSE_MIDDLE = 2; + public static final int MOUSE_BACKWARD = 3; + public static final int MOUSE_FORWARD = 4; + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (screenToOpenNextTick != null) { + Minecraft.getMinecraft().displayGuiScreen(screenToOpenNextTick); + screenToOpenNextTick = null; + } } } diff --git a/src/main/java/com/example/MyGuiScreen.java b/src/main/java/com/example/MyGuiScreen.java new file mode 100644 index 0000000..331e21d --- /dev/null +++ b/src/main/java/com/example/MyGuiScreen.java @@ -0,0 +1,82 @@ +package com.example; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.io.IOException; + +public class MyGuiScreen extends GuiScreen { + + int lastClickedButton = 0; + + @Override + public void initGui() { + super.initGui(); + this.buttonList.add(new GuiButton(0, width / 2 - 55, height / 2 - 10, 30, 20, "§cRED")); + this.buttonList.add(new GuiButton(1, width / 2 - 15, height / 2 - 10, 30, 20, "§9BLUE")); + this.buttonList.add(new GuiButton(2, width / 2 + 25, height / 2 - 10, 30, 20, "§2GREEN")); + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + lastClickedButton = button.id; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + // Draw tinted background + drawDefaultBackground(); + + Minecraft minecraft = Minecraft.getMinecraft(); + + // First we need to bind the texture + minecraft.getTextureManager().bindTexture(new ResourceLocation("examplemod"/* or your modid */, "textures/gui/background.png")); + + // Render from your texture. + drawModalRectWithCustomSizedTexture( + // The first two arguments are the position on the screen + width / 2 - 100, height / 2 - 20, + // The next arguments are the starting u and v + 0, 0, + // The next arguments are the size on the screen + 200, 40, + // The last two arguments are the size of the texture + 200, 40 + ); + + FontRenderer fr = minecraft.fontRendererObj; + String text = "Hello, World!"; + int textWidth = fr.getStringWidth(text); + + // Draw a string left aligned + fr.drawString(text, width / 2 - 95, height / 2 - 15, 0xFF000000); + + // Draw a string center aligned + GlStateManager.pushMatrix(); + GlStateManager.translate(width / 2, height / 2 - 5 + fr.FONT_HEIGHT / 2, 0); + GlStateManager.rotate((float) ((System.currentTimeMillis() / 200.0) % (360)), 0, 0, 1); + fr.drawString(text, -textWidth / 2, -fr.FONT_HEIGHT / 2, 0xFF000000); + GlStateManager.popMatrix(); + + // Draw a string right aligned + fr.drawString(text, width / 2 + 95 - textWidth, height / 2 + 5, 0xFF000000); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + } + + int lastMouseButton = -1; + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + lastMouseButton = mouseButton; + } +} diff --git a/src/main/resources/assets/examplemod/textures/gui/background.png b/src/main/resources/assets/examplemod/textures/gui/background.png Binary files differnew file mode 100644 index 0000000..ca51491 --- /dev/null +++ b/src/main/resources/assets/examplemod/textures/gui/background.png |