Added a GUI via an item you can get it via /seed gui

This commit is contained in:
Neil
2020-02-18 02:33:03 +01:00
parent 3baab7fe78
commit da35bda7b9
13 changed files with 147 additions and 34 deletions
+10 -3
View File
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.5-SNAPSHOT'
id 'fabric-loom' version '0.2.6-SNAPSHOT'
id 'maven-publish'
}
@@ -12,13 +12,20 @@ group = project.maven_group
minecraft {
}
repositories {
maven {
name = "CottonMC"
url = "http://server.bbkr.space:8081/artifactory/libs-release"
}
}
dependencies {
modImplementation "io.github.cottonmc:LibGui:1.6.0"
}
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
// modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
+1
View File
@@ -15,3 +15,4 @@ org.gradle.jvmargs=-Xmx1G
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.4.29+build.290-1.15
modmenu_version=1.10.1+build.30
@@ -2,18 +2,25 @@ package kaptainwutax.seedcracker;
import kaptainwutax.seedcracker.cracker.storage.DataStorage;
import kaptainwutax.seedcracker.finder.FinderQueue;
import kaptainwutax.seedcracker.gui.GuiItem;
import kaptainwutax.seedcracker.render.RenderQueue;
import net.fabricmc.api.ModInitializer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;
public class SeedCracker implements ModInitializer {
private static final SeedCracker INSTANCE = new SeedCracker();
private DataStorage dataStorage = new DataStorage();
public static Item GUI_ITEM=new GuiItem(new Item.Settings().group(ItemGroup.MISC).rarity(Rarity.EPIC));
@Override
public void onInitialize() {
RenderQueue.get().add("hand", FinderQueue.get()::renderFinders);
Registry.register(Registry.ITEM,new Identifier("seedcracker","gui_item"),GUI_ITEM);
/*
long ss = 5718603440394L;
LCG lcg = Rand.JAVA_LCG.combine(-5);
@@ -0,0 +1,42 @@
package kaptainwutax.seedcracker.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import kaptainwutax.seedcracker.finder.Finder;
import kaptainwutax.seedcracker.finder.FinderQueue;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import static kaptainwutax.seedcracker.SeedCracker.GUI_ITEM;
import static net.minecraft.server.command.CommandManager.literal;
public class GuiCommand extends ClientCommand {
@Override
public String getName() {
return "gui";
}
@Override
public void build(LiteralArgumentBuilder<ServerCommandSource> builder) {
builder.executes(ctx->
{
ServerCommandSource source = ctx.getSource();
ClientPlayerEntity self =(ClientPlayerEntity) source.getEntity();
assert self != null;
if(!self.inventory.insertStack(new ItemStack(GUI_ITEM))){
throw new SimpleCommandExceptionType(new TranslatableText("inventory.isfull")).create();
}
return 1;
});
}
}
@@ -0,0 +1,37 @@
package kaptainwutax.seedcracker.gui;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
import io.github.cottonmc.cotton.gui.widget.WButton;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WSprite;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
public class Gui extends LightweightGuiDescription {
public Gui() {
WGridPanel root = new WGridPanel();
setRootPanel(root);
root.setSize(256, 240);
WSprite icon = new WSprite(new Identifier("minecraft:textures/item/redstone.png"));
root.add(icon, 0, 2, 1, 1);
WButton button = new WButton(new TranslatableText("gui.examplemod.examplebutton"));
root.add(button, 0, 3, 4, 1);
WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
root.add(label, 0, 4, 2, 1);
root.validate(this);
}
@Override
public void addPainters() {
getRootPanel().setBackgroundPainter(BackgroundPainter.VANILLA); //This is done automatically though
}
}
@@ -0,0 +1,22 @@
package kaptainwutax.seedcracker.gui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class GuiItem extends Item {
public GuiItem(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
MinecraftClient.getInstance().openScreen(new Screen(new Gui()));
return super.use(world, user, hand);
}
}
@@ -1,22 +0,0 @@
package kaptainwutax.seedcracker.gui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.LiteralText;
public class GuiScreen extends Screen {
public GuiScreen(String name) {
super(new LiteralText(name));
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
this.renderBackground();
}
@Override
public boolean isPauseScreen() {
return false;
}
}
@@ -0,0 +1,11 @@
package kaptainwutax.seedcracker.gui;
import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
public class Screen extends CottonClientScreen {
public Screen(GuiDescription description) {
super(description);
}
}
@@ -5,6 +5,7 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import kaptainwutax.seedcracker.command.ClientCommand;
import kaptainwutax.seedcracker.command.FinderCommand;
import kaptainwutax.seedcracker.command.GuiCommand;
import kaptainwutax.seedcracker.command.RenderCommand;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
@@ -23,10 +24,12 @@ public class ClientCommands {
public static RenderCommand RENDER;
public static FinderCommand FINDER;
public static GuiCommand GUI;
static {
COMMANDS.add(RENDER = new RenderCommand());
COMMANDS.add(FINDER = new FinderCommand());
COMMANDS.add(GUI = new GuiCommand());
}
public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
@@ -2,10 +2,7 @@ package kaptainwutax.seedcracker.mixin;
import com.mojang.brigadier.StringReader;
import kaptainwutax.seedcracker.SeedCracker;
import kaptainwutax.seedcracker.gui.GuiScreen;
import kaptainwutax.seedcracker.init.ClientCommands;
import kaptainwutax.seedcracker.init.KeyBindings;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -20,10 +17,6 @@ public abstract class ClientPlayerEntityMixin {
@Inject(method = "tick", at = @At("HEAD"))
private void tick(CallbackInfo ci) {
SeedCracker.get().getDataStorage().tick();
if(MinecraftClient.getInstance().currentScreen == null && KeyBindings.OPEN_MENU.isPressed()) {
MinecraftClient.getInstance().openScreen(new GuiScreen("Test"));
}
}
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
@@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "seedcracker:item/gui_item"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

+7 -1
View File
@@ -27,9 +27,15 @@
],
"depends": {
"fabricloader": ">=0.4.0"
"fabricloader": ">=0.4.0",
"fabric": "*",
"minecraft": ">=1.15"
},
"suggests": {
"flamingo": "*"
},
"custom": {
"modmenu:api": true,
"modmenu:clientsideOnly": true
}
}