diff --git a/src/main/java/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java b/src/main/java/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java index a3c63a5f9..ebbe97280 100644 --- a/src/main/java/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java +++ b/src/main/java/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java @@ -2,6 +2,7 @@ import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityDrawerGroup; import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityItemRepository; +import com.jaquadro.minecraft.storagedrawers.config.ClientConfig; import com.jaquadro.minecraft.storagedrawers.config.CommonConfig; import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry; import com.jaquadro.minecraft.storagedrawers.core.*; @@ -43,6 +44,7 @@ public StorageDrawers () { proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.spec); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModConfigEvent); @@ -80,7 +82,10 @@ private void clientSetup (final FMLClientSetupEvent event) { } private void onModConfigEvent(final ModConfig.ModConfigEvent event) { - CommonConfig.setLoaded(); + if (event.getConfig().getType() == ModConfig.Type.COMMON) + CommonConfig.setLoaded(); + if (event.getConfig().getType() == ModConfig.Type.CLIENT) + ClientConfig.setLoaded(); } @SubscribeEvent diff --git a/src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index 5ea2dc2fb..b5231bae6 100644 --- a/src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/main/java/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -5,6 +5,7 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers; import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityDrawerAttributes; +import com.jaquadro.minecraft.storagedrawers.config.ClientConfig; import com.jaquadro.minecraft.storagedrawers.config.CommonConfig; import com.jaquadro.minecraft.storagedrawers.core.ModItems; import com.jaquadro.minecraft.storagedrawers.inventory.ContainerDrawers1; @@ -216,7 +217,7 @@ public void onBlockPlacedBy (World world, BlockPos pos, BlockState state, Living // tile.setCustomName(stack.getDisplayName()); } - if (entity.getHeldItemOffhand().getItem() == ModItems.DRAWER_KEY) { + if (entity != null && entity.getHeldItemOffhand().getItem() == ModItems.DRAWER_KEY) { TileEntityDrawers tile = getTileEntity(world, pos); if (tile != null) { IDrawerAttributes _attrs = tile.getCapability(CapabilityDrawerAttributes.DRAWER_ATTRIBUTES_CAPABILITY).orElse(new EmptyDrawerAttributes()); @@ -454,14 +455,8 @@ public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, Player IDrawer drawer = tileDrawers.getDrawer(slot); ItemStack item; - //Map> configSettings = ConfigManager.serverPlayerConfigSettings.get(playerIn.getUniqueID()); - boolean invertShift = false; - /*if (configSettings != null) { - PlayerConfigSetting setting = (PlayerConfigSetting) configSettings.get("invertShift"); - if (setting != null) { - invertShift = setting.value; - } - }*/ + boolean invertShift = ClientConfig.GENERAL.invertShift.get(); + if (playerIn.isSneaking() != invertShift) item = tileDrawers.takeItemsFromSlot(slot, drawer.getStoredItemStackSize()); else diff --git a/src/main/java/com/jaquadro/minecraft/storagedrawers/config/ClientConfig.java b/src/main/java/com/jaquadro/minecraft/storagedrawers/config/ClientConfig.java new file mode 100644 index 000000000..9ec726025 --- /dev/null +++ b/src/main/java/com/jaquadro/minecraft/storagedrawers/config/ClientConfig.java @@ -0,0 +1,48 @@ +package com.jaquadro.minecraft.storagedrawers.config; + +import net.minecraftforge.common.ForgeConfigSpec; + +import java.util.ArrayList; +import java.util.List; + +public class ClientConfig +{ + private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); + public static final General GENERAL = new General(BUILDER); + public static final ForgeConfigSpec spec = BUILDER.build(); + + private static boolean loaded = false; + private static List loadActions = new ArrayList<>(); + + public static void setLoaded() { + if (!loaded) + loadActions.forEach(Runnable::run); + loaded = true; + } + + public static boolean isLoaded() { + return loaded; + } + + public static void onLoad(Runnable action) { + if (loaded) + action.run(); + else + loadActions.add(action); + } + + public static class General { + public final ForgeConfigSpec.ConfigValue invertShift; + + public General(ForgeConfigSpec.Builder builder) { + builder.push("General"); + List test = new ArrayList<>(); + test.add("minecraft:clay, minecraft:clay_ball, 4"); + + invertShift = builder + .define("invertShift", false); + + builder.pop(); + } + } +}