-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/johanvonelectrum/johan_carpet/commands/CommandItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.johanvonelectrum.johan_carpet.commands; | ||
|
||
import com.johanvonelectrum.johan_carpet.JohanSettings; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.BoolArgumentType; | ||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.text.LiteralText; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static net.minecraft.server.command.CommandManager.argument; | ||
import static net.minecraft.server.command.CommandManager.literal; | ||
|
||
public class CommandItem { | ||
|
||
public static final Map<Integer, List<Item>> ITEMS = new HashMap<>(); | ||
|
||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { | ||
LiteralArgumentBuilder literalargumentbuilder = literal("item") | ||
.requires((player) -> JohanSettings.commandItem) | ||
.then(argument("stack_size", IntegerArgumentType.integer(1, 64)) | ||
.executes(context -> getItemCount(context.getSource(), IntegerArgumentType.getInteger(context, "stack_size"), false)) | ||
.then(argument("list", BoolArgumentType.bool()) | ||
.executes(context -> getItemCount(context.getSource(), IntegerArgumentType.getInteger(context, "stack_size"), BoolArgumentType.getBool(context, "list"))) | ||
) | ||
); | ||
|
||
dispatcher.register(literalargumentbuilder); | ||
} | ||
|
||
private static int getItemCount(ServerCommandSource source, int stackSize, boolean list) throws CommandSyntaxException { | ||
List<Item> items = ITEMS.get(stackSize); | ||
if (items != null) { | ||
source.sendFeedback(new LiteralText("There are " + items.size() + " items whose stack size is " + stackSize + "."), false); | ||
|
||
if (!list) | ||
return 1; | ||
|
||
String result = items.stream() | ||
.map(n -> Registry.ITEM.getId(n).toString()) | ||
.collect(Collectors.joining("\n", "", "")); | ||
source.sendFeedback(new LiteralText(result), false); | ||
return 0; | ||
} else | ||
source.sendError(new LiteralText("There are no items whose stack size is " + stackSize + ".")); | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/johanvonelectrum/johan_carpet/mixins/ItemMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.johanvonelectrum.johan_carpet.mixins; | ||
|
||
import com.johanvonelectrum.johan_carpet.JohanSettings; | ||
import net.minecraft.item.Item; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Item.class) | ||
public class ItemMixin { | ||
|
||
@Inject(method = "getMaxCount", at=@At("HEAD"), cancellable = true) | ||
public final void getMaxCount(CallbackInfoReturnable<Integer> cir) { | ||
if (JohanSettings.allStackable) | ||
cir.setReturnValue(64); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/johanvonelectrum/johan_carpet/mixins/ItemsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.johanvonelectrum.johan_carpet.mixins; | ||
|
||
import com.johanvonelectrum.johan_carpet.commands.CommandItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mixin(Items.class) | ||
public class ItemsMixin { | ||
|
||
@Inject(method = "register(Lnet/minecraft/util/Identifier;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;", at = @At("HEAD")) | ||
private static void register(Identifier id, Item item, CallbackInfoReturnable<Item> cir) { | ||
List<Item> eqSizeItems = CommandItem.ITEMS.computeIfAbsent(item.getMaxCount(), k -> new ArrayList<>()); | ||
|
||
eqSizeItems.add(item); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters