Skip to content

Commit

Permalink
更新 编写指令系统与按键设置
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallXY committed Dec 30, 2022
1 parent 01319b6 commit a40ee85
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 48 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# AVMWandMod

致力于模仿与创造不可能~
请注意在创造块法杖可能会毁端请玩之前备份客户端的所有~
7 changes: 4 additions & 3 deletions src/main/java/net/lanternmc/avmwandmod/AVMWandMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.lanternmc.avmwandmod.NBT.CopyItem;
import net.lanternmc.avmwandmod.red.CommandWand;
import net.lanternmc.avmwandmod.red.RedWands;
import net.minecraft.block.BlockState;
Expand All @@ -19,13 +20,13 @@

public class AVMWandMod implements ModInitializer {

private static final Item AVM_WAND_EMPTY =
public static final Item AVM_WAND_EMPTY =
Registry.register(Registries.ITEM, new Identifier("avmwandmod", "red"),
new Item(new FabricItemSettings().maxCount(1)));
private static final Item AVM_WAND_MC =
public static final Item AVM_WAND_MC =
Registry.register(Registries.ITEM, new Identifier("avmwandmod", "creative"),
new RedWands(new FabricItemSettings().maxCount(1)));
private static final Item AVM_WAND_CB =
public static final Item AVM_WAND_CB =
Registry.register(Registries.ITEM, new Identifier("avmwandmod", "commandblock"),
new CommandWand(new FabricItemSettings().maxCount(1)));

Expand Down
33 changes: 0 additions & 33 deletions src/main/java/net/lanternmc/avmwandmod/Command/BianXie.java

This file was deleted.

29 changes: 29 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/Command/CmdGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.lanternmc.avmwandmod.Command;

import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
import io.github.cottonmc.cotton.gui.widget.WButton;
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
import io.github.cottonmc.cotton.gui.widget.WTextField;
import io.github.cottonmc.cotton.gui.widget.data.Insets;
import net.lanternmc.avmwandmod.NBT.CmdRunnable;
import net.minecraft.entity.player.PlayerEntity;

public class CmdGUI extends LightweightGuiDescription {

public CmdGUI(PlayerEntity player) {
WPlainPanel panel = new WPlainPanel();
panel.setInsets(Insets.ROOT_PANEL);

WTextField inPut = new WTextField();
inPut.setSize(500, 100);
panel.add(inPut, 5,5);
WButton button = new WButton();
button.setOnClick(new CmdRunnable(player, inPut.getText()));
button.setSize(100, 100);
panel.add(button,0,10);

setFullscreen(true);
setRootPanel(panel);
}

}
13 changes: 13 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/Command/CmdScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.lanternmc.avmwandmod.Command;

import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
import net.minecraft.text.Text;

public class CmdScreen extends CottonClientScreen {


public CmdScreen(GuiDescription description) {
super(description);
}
}
20 changes: 20 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/NBT/CmdRunnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.lanternmc.avmwandmod.NBT;

import net.minecraft.entity.player.PlayerEntity;

public class CmdRunnable implements Runnable {

private final PlayerEntity player;
private final String command;

public CmdRunnable(PlayerEntity p, String command) {
this.player = p;
this.command = command;
}

@Override
public void run() {
NBTManager.GenNBT(command, player.getMainHandStack());
}

}
9 changes: 9 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/NBT/CopyItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.lanternmc.avmwandmod.NBT;

import net.minecraft.item.Item;

public class CopyItem extends Item {
public CopyItem(Settings settings) {
super(settings);
}
}
22 changes: 22 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/NBT/NBTManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.lanternmc.avmwandmod.NBT;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;

import java.util.Objects;

public class NBTManager {

public static void GenNBT(String CommandInfo, ItemStack is) {
NbtCompound nbt = new NbtCompound();
nbt.putString("Command", CommandInfo);
is.setNbt(nbt);
}


public static String loadNBT(ItemStack is) {
NbtCompound nbt = is.getNbt();
return Objects.requireNonNull(nbt).getString("Command");
}

}
13 changes: 13 additions & 0 deletions src/main/java/net/lanternmc/avmwandmod/Resourcepack/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.lanternmc.avmwandmod.Resourcepack;

import net.minecraft.client.resource.DefaultClientResourcePackProvider;

import java.nio.file.Path;

public class Test {

public void init() {
DefaultClientResourcePackProvider rp = new DefaultClientResourcePackProvider(Path.of("resourcepacks","resourcepacks"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.lanternmc.avmwandmod.Command.BianXie;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.registry.Registry;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.lanternmc.avmwandmod.AVMWandMod;
import net.lanternmc.avmwandmod.Command.CmdGUI;
import net.lanternmc.avmwandmod.Command.CmdScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class AVMWandModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("Show Debug Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B,"Debug Menu"));
// HandledScreens.<BianXie, ExampleBlockScreen>register(MyMod.SCREEN_HANDLER_TYPE, (gui, inventory, title) -> new ExampleBlockScreen(gui, inventory.player, title));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (keyBinding.wasPressed()) {
if (client.player != null
&& client.player.getMainHandStack().getItem() == AVMWandMod.AVM_WAND_CB) {
client.setScreen(new CmdScreen(new CmdGUI(client.player)));
}
}
});
}
}
26 changes: 18 additions & 8 deletions src/main/java/net/lanternmc/avmwandmod/red/CommandWand.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package net.lanternmc.avmwandmod.red;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.lanternmc.avmwandmod.Command.CmdGUI;
import net.lanternmc.avmwandmod.Command.CmdScreen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.Objects;

public class CommandWand extends Item {
public CommandWand(Settings settings) {
super(settings);
Expand All @@ -25,4 +21,18 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity p, Hand hand)
return TypedActionResult.success(p.getStackInHand(hand));
}

@Override
public boolean hasGlint(ItemStack stack) {
if(stack.hasNbt()) {
assert stack.getNbt() != null;
return stack.getNbt().getString("command").isEmpty();
}
return false;
}

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
// context.getPlayer().open.setScreen(new CmdScreen(new CmdGUI()));
return ActionResult.success(context.hitsInsideBlock());
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/lanternmc/avmwandmod/red/RedWands.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public RedWands(Settings settings) {

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity p, Hand hand) {

//删除save
if (OSinfo.isWindows()) {
new Delete().DeleteBat();
// p.sendMessage(Text.of(FilePath.mcRoot.getAbsolutePath()));
} else {
new Delete().DeleteSh();
}
Expand Down

0 comments on commit a40ee85

Please sign in to comment.