Skip to content

Commit

Permalink
restore invertShift option
Browse files Browse the repository at this point in the history
  • Loading branch information
jaquadro committed Apr 12, 2021
1 parent 7942105 commit 1a30a1d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -454,14 +455,8 @@ public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, Player
IDrawer drawer = tileDrawers.getDrawer(slot);

ItemStack item;
//Map<String, PlayerConfigSetting<?>> configSettings = ConfigManager.serverPlayerConfigSettings.get(playerIn.getUniqueID());
boolean invertShift = false;
/*if (configSettings != null) {
PlayerConfigSetting<Boolean> setting = (PlayerConfigSetting<Boolean>) 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Runnable> 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<Boolean> invertShift;

public General(ForgeConfigSpec.Builder builder) {
builder.push("General");
List<String> test = new ArrayList<>();
test.add("minecraft:clay, minecraft:clay_ball, 4");

invertShift = builder
.define("invertShift", false);

builder.pop();
}
}
}

0 comments on commit 1a30a1d

Please sign in to comment.