Skip to content

Commit

Permalink
Finished Lang, now needs FAPI tho
Browse files Browse the repository at this point in the history
  • Loading branch information
OverlordsIII committed Oct 2, 2020
1 parent ad0eb77 commit b9490e2
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 46 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
//resource loader from fabric api
modImplementation(fabricApi.module('fabric-resource-loader-v0', project.fabric_version))

//config
modApi("me.sargunvohra.mcmods:autoconfig1u:3.2.2") {
exclude(group: "net.fabricmc.fabric-api")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ minecraft_version=1.16.3
yarn_mappings=1.16.3+build.17
loader_version=0.9.3+build.207
# Mod Properties
fabric_version=0.21.0+build.407-1.16
mod_version=1.0.0
maven_group=io.github.overlordsiii
archives_base_name=configuredkeepinventory-1.16.3
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class ConfiguredKeepInventory implements ModInitializer {
public static InventoryConfig Config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig();
@Override
public void onInitialize() {

}
}
76 changes: 35 additions & 41 deletions src/main/java/io/github/overlordsiii/command/InventoryCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

;




public class InventoryCommand {
static InventoryConfig config = ConfiguredKeepInventory.Config;
static ConfigManager manager = ConfiguredKeepInventory.manager;
private static InventoryConfig config = ConfiguredKeepInventory.Config;
private static ConfigManager manager = ConfiguredKeepInventory.manager;
//TODO redo the Translatable text cuz lang wasnt working
public static void register(CommandDispatcher<ServerCommandSource> dispatcher){
dispatcher.register(literal("inventory")
Expand Down Expand Up @@ -55,53 +57,44 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher){
.executes(context -> executeRemoveName(context, StringArgumentType.getString(context, "name"))))))
.then(literal("enable")
.then(literal("vanishing")
.executes(context -> executeEnchantEnable("vanishing", context))))
.executes(context -> executeEnchantEnable("vanishing", context)))
.then(literal("binding")
.executes(context -> executeEnchantEnable("binding", context)))
.executes(context -> executeEnchantEnable("binding", context))))
.then(literal("help")
.executes(InventoryCommand::executeSummary))
.then(literal("disable")
.then(literal("vanishing")
.executes(context -> executeEnchantDisable("vanishing", context))))
.executes(context -> executeEnchantDisable("vanishing", context)))
.then(literal("binding")
.executes(context -> executeEnchantDisable("binding", context))));
.executes(context -> executeEnchantDisable("binding", context)))));
}
public static int execute(CommandContext<ServerCommandSource> ctx, int value) {
config.configdroprate = value;
manager.save();
// ctx.getSource().sendFeedback(new TranslatableText("inventory.set", value), true);
ctx.getSource().sendFeedback(new LiteralText("set the inventory droprate to " + value + " percent").formatted(Formatting.AQUA), true);
ctx.getSource().sendFeedback(new TranslatableText("inventory.set", value), true);
// ctx.getSource().sendFeedback(new LiteralText("set the inventory droprate to " + value + " percent").formatted(Formatting.AQUA), true);
return 1;
}
public static int executeOn(CommandContext<ServerCommandSource> ctx, boolean onoroff){
if (onoroff){
config.enableConfig = true;
manager.save();
ctx.getSource().sendFeedback(new LiteralText("the config has been turned on").formatted(Formatting.GREEN), true);
}
else{
config.enableConfig = false;
public static int executeOn(CommandContext<ServerCommandSource> ctx, boolean onoroff) throws CommandSyntaxException {
config.enableConfig = onoroff;
manager.save();
ctx.getSource().sendFeedback(new LiteralText("the config has been turned off").formatted(Formatting.RED), true);
}
// ctx.getSource().sendFeedback(new TranslatableText("config.on").formatted(Formatting.GREEN), true);

ctx.getSource().sendFeedback(new TranslatableText("config.on", config.enableConfig).formatted(Formatting.GREEN), true);
return 1;
}
public static int executeGet(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerPlayerEntity entity = ctx.getSource().getPlayer();
ctx.getSource().sendFeedback(new LiteralText("showing config values").formatted(Formatting.GREEN), false);
entity.sendMessage(new LiteralText("the config droprate is currently set to " + config.configdroprate).formatted(Formatting.AQUA), false);
entity.sendMessage(new LiteralText("starting to read the items save list...").formatted(Formatting.AQUA), false);
ctx.getSource().sendFeedback(new TranslatableText("config.show").formatted(Formatting.GREEN), false);
entity.sendMessage(new TranslatableText("config.isSet", config.configdroprate).formatted(Formatting.AQUA), false);
entity.sendMessage(new TranslatableText("itemsavelist.read").formatted(Formatting.AQUA), false);
for (String item : config.itemsSavedList){
entity.sendMessage(new LiteralText(item).formatted(Formatting.AQUA), false);
}
entity.sendMessage(new LiteralText("starting to read the names save list...").formatted(Formatting.AQUA), false);
entity.sendMessage(new TranslatableText("namesavelist.read").formatted(Formatting.AQUA), false);
for (String name : config.namesSavedList){
entity.sendMessage(new LiteralText(name).formatted(Formatting.AQUA), false);
}
entity.sendMessage(new TranslatableText("vanishingenabled.show", config.disableVanishingCurse).formatted(Formatting.AQUA), false);
entity.sendMessage(new TranslatableText("bindingdisabled.show", config.disableBindingCurse).formatted(Formatting.AQUA), false);
entity.sendMessage(new TranslatableText("vanish.current", !config.disableVanishingCurse).formatted(Formatting.AQUA), false);
entity.sendMessage(new TranslatableText("binding.current", !config.disableBindingCurse).formatted(Formatting.AQUA), false);
return 1;
}
public static int executeEnchantEnable(String enchant, CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
Expand All @@ -118,7 +111,7 @@ public static int executeEnchantEnable(String enchant, CommandContext<ServerComm
throw new IllegalStateException("Unexpected value: " + enchant);
}
manager.save();
ctx.getSource().getPlayer().sendMessage(new LiteralText("disabled the effects of the " + enchant + " curse").formatted(Formatting.AQUA), false);
ctx.getSource().getPlayer().sendMessage(new TranslatableText("enchant.disable", enchant).formatted(Formatting.AQUA), false);
return 1;
}
public static int executeEnchantDisable(String enchant, CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
Expand All @@ -134,27 +127,28 @@ public static int executeEnchantDisable(String enchant, CommandContext<ServerCom
throw new IllegalStateException("Unexpected value: " + enchant);
}
manager.save();
ctx.getSource().getPlayer().sendMessage(new LiteralText("reenabled the effects of the " + enchant + " curse").formatted(Formatting.AQUA), false);
ctx.getSource().getPlayer().sendMessage(new TranslatableText("enchant.enable", enchant).formatted(Formatting.AQUA), false);
return 1;
}
public static int executeSummary(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
player.sendMessage(new LiteralText("----------------------------------------------------------------------------------------------------").formatted(Formatting.AQUA), false);
//TODO translateable
player.sendMessage(new LiteralText("-------------------------------------------------------------------------------------").formatted(Formatting.AQUA), false);
player.sendMessage(new LiteralText(" Configured Inventory's Summary/Help"), false);
player.sendMessage(new LiteralText("/inventory set (integer) - sets the inventory droprate (Sets the config value of \"configdroprate\"."), false);
player.sendMessage(new LiteralText("/inventory on/off - turns the mod on and off. Requires a restart to fully take effect (Sets the config value of \"enableconfig\")"), false);
player.sendMessage(new LiteralText("/inventory set (integer) - sets the inventory droprate "), false);
player.sendMessage(new LiteralText("/inventory on/off - turns the mod on and off"), false);
player.sendMessage(new LiteralText("/inventory get info - sends all the info about the config values of the mod back to the player"), false);
player.sendMessage(new LiteralText("/inventory get summary - sends this message to the player"), false);
player.sendMessage(new LiteralText("/inventory add item (item) - adds an item to the item save list. Makes it so the item will be saved no matter the config droprate"), false);
player.sendMessage(new LiteralText("/inventory add name (name) - adds an name to the name save list. If an item has a custom name and the name of the item is on the list, that item will be saved and never drop"), false);
player.sendMessage(new LiteralText("/inventory add item (item) - adds an item to the item save list."), false);
player.sendMessage(new LiteralText("/inventory add name (name) - adds an name to the name save list. "), false);
player.sendMessage(new LiteralText("/inventory remove item (item) - removes an item from the item save list"), false);
player.sendMessage(new LiteralText("/inventory remove name (name) - removes an item from the name save list"), false);
player.sendMessage(new LiteralText("/inventory disable vanishing - makes the vanishing curse ineffective and now they drop like normal"), false);
player.sendMessage(new LiteralText("/inventory disable binding - makes the binding curse ineffective and now items can move around the inventory freely"), false);
player.sendMessage(new LiteralText("/inventory disable binding - makes the binding curse ineffective"), false);
player.sendMessage(new LiteralText("/inventory enable binding - turns binding back on"), false);
player.sendMessage(new LiteralText("/inventory enable vanishing - turns vanishing back on"), false);
player.sendMessage(new LiteralText("/inventory help - also displays this message"), false);
player.sendMessage(new LiteralText("------------------------------------------------------------------------------------------------------").formatted(Formatting.AQUA), false);
player.sendMessage(new LiteralText("--------------------------------------------------------------------------------------").formatted(Formatting.AQUA), false);
player.sendMessage(new LiteralText("Issues ? : https://github.com/OverlordsIII/ConfiguredKeepInventory/issues"), false);
return 1;
}
Expand All @@ -178,11 +172,11 @@ public static int executeRemoveName(CommandContext<ServerCommandSource> ctx, Str
public static void remove(String string, CommandContext<ServerCommandSource> ctx, boolean itemorname){
if (itemorname){
config.itemsSavedList.remove(string);
ctx.getSource().sendFeedback(new LiteralText("removed item " + string + " from the item save list"), true);
ctx.getSource().sendFeedback(new TranslatableText("removed.item", string), true);
}
else{
config.namesSavedList.remove(string);
ctx.getSource().sendFeedback(new LiteralText("removed name " + string + " from the item save list"), true);
ctx.getSource().sendFeedback(new TranslatableText("removed.name", string), true);
}
manager.save();
}
Expand All @@ -191,19 +185,19 @@ public static void add(String string, CommandContext<ServerCommandSource> ctx, b
if (itemOrName ){
if (!config.itemsSavedList.contains(string)){
config.itemsSavedList.add(string);
ctx.getSource().sendFeedback(new LiteralText("added item " + string + " to the item save list"), true);
ctx.getSource().sendFeedback(new TranslatableText("added.item", string), true);
}
else{
ctx.getSource().sendFeedback(new LiteralText("the item list already contains said item!").formatted(Formatting.RED), false);
ctx.getSource().sendFeedback(new TranslatableText("add.error.item").formatted(Formatting.RED), false);
}
}
else{
if (!config.namesSavedList.contains(string)){
config.namesSavedList.add(string);
ctx.getSource().sendFeedback(new LiteralText("added name " + string + " to the name save list"), true);
ctx.getSource().sendFeedback(new TranslatableText("add.name", string), true);
}
else{
ctx.getSource().sendFeedback(new LiteralText("the name list already contains said name!").formatted(Formatting.RED), false);
ctx.getSource().sendFeedback(new TranslatableText("add.name.error").formatted(Formatting.RED), false);
}
}
manager.save();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.overlordsiii.mixin;



import io.github.overlordsiii.ConfiguredKeepInventory;
import io.github.overlordsiii.mixinterfaces.PlayerInventoryDuck;
import io.github.overlordsiii.mixinterfaces.PlayerInventoryExt;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
Expand All @@ -22,15 +21,24 @@
import java.util.List;

@Mixin(PlayerInventory.class)
public abstract class PlayerInventoryMixin implements PlayerInventoryDuck {
public abstract class PlayerInventoryMixin implements PlayerInventoryExt {

// public Item[] autosortItems = new Item[]{Objects.requireNonNull(this.player.world.getServer()).isHardcore() ? Items.TOTEM_OF_UNDYING : Items.GOLDEN_CARROT, };

@Shadow @Final private List<DefaultedList<ItemStack>> combinedInventory;

@Shadow @Final public PlayerEntity player;

@Shadow @Final public DefaultedList<ItemStack> offHand;

@Shadow public abstract ItemStack getStack(int slot);

@Shadow public abstract void setStack(int slot, ItemStack stack);

@Shadow @Final public DefaultedList<ItemStack> main;

@Shadow @Final public DefaultedList<ItemStack> armor;

@Redirect(method = "dropAll", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z"))
private boolean droredirect(Iterator iterator){
//redirect for vanilla behavior
Expand Down Expand Up @@ -78,14 +86,77 @@ else if (!ConfiguredKeepInventory.Config.namesSavedList.contains(stack.getName()
}
}

//coming soon
/**
* A method that sorts your offhand based on the stack, or a pregenerated list
* @param stack that you want sorted. Input null to auto sort
*/


@Override
public void sortOffHand(ItemStack stack) {

if (stack != null){
if (this.indexOf(stack) != -1){
int item = indexOf(stack);
ItemStack currentOffStack = this.offHand.get(0);
ItemStack wantedStack = this.main.get(item);
this.main.set(item, currentOffStack);
this.offHand.set(0, wantedStack);
}
else{
int slot = this.indexOfArmor(stack);
ItemStack currentOffHandStack = this.offHand.get(0);
ItemStack wantedStack = this.armor.get(slot);
this.armor.set(slot, currentOffHandStack);
this.offHand.set(0, wantedStack);
}
}
}



@Override

public void sortHotBar(DefaultedList<ItemStack> stack) {

}

/**
* this only searches on the main inventory
* @param stack wanted stack
* @return index of stack in the main slot
*/

@Override

public int indexOf(ItemStack stack) {
for (int i = 0; i < this.main.size(); i++){
ItemStack itemStack = this.main.get(i);
if (itemStack.isItemEqual(stack)){
return i;
}
}
return -1;
}

/**
* only searches armor inventory
* @param stack wanted stack
* @return index of the stack in armor slots
*/

@Override
public int indexOfArmor(ItemStack stack){
for (int i = 0; i < this.armor.size(); i++){
ItemStack stacker = this.armor.get(i);
if (stacker.isItemEqual(stack)){
return i;
}
}
return -1;
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;

public interface PlayerInventoryDuck {
public interface PlayerInventoryExt {
//TODO add sorting in 1.1
void sortOffHand(ItemStack stack);
void sortHotBar(DefaultedList<ItemStack> stack);
int indexOf(ItemStack stack);
int indexOfArmor(ItemStack stack);
}
16 changes: 15 additions & 1 deletion src/main/resources/assets/inventoryconfig/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{
"droprate.show": "The Current inventory droprate is set to %d",
"inventory.set": "Set the inventory droprate to %d"
"inventory.set": "Set the inventory droprate to %d",
"config.show": "Currently showing the inventory config...",
"config.isSet": "Config droprate set to %d percent",
"itemsavelist.read": "Reading items from the item save list...",
"namesavelist.read": "Reading names from the name save list...",
"vanish.current": "Vanishing curse is currently %s",
"binding.current": "Binding Curse is currently %s",
"enchant.disable": "Disabled the %s curse",
"enchant.enable": "Reenabled the %s curse",
"removed.name": "Removed the %s name from the name save list",
"removed.item": "Removed the %s item from the item save list",
"added.item": "Added the %s item to the item save list",
"add.error.item": "The Item save list already has that item!",
"add.name": "Added the %s name to the name save list",
"add.error.name": "The Name save list already has that name!"
}

0 comments on commit b9490e2

Please sign in to comment.