Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bug1312 committed Oct 28, 2022
1 parent c4df146 commit e8b850e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=false
minecraft_version = 1.16.5
forge_version = 36.2.30

version = 1.0.1
version = 1.1.0

mods.extra_mods = true

Expand Down
29 changes: 26 additions & 3 deletions src/main/java/com/bug1312/dalekmoddev/DMDT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import com.bug1312.dalekmoddev.commands.CommandCreateTardisImage;
import com.bug1312.dalekmoddev.commands.CommandCreateTardisSchem;
import com.bug1312.dalekmoddev.commands.CommandGetInteriorPos;
import com.bug1312.dalekmoddev.commands.CommandGiveChameleon;
import com.bug1312.dalekmoddev.commands.arguments.ChameleonArgument;
import com.google.common.base.Supplier;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;

import net.minecraft.command.CommandSource;
import net.minecraft.command.arguments.ArgumentSerializer;
import net.minecraft.command.arguments.ArgumentTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@Mod(DMDT.MOD_ID)
public class DMDT {
Expand All @@ -17,11 +27,24 @@ public DMDT() {
MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent
public void registerArguments(FMLCommonSetupEvent event) {
registerArgument("chameleon", ChameleonArgument::chameleon);
}

@SuppressWarnings("unchecked")
private static <T extends ArgumentType<?>> void registerArgument(String id, Supplier<T> argument) {
ArgumentTypes.register(new ResourceLocation(MOD_ID, id).toString(), (Class<T>) argument.get().getClass(), new ArgumentSerializer<>(argument));
}

@SubscribeEvent
public void registerCommands(RegisterCommandsEvent event) {
CommandCreateTardisImage.register(event.getDispatcher());
CommandCreateTardisSchem.register(event.getDispatcher());
CommandGetInteriorPos.register(event.getDispatcher());
CommandDispatcher<CommandSource> d = event.getDispatcher();

CommandCreateTardisImage.register(d);
CommandCreateTardisSchem.register(d);
CommandGetInteriorPos.register(d);
CommandGiveChameleon.register(d);
}

}
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;
})));
}

}

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;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license="MIT"
issueTrackerURL="https://github.com/Bug1312/dalekmoddev/issues"
[[mods]]
modId="dalekmoddev"
version="1.0.0"
version="1.1.0"
displayName="Dalek Mod Dev Tools"
displayURL="https://github.com/Bug1312/dalekmoddev"
logoFile="logo.png"
Expand Down

0 comments on commit e8b850e

Please sign in to comment.