This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
5 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/bug1312/dalekmoddev/commands/CommandGiveChameleon.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,39 @@ | ||
package com.bug1312.dalekmoddev.commands; | ||
|
||
import com.bug1312.dalekmoddev.commands.arguments.ChameleonArgument; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import com.swdteam.common.init.DMItems; | ||
|
||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.command.Commands; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
public class CommandGiveChameleon { | ||
|
||
// Input chameleon and get a circuit. | ||
// Gives chameleon circuit with skin ID set to inputed value | ||
|
||
private static final LiteralArgumentBuilder<CommandSource> INITIAL = Commands.literal("dev-cartridge"); | ||
private static final RequiredArgumentBuilder<CommandSource, ResourceLocation> SKIN = Commands.argument("skin", ChameleonArgument.chameleon()); | ||
|
||
public static void register(CommandDispatcher<CommandSource> dispatcher) { | ||
dispatcher.register(INITIAL.then(SKIN.executes((commandContext) -> { | ||
ServerPlayerEntity player = commandContext.getSource().getPlayerOrException(); | ||
String skin = commandContext.getArgument("skin", ResourceLocation.class).toString(); | ||
|
||
ItemStack stack = new ItemStack(DMItems.CHAMELEON_CATRTIDGE.get()); | ||
CompoundNBT tag = stack.getOrCreateTag(); | ||
tag.putString("skin_id", skin); | ||
|
||
player.addItem(stack); | ||
return 1; | ||
}))); | ||
} | ||
|
||
} | ||
|
56 changes: 56 additions & 0 deletions
56
src/main/java/com/bug1312/dalekmoddev/commands/arguments/ChameleonArgument.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,56 @@ | ||
package com.bug1312.dalekmoddev.commands.arguments; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; | ||
import com.swdteam.common.init.DMTardisRegistry; | ||
import com.swdteam.common.tardis.Tardis; | ||
|
||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.command.ISuggestionProvider; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
public class ChameleonArgument implements ArgumentType<ResourceLocation>, Serializable { | ||
|
||
private static final long serialVersionUID = 7899063015209167811L; | ||
private static final Collection<String> EXAMPLES = Arrays.asList("dalekmod:tardis_capsule", "dalekmod:police_box", "dalekmod:pagoda"); | ||
|
||
public static ChameleonArgument chameleon() { return new ChameleonArgument(); } | ||
|
||
public static ResourceLocation getResource(CommandContext<CommandSource> context, String input) { | ||
return context.getArgument(input, ResourceLocation.class); | ||
} | ||
|
||
@Override | ||
public ResourceLocation parse(StringReader reader) throws CommandSyntaxException { | ||
return ResourceLocation.read(reader); | ||
} | ||
|
||
@Override | ||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { | ||
List<String> suggestions = new ArrayList<>(); | ||
|
||
for (Entry<ResourceLocation, Tardis> tardis : DMTardisRegistry.getRegistry().entrySet()) { | ||
suggestions.add(tardis.getKey().toString()); | ||
} | ||
|
||
return ISuggestionProvider.suggest(suggestions, builder); | ||
} | ||
|
||
@Override | ||
public Collection<String> getExamples() { | ||
return EXAMPLES; | ||
} | ||
|
||
} |
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