Skip to content

Commit

Permalink
add: LoomModule + CartographyModule + SmithingModule
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Jul 7, 2024
1 parent 3ec26c1 commit 02b5310
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/github/sakurawald/config/model/ConfigModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -926,5 +926,20 @@ public class CommandRewrite {

}

public Loom loom = new Loom();
public class Loom {
public boolean enable = false;
}

public Cartography cartography = new Cartography();
public class Cartography {
public boolean enable = false;
}

public Smithing smithing = new Smithing();
public class Smithing {
public boolean enable = false;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.sakurawald.module.initializer.cartography;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import io.github.sakurawald.module.initializer.ModuleInitializer;
import io.github.sakurawald.util.CommandUtil;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.CartographyTableScreenHandler;
import net.minecraft.screen.LoomScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;

public class CartographyModule extends ModuleInitializer {
@Override
public void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
dispatcher.register(CommandManager.literal("cartography").executes(this::$cartography));
}

private int $cartography(CommandContext<ServerCommandSource> ctx) {
return CommandUtil.playerOnlyCommand(ctx, player -> {
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inventory, p) -> new CartographyTableScreenHandler(i, inventory, ScreenHandlerContext.create(p.getWorld(), p.getBlockPos())) {
@Override
public boolean canUse(PlayerEntity player) {
return true;
}
}, Text.translatable("container.cartography_table")));
player.incrementStat(Stats.INTERACT_WITH_CARTOGRAPHY_TABLE);
return Command.SINGLE_SUCCESS;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.sakurawald.module.initializer.loom;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import io.github.sakurawald.module.initializer.ModuleInitializer;
import io.github.sakurawald.util.CommandUtil;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.*;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;

public class LoomModule extends ModuleInitializer {
@Override
public void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
dispatcher.register(CommandManager.literal("loom").executes(this::$loom));
}

private int $loom(CommandContext<ServerCommandSource> ctx) {
return CommandUtil.playerOnlyCommand(ctx, player -> {
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inventory, p) -> new LoomScreenHandler(i, inventory, ScreenHandlerContext.create(p.getWorld(), p.getBlockPos())) {
@Override
public boolean canUse(PlayerEntity player) {
return true;
}
}, Text.translatable("container.loom")));
player.incrementStat(Stats.INTERACT_WITH_LOOM);
return Command.SINGLE_SUCCESS;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.sakurawald.module.initializer.smithing;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import io.github.sakurawald.module.initializer.ModuleInitializer;
import io.github.sakurawald.util.CommandUtil;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.*;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;

public class SmithInitializer extends ModuleInitializer {

@Override
public void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
dispatcher.register(CommandManager.literal("smithing").executes(this::$smithing));
}

private int $smithing(CommandContext<ServerCommandSource> ctx) {
return CommandUtil.playerOnlyCommand(ctx, player -> {
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inventory, p) -> new SmithingScreenHandler(i, inventory, ScreenHandlerContext.create(p.getWorld(), p.getBlockPos())) {
@Override
public boolean canUse(PlayerEntity player) {
return true;
}
}, Text.translatable("block.minecraft.smithing_table")));
player.incrementStat(Stats.INTERACT_WITH_SMITHING_TABLE);
return Command.SINGLE_SUCCESS;
});
}
}

0 comments on commit 02b5310

Please sign in to comment.