Add pattern dump command (/refinedstorage patterndump)
This commit is contained in:
@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.item.group.MainItemGroup;
|
|||||||
import com.raoulvdberge.refinedstorage.network.NetworkHandler;
|
import com.raoulvdberge.refinedstorage.network.NetworkHandler;
|
||||||
import com.raoulvdberge.refinedstorage.setup.ClientSetup;
|
import com.raoulvdberge.refinedstorage.setup.ClientSetup;
|
||||||
import com.raoulvdberge.refinedstorage.setup.CommonSetup;
|
import com.raoulvdberge.refinedstorage.setup.CommonSetup;
|
||||||
|
import com.raoulvdberge.refinedstorage.setup.ServerSetup;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.inventory.container.ContainerType;
|
import net.minecraft.inventory.container.ContainerType;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -14,6 +15,7 @@ import net.minecraft.item.ItemGroup;
|
|||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
@@ -32,6 +34,8 @@ public final class RS {
|
|||||||
public RS() {
|
public RS() {
|
||||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> ClientSetup::new);
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> ClientSetup::new);
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(new ServerSetup());
|
||||||
|
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG.getSpec());
|
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG.getSpec());
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_CONFIG.getSpec());
|
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CLIENT_CONFIG.getSpec());
|
||||||
|
|
||||||
|
@@ -0,0 +1,125 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.AllowedTagList;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||||
|
import com.raoulvdberge.refinedstorage.item.PatternItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.render.Styles;
|
||||||
|
import net.minecraft.command.CommandSource;
|
||||||
|
import net.minecraft.command.Commands;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
|
public class PatternDumpCommand implements Command<CommandSource> {
|
||||||
|
public static ArgumentBuilder<CommandSource, ?> register(CommandDispatcher<CommandSource> dispatcher) {
|
||||||
|
return Commands.literal("patterndump")
|
||||||
|
.requires(cs -> cs.hasPermissionLevel(0))
|
||||||
|
.executes(new PatternDumpCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||||
|
ItemStack stack = context.getSource().asPlayer().inventory.getCurrentItem();
|
||||||
|
|
||||||
|
if (stack.getItem() instanceof PatternItem) {
|
||||||
|
boolean processing = PatternItem.isProcessing(stack);
|
||||||
|
boolean exact = PatternItem.isExact(stack);
|
||||||
|
AllowedTagList allowedTagList = PatternItem.getAllowedTags(stack);
|
||||||
|
|
||||||
|
CraftingPattern pattern = PatternItem.fromCache(context.getSource().getWorld(), stack);
|
||||||
|
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Crafting ID: ").setStyle(Styles.YELLOW).appendSibling(new StringTextComponent(pattern.getId().toString()).setStyle(Styles.WHITE)), false);
|
||||||
|
|
||||||
|
if (!pattern.isValid()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Pattern is invalid! Reason: ").appendSibling(pattern.getErrorMessage()).setStyle(Styles.RED), false);
|
||||||
|
} else {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Processing: ").setStyle(Styles.YELLOW).appendSibling(new StringTextComponent(String.valueOf(processing)).setStyle(Styles.WHITE)), false);
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Exact: ").setStyle(Styles.YELLOW).appendSibling(new StringTextComponent(String.valueOf(exact)).setStyle(Styles.WHITE)), false);
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Has allowed tag list: ").setStyle(Styles.YELLOW).appendSibling(new StringTextComponent(String.valueOf(allowedTagList != null)).setStyle(Styles.WHITE)), false);
|
||||||
|
|
||||||
|
if (pattern.isProcessing()) {
|
||||||
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
|
if (!pattern.getInputs().get(i).isEmpty()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Item inputs in slot " + i + ":").setStyle(Styles.YELLOW), false);
|
||||||
|
|
||||||
|
for (int j = 0; j < pattern.getInputs().get(i).size(); ++j) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- Possibility #" + j + ": " + pattern.getInputs().get(i).get(j).getCount() + "x ").appendSibling(pattern.getInputs().get(i).get(j).getDisplayName()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedTagList != null) {
|
||||||
|
for (ResourceLocation allowed : allowedTagList.getAllowedItemTags().get(i)) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- Allowed item tag: " + allowed.toString()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pattern.getFluidInputs().size(); ++i) {
|
||||||
|
if (!pattern.getFluidInputs().get(i).isEmpty()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Fluid inputs in slot " + i + ":").setStyle(Styles.YELLOW), false);
|
||||||
|
|
||||||
|
for (int j = 0; j < pattern.getFluidInputs().get(i).size(); ++j) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- Possibility #" + j + ": " + pattern.getFluidInputs().get(i).get(j).getAmount() + " mB ").appendSibling(pattern.getFluidInputs().get(i).get(j).getDisplayName()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowedTagList != null) {
|
||||||
|
for (ResourceLocation allowed : allowedTagList.getAllowedFluidTags().get(i)) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- Allowed fluid tag: " + allowed.toString()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Outputs").setStyle(Styles.YELLOW), false);
|
||||||
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- " + output.getCount() + "x ").appendSibling(output.getDisplayName()), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Fluid outputs").setStyle(Styles.YELLOW), false);
|
||||||
|
for (FluidStack output : pattern.getFluidOutputs()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- " + output.getAmount() + " mB ").appendSibling(output.getDisplayName()), false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
|
if (!pattern.getInputs().get(i).isEmpty()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Inputs in slot " + i + ":").setStyle(Styles.YELLOW), false);
|
||||||
|
|
||||||
|
for (int j = 0; j < pattern.getInputs().get(i).size(); ++j) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- Possibility #" + j + ": " + pattern.getInputs().get(i).get(j).getCount() + "x ").appendSibling(pattern.getInputs().get(i).get(j).getDisplayName()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Outputs").setStyle(Styles.YELLOW), false);
|
||||||
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- " + output.getCount() + "x ").appendSibling(output.getDisplayName()), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean anyByproducts = false;
|
||||||
|
|
||||||
|
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||||
|
if (!byproduct.isEmpty()) {
|
||||||
|
if (!anyByproducts) {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("Byproducts").setStyle(Styles.YELLOW), false);
|
||||||
|
|
||||||
|
anyByproducts = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("- " + byproduct.getCount() + "x ").appendSibling(byproduct.getDisplayName()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.getSource().sendFeedback(new StringTextComponent("You need to be holding a pattern in your hand.").setStyle(Styles.RED), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,7 @@ import net.minecraft.util.text.Style;
|
|||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
|
||||||
public class Styles {
|
public class Styles {
|
||||||
|
public static final Style WHITE = new Style().setColor(TextFormatting.WHITE);
|
||||||
public static final Style GRAY = new Style().setColor(TextFormatting.GRAY);
|
public static final Style GRAY = new Style().setColor(TextFormatting.GRAY);
|
||||||
public static final Style YELLOW = new Style().setColor(TextFormatting.YELLOW);
|
public static final Style YELLOW = new Style().setColor(TextFormatting.YELLOW);
|
||||||
public static final Style RED = new Style().setColor(TextFormatting.RED);
|
public static final Style RED = new Style().setColor(TextFormatting.RED);
|
||||||
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.setup;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.command.PatternDumpCommand;
|
||||||
|
import net.minecraft.command.Commands;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||||
|
|
||||||
|
public class ServerSetup {
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onServerStarting(FMLServerStartingEvent e) {
|
||||||
|
e.getCommandDispatcher().register(
|
||||||
|
Commands.literal("refinedstorage")
|
||||||
|
.then(PatternDumpCommand.register(e.getCommandDispatcher()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user