mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-05 20:59:09 +01:00
switch to a mode toggle for tool abilities
This commit is contained in:
parent
c1797eb14b
commit
f565a02561
21 changed files with 98 additions and 28 deletions
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/depth_pickaxe"
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/sky_axe"
|
||||
}
|
||||
}
|
|
@ -359,4 +359,17 @@ public final class Helper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isToolEnabled(ItemStack stack) {
|
||||
return stack.hasTag() && !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":disabled");
|
||||
}
|
||||
|
||||
public static boolean toggleToolEnabled(Player player, ItemStack stack) {
|
||||
if (!player.isShiftKeyDown())
|
||||
return false;
|
||||
var disabled = !Helper.isToolEnabled(stack);
|
||||
stack.getOrCreateTag().putBoolean(NaturesAura.MOD_ID + ":disabled", !disabled);
|
||||
player.level.playSound(null, player.getX() + 0.5, player.getY() + 0.5, player.getZ() + 0.5, SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
|
|||
if (!levelIn.isClientSide) {
|
||||
var key = NaturesAura.MOD_ID + ":field_creator_pos";
|
||||
var compound = player.getPersistentData();
|
||||
if (!player.isCrouching() && compound.contains(key)) {
|
||||
if (!player.isShiftKeyDown() && compound.contains(key)) {
|
||||
var stored = BlockPos.of(compound.getLong(key));
|
||||
var creator = (BlockEntityFieldCreator) tile;
|
||||
if (!pos.equals(stored)) {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
|
|||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
|
||||
if (!player.isCrouching())
|
||||
if (!player.isShiftKeyDown())
|
||||
return InteractionResult.FAIL;
|
||||
var tile = levelIn.getBlockEntity(pos);
|
||||
if (!(tile instanceof BlockEntityGratedChute chute))
|
||||
|
|
|
@ -21,7 +21,7 @@ public class BlockItemDistributor extends BlockContainerImpl implements ICustomB
|
|||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
|
||||
if (!player.isCrouching())
|
||||
if (!player.isShiftKeyDown())
|
||||
return InteractionResult.FAIL;
|
||||
var tile = levelIn.getBlockEntity(pos);
|
||||
if (!(tile instanceof BlockEntityItemDistributor))
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
|
|||
@SubscribeEvent
|
||||
public void onPickup(EntityItemPickupEvent event) {
|
||||
var player = event.getEntity();
|
||||
if (player != null && !player.isCrouching()) {
|
||||
if (player != null && !player.isShiftKeyDown()) {
|
||||
var item = event.getItem();
|
||||
var pos = item.blockPosition();
|
||||
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
|
|||
@Override
|
||||
public void inventoryTick(ItemStack stackIn, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
||||
if (!levelIn.isClientSide && entityIn instanceof Player player) {
|
||||
if (player.isCrouching() && stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) {
|
||||
if (player.isShiftKeyDown() && stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) {
|
||||
var container = stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null);
|
||||
if (container.getStoredAura() <= 0) {
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
var color = DyeColor.byId(blocks.indexOf(block));
|
||||
if (firstColor == null || color == firstColor) {
|
||||
var stored = ItemColorChanger.getStoredColor(stack);
|
||||
if (player.isCrouching()) {
|
||||
if (player.isShiftKeyDown()) {
|
||||
if (stored != color) {
|
||||
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
|
@ -105,7 +105,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
|
||||
var stack = playerIn.getItemInHand(handIn);
|
||||
if (playerIn.isCrouching() && ItemColorChanger.getStoredColor(stack) != null) {
|
||||
if (playerIn.isShiftKeyDown() && ItemColorChanger.getStoredColor(stack) != null) {
|
||||
levelIn.playSound(playerIn, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.BUCKET_FILL_LAVA, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
if (!levelIn.isClientSide) {
|
||||
ItemColorChanger.setFillMode(stack, !ItemColorChanger.isFillMode(stack));
|
||||
|
|
|
@ -52,7 +52,7 @@ public class ItemRangeVisualizer extends ItemImpl {
|
|||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
|
||||
var stack = playerIn.getItemInHand(handIn);
|
||||
if (playerIn.isCrouching()) {
|
||||
if (playerIn.isShiftKeyDown()) {
|
||||
ItemRangeVisualizer.clear();
|
||||
playerIn.displayClientMessage(Component.translatable("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true);
|
||||
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
|
|||
|
||||
compound.putBoolean("air", false);
|
||||
|
||||
if (!living.isCrouching())
|
||||
if (!living.isShiftKeyDown())
|
||||
return;
|
||||
if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
|
||||
return;
|
||||
|
|
|
@ -11,10 +11,13 @@ import de.ellpeck.naturesaura.reg.ModRegistry;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.AxeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
|
@ -46,14 +49,22 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
|
||||
if (itemstack.getItem() == ModItems.SKY_AXE && !player.isShiftKeyDown() && player.level.getBlockState(pos).is(BlockTags.LOGS)) {
|
||||
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
|
||||
if (stack.getItem() == ModItems.SKY_AXE && Helper.isToolEnabled(stack) && player.level.getBlockState(pos).is(BlockTags.LOGS)) {
|
||||
BlockEntityWoodStand.recurseTreeDestruction(player.level, pos, pos, false, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
var stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() == ModItems.SKY_AXE && Helper.toggleToolEnabled(player, stack))
|
||||
return InteractionResultHolder.success(stack);
|
||||
return super.use(level, player, hand);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
|
@ -62,6 +73,8 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
|
|||
|
||||
@Override
|
||||
public void generateCustomItemModel(ItemModelGenerator generator) {
|
||||
if (this == ModItems.SKY_AXE)
|
||||
return;
|
||||
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -26,7 +28,6 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -89,13 +90,21 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
|
|||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
|
||||
if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && !player.isShiftKeyDown() && player.level.getBlockState(pos).is(Tags.Blocks.ORES)) {
|
||||
if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && Helper.isToolEnabled(itemstack) && player.level.getBlockState(pos).is(Tags.Blocks.ORES)) {
|
||||
Helper.mineRecursively(player.level, pos, pos, true, 5, 5, s -> s.is(Tags.Blocks.ORES));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
var stack = player.getItemInHand(hand);
|
||||
if (stack.getItem() == ModItems.DEPTH_PICKAXE && Helper.toggleToolEnabled(player, stack))
|
||||
return InteractionResultHolder.success(stack);
|
||||
return super.use(level, player, hand);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
|
@ -104,6 +113,8 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
|
|||
|
||||
@Override
|
||||
public void generateCustomItemModel(ItemModelGenerator generator) {
|
||||
if (this == ModItems.DEPTH_PICKAXE)
|
||||
return;
|
||||
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
|
|||
damage = 5;
|
||||
}
|
||||
} else {
|
||||
var range = player.isCrouching() ? 0 : 1;
|
||||
var range = player.isShiftKeyDown() ? 0 : 1;
|
||||
for (var x = -range; x <= range; x++) {
|
||||
for (var y = -range; y <= range; y++) {
|
||||
var actualPos = pos.offset(x, 0, y);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura.proxy;
|
||||
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.blocks.ModBlocks;
|
||||
import de.ellpeck.naturesaura.compat.Compat;
|
||||
|
@ -45,9 +46,13 @@ public class ClientProxy implements IProxy {
|
|||
MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new);
|
||||
|
||||
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"),
|
||||
(stack, levelIn, entityIn, i) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F);
|
||||
(stack, level, entity, i) -> ItemColorChanger.isFillMode(stack) ? 1 : 0);
|
||||
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"),
|
||||
(stack, levelIn, entityIn, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F);
|
||||
(stack, level, entity, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1 : 0);
|
||||
for (var item : new Item[]{ModItems.SKY_AXE, ModItems.DEPTH_PICKAXE}) {
|
||||
ItemProperties.register(item, new ResourceLocation(NaturesAura.MOD_ID, "enabled"),
|
||||
(stack, level, entity, i) -> Helper.isToolEnabled(stack) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/depth_pickaxe"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"naturesaura:enabled": 1
|
||||
},
|
||||
"model": "naturesaura:item/depth_pickaxe_enabled"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/depth_pickaxe_enabled"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/sky_axe"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"naturesaura:enabled": 1
|
||||
},
|
||||
"model": "naturesaura:item/sky_axe_enabled"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/sky_axe_enabled"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 577 B |
Binary file not shown.
After Width: | Height: | Size: 532 B |
Loading…
Reference in a new issue