generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
handRestockListType
, handRestockWhiteList
, `handRestockBlac…
…kList`
- Loading branch information
1 parent
1d82a30
commit c4665b3
Showing
9 changed files
with
212 additions
and
2 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
19 changes: 19 additions & 0 deletions
19
src/main/java/me/fallenbreath/tweakermore/config/TweakerMoreConfigs.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 |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package me.fallenbreath.tweakermore.config; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed; | ||
import fi.dy.masa.malilib.config.options.ConfigDouble; | ||
import fi.dy.masa.malilib.config.options.ConfigOptionList; | ||
import fi.dy.masa.malilib.config.options.ConfigStringList; | ||
import fi.dy.masa.malilib.util.restrictions.ItemRestriction; | ||
import fi.dy.masa.malilib.util.restrictions.UsageRestriction; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class TweakerMoreConfigs | ||
{ | ||
// Generic | ||
public static final ConfigDouble NETHER_PORTAL_SOUND_CHANCE = new ConfigDouble("netherPortalSoundChance", 0.01D, 0.0D, 0.01D, "The chance for a nether portal block to play sound\nSet it to 0.001 or 0.0001 for less noisy portal"); | ||
|
||
// List | ||
public static final ConfigOptionList HAND_RESTORE_LIST_TYPE = new ConfigOptionList("handRestockListType", UsageRestriction.ListType.NONE, "The item restriction type for tweakHandRestock"); | ||
public static final ConfigStringList HAND_RESTORE_WHITELIST = new ConfigStringList("handRestockWhiteList", ImmutableList.of(getItemId(Items.BUCKET)), "The items that will trigger tweakHandRestock"); | ||
public static final ConfigStringList HAND_RESTORE_BLACKLIST = new ConfigStringList("handRestockBlackList", ImmutableList.of(getItemId(Items.LAVA_BUCKET)), "The items that will NOT trigger tweakHandRestock"); | ||
public static final ItemRestriction HAND_RESTORE_RESTRICTION = new ItemRestriction(); | ||
|
||
private static String getItemId(Item item) | ||
{ | ||
return Registry.ITEM.getId(item).toString(); | ||
} | ||
|
||
// Disable | ||
public static final ConfigBooleanHotkeyed DISABLE_LIGHT_UPDATES = new ConfigBooleanHotkeyed("disableLightUpdates", false, "", "Yeets client-side light updates"); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/me/fallenbreath/tweakermore/mixins/core/ConfigsMixin.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,21 @@ | ||
package me.fallenbreath.tweakermore.mixins.core; | ||
|
||
import fi.dy.masa.malilib.util.restrictions.UsageRestriction; | ||
import fi.dy.masa.tweakeroo.config.Configs; | ||
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Configs.class) | ||
public class ConfigsMixin | ||
{ | ||
@Inject(method = "loadFromFile", at = @At("TAIL"), remap = false) | ||
private static void buildRestrictionLists(CallbackInfo ci) | ||
{ | ||
|
||
TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.setListType((UsageRestriction.ListType)TweakerMoreConfigs.HAND_RESTORE_LIST_TYPE.getOptionListValue()); | ||
TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.setListContents(TweakerMoreConfigs.HAND_RESTORE_BLACKLIST.getStrings(), TweakerMoreConfigs.HAND_RESTORE_WHITELIST.getStrings()); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/me/fallenbreath/tweakermore/mixins/core/ListsConfigsMixin.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,29 @@ | ||
package me.fallenbreath.tweakermore.mixins.core; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Lists; | ||
import fi.dy.masa.malilib.config.IConfigBase; | ||
import fi.dy.masa.tweakeroo.config.Configs; | ||
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(Configs.Lists.class) | ||
public abstract class ListsConfigsMixin | ||
{ | ||
@Mutable | ||
@Shadow(remap = false) @Final public static ImmutableList<IConfigBase> OPTIONS; | ||
|
||
static | ||
{ | ||
List<IConfigBase> optionList = Lists.newArrayList(OPTIONS); | ||
optionList.add(TweakerMoreConfigs.HAND_RESTORE_LIST_TYPE); | ||
optionList.add(TweakerMoreConfigs.HAND_RESTORE_BLACKLIST); | ||
optionList.add(TweakerMoreConfigs.HAND_RESTORE_WHITELIST); | ||
OPTIONS = ImmutableList.copyOf(optionList); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...n/java/me/fallenbreath/tweakermore/mixins/handRestoreRestriction/InventoryUtilsMixin.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,40 @@ | ||
package me.fallenbreath.tweakermore.mixins.handRestoreRestriction; | ||
|
||
import fi.dy.masa.tweakeroo.config.FeatureToggle; | ||
import fi.dy.masa.tweakeroo.util.InventoryUtils; | ||
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.util.Hand; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
|
||
@Mixin(InventoryUtils.class) | ||
public abstract class InventoryUtilsMixin | ||
{ | ||
|
||
@Redirect( | ||
method = "preRestockHand", | ||
slice = @Slice( | ||
from = @At( | ||
value = "FIELD", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;", | ||
remap = false | ||
) | ||
), | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z", | ||
ordinal = 0, | ||
remap = false | ||
), | ||
remap = false | ||
) | ||
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand, boolean allowHotbar) | ||
{ | ||
Item currentItem = player.getStackInHand(hand).getItem(); | ||
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
.../java/me/fallenbreath/tweakermore/mixins/handRestoreRestriction/PlacementTweaksMixin.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,92 @@ | ||
package me.fallenbreath.tweakermore.mixins.handRestoreRestriction; | ||
|
||
import fi.dy.masa.tweakeroo.config.FeatureToggle; | ||
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks; | ||
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Hand; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
|
||
@Mixin(PlacementTweaks.class) | ||
public abstract class PlacementTweaksMixin | ||
{ | ||
@Redirect( | ||
method = "onProcessRightClickPre", | ||
slice = @Slice( | ||
from = @At( | ||
value = "FIELD", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;", | ||
remap = false | ||
) | ||
), | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z", | ||
ordinal = 0, | ||
remap = false | ||
), | ||
remap = false | ||
) | ||
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand) | ||
{ | ||
Item currentItem = player.getStackInHand(hand).getItem(); | ||
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem); | ||
} | ||
|
||
@Redirect( | ||
method = "cacheStackInHand", | ||
slice = @Slice( | ||
from = @At( | ||
value = "FIELD", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;", | ||
remap = false | ||
) | ||
), | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z", | ||
ordinal = 0, | ||
remap = false | ||
), | ||
remap = false | ||
) | ||
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ Hand hand) | ||
{ | ||
boolean result = featureToggle.getBooleanValue(); | ||
PlayerEntity player = MinecraftClient.getInstance().player; | ||
if (player != null) | ||
{ | ||
Item currentItem = player.getStackInHand(hand).getItem(); | ||
result &= TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem); | ||
} | ||
return result; | ||
} | ||
|
||
@Redirect( | ||
method = "tryRestockHand", | ||
slice = @Slice( | ||
from = @At( | ||
value = "FIELD", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;", | ||
remap = false | ||
) | ||
), | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z", | ||
ordinal = 0, | ||
remap = false | ||
), | ||
remap = false | ||
) | ||
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand, ItemStack stackOriginal) | ||
{ | ||
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(stackOriginal.getItem()); | ||
} | ||
} |
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