Re-implemented the /refinedstorage createdisk command.

This commit is contained in:
raoulvdberge
2020-09-05 16:38:15 +02:00
parent c621a16ab3
commit be91d5ba93
16 changed files with 191 additions and 123 deletions

View File

@@ -1,6 +1,7 @@
# Refined Storage Changelog
### 1.9.5
- Re-implemented the /refinedstorage createdisk command (raoulvdberge)
- Added JEI ghost ingredient dragging support (raoulvdberge)
### 1.9.4

View File

@@ -50,10 +50,4 @@ public final class RS {
API.deliver();
}
/* TODO
@EventHandler
public void onServerStarting(FMLServerStartingEvent e) {
e.registerServerCommand(new CommandCreateDisk());
}*/
}

View File

@@ -1,8 +1,11 @@
package com.refinedmods.refinedstorage.api.storage.disk;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.server.ServerWorld;
import java.util.UUID;
/**
* Creates a storage disk from NBT or on-demand.
*
@@ -18,6 +21,15 @@ public interface IStorageDiskFactory<T> {
*/
IStorageDisk<T> createFromNbt(ServerWorld world, CompoundNBT tag);
/**
* Creates a storage disk item based on ID.
*
* @param disk the disk
* @param id the disk id
* @return the storage disk
*/
ItemStack createDiskItem(IStorageDisk<T> disk, UUID id);
/**
* Creates a storage disk on-demand.
*

View File

@@ -1,9 +1,12 @@
package com.refinedmods.refinedstorage.apiimpl.storage.disk.factory;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory;
import com.refinedmods.refinedstorage.apiimpl.storage.disk.FluidStorageDisk;
import com.refinedmods.refinedstorage.item.FluidStorageDiskItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.util.ResourceLocation;
@@ -11,6 +14,8 @@ import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.FluidStack;
import java.util.UUID;
public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack> {
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "fluid");
@@ -31,6 +36,32 @@ public class FluidStorageDiskFactory implements IStorageDiskFactory<FluidStack>
return disk;
}
@Override
public ItemStack createDiskItem(IStorageDisk<FluidStack> disk, UUID id) {
FluidStorageDiskItem item;
switch (disk.getCapacity()) {
case 64_000:
item = RSItems.SIXTY_FOUR_K_FLUID_STORAGE_DISK;
break;
case 256_000:
item = RSItems.TWO_HUNDRED_FIFTY_SIX_K_FLUID_STORAGE_DISK;
break;
case 1024_000:
item = RSItems.THOUSAND_TWENTY_FOUR_K_FLUID_STORAGE_DISK;
break;
case 4096_000:
item = RSItems.FOUR_THOUSAND_NINETY_SIX_K_FLUID_STORAGE_DISK;
break;
default:
item = RSItems.CREATIVE_FLUID_STORAGE_DISK;
break;
}
ItemStack stack = new ItemStack(item);
item.setId(stack, id);
return stack;
}
@Override
public IStorageDisk<FluidStack> create(ServerWorld world, int capacity) {
return new FluidStorageDisk(world, capacity);

View File

@@ -1,10 +1,15 @@
package com.refinedmods.refinedstorage.apiimpl.storage.disk.factory;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.apiimpl.storage.ItemStorageType;
import com.refinedmods.refinedstorage.apiimpl.storage.disk.ItemStorageDisk;
import com.refinedmods.refinedstorage.item.StorageDiskItem;
import com.refinedmods.refinedstorage.util.StackUtils;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
@@ -12,6 +17,8 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.Constants;
import java.util.UUID;
public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> {
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "item");
@@ -32,6 +39,32 @@ public class ItemStorageDiskFactory implements IStorageDiskFactory<ItemStack> {
return disk;
}
@Override
public ItemStack createDiskItem(IStorageDisk<ItemStack> disk, UUID id) {
StorageDiskItem item;
switch (disk.getCapacity()) {
case 1_000:
item = RSItems.ONE_K_STORAGE_DISK;
break;
case 4_000:
item = RSItems.FOUR_K_STORAGE_DISK;
break;
case 16_000:
item = RSItems.SIXTEEN_K_STORAGE_DISK;
break;
case 64_000:
item = RSItems.SIXTY_FOUR_K_STORAGE_DISK;
break;
default:
item = RSItems.CREATIVE_STORAGE_DISK;
break;
}
ItemStack stack = new ItemStack(item);
item.setId(stack, id);
return stack;
}
@Override
public IStorageDisk<ItemStack> create(ServerWorld world, int capacity) {
return new ItemStorageDisk(world, capacity);

View File

@@ -1,92 +0,0 @@
package com.refinedmods.refinedstorage.command;
/* TODO
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskProvider;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class CommandCreateDisk extends Command {
@Override
public String getName() {
return "createdisk";
}
@Override
public String getUsage(ICommandSender sender) {
return "commands.refinedstorage.createdisk.usage";
}
@Override
public int getRequiredPermissionLevel() {
return 2;
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 4) {
throw new WrongUsageException("commands.refinedstorage.createdisk.usage");
} else {
PlayerEntity player = getPlayer(server, sender, args[0]);
Item item = getItemByText(sender, args[1]);
int metadata = parseInt(args[2]);
UUID id;
try {
id = UUID.fromString(args[3]);
} catch (IllegalArgumentException e) {
throw new CommandException("commands.refinedstorage.createdisk.error.diskNotFound", args[3]);
}
if (!(item instanceof IStorageDiskProvider)) {
throw new CommandException("commands.refinedstorage.createdisk.error.notADisk");
}
IStorageDisk disk = API.instance().getStorageDiskManager(sender.getEntityWorld()).get(id);
if (disk == null) {
throw new CommandException("commands.refinedstorage.createdisk.error.diskNotFound", args[3]);
}
ItemStack diskStack = new ItemStack(item, 1, metadata);
((IStorageDiskProvider) item).setId(diskStack, id);
if (player.inventory.addItemStackToInventory(diskStack)) {
// From CommandGive
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.inventoryContainer.detectAndSendChanges();
}
notifyCommandListener(sender, this, "commands.refinedstorage.createdisk.success", args[3], player.getName());
}
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
} else if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, Item.REGISTRY.getKeys());
} else if (args.length == 4) {
return getListOfStringsMatchingLastWord(args, API.instance().getStorageDiskManager(sender.getEntityWorld()).getAll().keySet().stream().map(UUID::toString).collect(Collectors.toList()));
}
return Collections.emptyList();
}
}
*/

View File

@@ -0,0 +1,80 @@
package com.refinedmods.refinedstorage.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskFactory;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.render.Styles;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.EntityArgument;
import net.minecraft.command.arguments.UUIDArgument;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import java.util.UUID;
public class CreateDiskCommand implements Command<CommandSource> {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("createdisk")
.requires(cs -> cs.hasPermissionLevel(2))
.then(Commands.argument("player", EntityArgument.player())
.then(Commands.argument("id", UUIDArgument.func_239194_a_()).suggests(new StorageDiskIdSuggestionProvider())
.executes(new CreateDiskCommand())
)
);
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
PlayerEntity player = EntityArgument.getPlayer(context, "player");
UUID id = UUIDArgument.func_239195_a_(context, "id");
IStorageDisk<?> disk = API.instance().getStorageDiskManager(context.getSource().getWorld()).get(id);
if (disk == null) {
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.createdisk.error.diskNotFound", id));
} else {
IStorageDiskFactory factory = API.instance().getStorageDiskRegistry().get(disk.getFactoryId());
if (factory != null) {
ItemStack stack = factory.createDiskItem(disk, id);
// @Volatile: From GiveCommand
boolean flag = player.inventory.addItemStackToInventory(stack);
if (flag && stack.isEmpty()) {
stack.setCount(1);
ItemEntity itemEntity = player.dropItem(stack, false);
if (itemEntity != null) {
itemEntity.makeFakeItem();
}
player.world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.container.detectAndSendChanges();
} else {
ItemEntity itemEntity = player.dropItem(stack, false);
if (itemEntity != null) {
itemEntity.setNoPickupDelay();
itemEntity.setOwnerId(player.getUniqueID());
}
}
context.getSource().sendFeedback(new TranslationTextComponent(
"commands.refinedstorage.createdisk.success",
new StringTextComponent(id.toString()).setStyle(Styles.YELLOW),
context.getSource().getDisplayName().deepCopy().setStyle(Styles.YELLOW)
), false);
}
}
return 0;
}
}

View File

@@ -1,7 +1,6 @@
package com.refinedmods.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;
@@ -17,7 +16,7 @@ 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) {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("patterndump")
.requires(cs -> cs.hasPermissionLevel(0))
.executes(new PatternDumpCommand());
@@ -37,7 +36,7 @@ public class PatternDumpCommand implements Command<CommandSource> {
context.getSource().sendFeedback(new StringTextComponent("Crafting task factory ID: ").setStyle(Styles.YELLOW).append(new StringTextComponent(pattern.getCraftingTaskFactoryId().toString()).setStyle(Styles.WHITE)), false);
if (!pattern.isValid()) {
context.getSource().sendFeedback(new StringTextComponent("Pattern is invalid! Reason: ").append(pattern.getErrorMessage()).setStyle(Styles.RED), false);
context.getSource().sendErrorMessage(new StringTextComponent("Pattern is invalid! Reason: ").append(pattern.getErrorMessage()));
} else {
context.getSource().sendFeedback(new StringTextComponent("Processing: ").setStyle(Styles.YELLOW).append(new StringTextComponent(String.valueOf(processing)).setStyle(Styles.WHITE)), false);
context.getSource().sendFeedback(new StringTextComponent("Exact: ").setStyle(Styles.YELLOW).append(new StringTextComponent(String.valueOf(exact)).setStyle(Styles.WHITE)), false);
@@ -117,7 +116,7 @@ public class PatternDumpCommand implements Command<CommandSource> {
}
}
} else {
context.getSource().sendFeedback(new StringTextComponent("You need to be holding a pattern in your hand.").setStyle(Styles.RED), false);
context.getSource().sendErrorMessage(new StringTextComponent("You need to be holding a pattern in your hand."));
}
return 0;

View File

@@ -0,0 +1,22 @@
package com.refinedmods.refinedstorage.command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import java.util.concurrent.CompletableFuture;
public class StorageDiskIdSuggestionProvider implements SuggestionProvider<CommandSource> {
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) {
API.instance().getStorageDiskManager(context.getSource().getWorld())
.getAll()
.keySet()
.forEach(id -> builder.suggest(id.toString()));
return builder.buildFuture();
}
}

View File

@@ -1,5 +1,7 @@
package com.refinedmods.refinedstorage.setup;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.command.CreateDiskCommand;
import com.refinedmods.refinedstorage.command.PatternDumpCommand;
import net.minecraft.command.Commands;
import net.minecraftforge.event.RegisterCommandsEvent;
@@ -8,9 +10,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ServerSetup {
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent e) {
e.getDispatcher().register(
Commands.literal("refinedstorage")
.then(PatternDumpCommand.register(e.getDispatcher()))
);
e.getDispatcher().register(Commands.literal(RS.ID).then(PatternDumpCommand.register()));
e.getDispatcher().register(Commands.literal(RS.ID).then(CreateDiskCommand.register()));
}
}

View File

@@ -281,8 +281,6 @@
"item.refinedstorage.security_card.owner": "Besitzer: %s",
"item.refinedstorage.processor_binding": "Prozessor Rohmaterial",
"commands.refinedstorage.createdisk.usage": "/createdisk <Spieler> <Item> <Metadaten> <ID>",
"commands.refinedstorage.createdisk.error.notADisk": "Das Item ist keine Speicherzelle.",
"commands.refinedstorage.createdisk.error.diskNotFound": "Speicherzelle %s konnte nicht gefunden werden.",
"commands.refinedstorage.createdisk.success": "Speicherzelle %s erfolgreich an %s gegeben.",
@@ -347,4 +345,4 @@
"advancements.refinedstorage.interface_to_the_world.description": "Benutze ein Interface, um gleichzeitig Items zu exportieren und zu importieren",
"advancements.refinedstorage.storing_externally": "Speicher auslagern",
"advancements.refinedstorage.storing_externally.description": "Benutze einen externen Speicher um externe Itemquellen wie zum Beispiel Kisten anzubinden"
}
}

View File

@@ -307,8 +307,6 @@
"item.refinedstorage.security_card.owner": "Bound to: %s",
"item.refinedstorage.processor_binding": "Processor Binding",
"commands.refinedstorage.createdisk.usage": "/createdisk <player> <item> <metadata> <id>",
"commands.refinedstorage.createdisk.error.notADisk": "The given disk item is not a disk.",
"commands.refinedstorage.createdisk.error.diskNotFound": "Disk %s was not found.",
"commands.refinedstorage.createdisk.success": "Successfully gave disk %s to %s.",
@@ -373,4 +371,4 @@
"advancements.refinedstorage.interface_to_the_world.description": "Export and import items at the same time with an Interface",
"advancements.refinedstorage.storing_externally": "Storing externally",
"advancements.refinedstorage.storing_externally.description": "Use an External Storage to provide the network with storage from an external block like a chest"
}
}

View File

@@ -307,8 +307,6 @@
"item.refinedstorage.security_card.owner": "所有者: %s",
"item.refinedstorage.processor_binding": "プロセッサ接合材",
"commands.refinedstorage.createdisk.usage": "/createdisk <プレイヤー> <アイテム> <メタデータ> <id>",
"commands.refinedstorage.createdisk.error.notADisk": "指定されたアイテムはディスクではありません",
"commands.refinedstorage.createdisk.error.diskNotFound": "ディスク%sが見つかりません",
"commands.refinedstorage.createdisk.success": "ディスク%sを%sに割り当てました",
@@ -373,4 +371,4 @@
"advancements.refinedstorage.interface_to_the_world.description": "インターフェースでアイテムの搬入出を同時に行う",
"advancements.refinedstorage.storing_externally": "外部保管",
"advancements.refinedstorage.storing_externally.description": "拡張ストレージを利用してチェストのような外部のブロックからネットワークにストレージを供給する"
}
}

View File

@@ -306,8 +306,6 @@
"item.refinedstorage.security_card.owner": "Привязана к %s",
"item.refinedstorage.processor_binding": "Связующий процессорный компонент",
"commands.refinedstorage.createdisk.usage": "/createdisk <игрок> <предмет> <метаданные> <id>",
"commands.refinedstorage.createdisk.error.notADisk": "Данный предмет не является диском.",
"commands.refinedstorage.createdisk.error.diskNotFound": "Диск %s не был найден.",
"commands.refinedstorage.createdisk.success": "Диск %s успешно выдан %s.",
@@ -372,4 +370,4 @@
"advancements.refinedstorage.interface_to_the_world.description": "Экспортируйте и импортируйте предметы одновременно с помощью интерфейса",
"advancements.refinedstorage.storing_externally": "Внешнее хранение",
"advancements.refinedstorage.storing_externally.description": "Используйте шину внешнего хранения для подключения к сети внешнего хранилища, например сундука"
}
}

View File

@@ -301,8 +301,6 @@
"item.refinedstorage.hollow_cover": "空心伪装板",
"item.refinedstorage.processor_binding": "处理器粘合物",
"commands.refinedstorage.createdisk.usage": "/createdisk <玩家> <物品> <metadata> <id>",
"commands.refinedstorage.createdisk.error.notADisk": "该物品不是磁盘.",
"commands.refinedstorage.createdisk.error.diskNotFound": "磁盘 %s 未找到.",
"commands.refinedstorage.createdisk.success": "成功把磁盘 %s 给了 %s.",
@@ -375,4 +373,4 @@
"advancements.refinedstorage.hollow_covering.description": "合成【空心伪装板】来隐藏线缆并不阻碍线缆穿过",
"advancements.refinedstorage.binding": "粘合物",
"advancements.refinedstorage.binding.description": "合成【处理器粘合物】来制作各种处理器"
}
}

View File

@@ -307,8 +307,6 @@
"item.refinedstorage.security_card.owner": "綁定至: %s",
"item.refinedstorage.processor_binding": "處理器黏合物",
"commands.refinedstorage.createdisk.usage": "/createdisk <player> <item> <metadata> <id>",
"commands.refinedstorage.createdisk.error.notADisk": "該物品不是磁碟.",
"commands.refinedstorage.createdisk.error.diskNotFound": "磁碟 %s 未找到.",
"commands.refinedstorage.createdisk.success": "成功把磁碟 %s 給了 %s.",