Compare commits

..

No commits in common. "336795421d328a2e4d0946592f85d21c5c10cc91" and "c1797eb14b33803c76e0665c244c4a825711e114" have entirely different histories.

22 changed files with 34 additions and 111 deletions

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/depth_pickaxe"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_axe"
}
}

View file

@ -359,17 +359,4 @@ 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;
}
} }

View file

@ -33,7 +33,7 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
var key = NaturesAura.MOD_ID + ":field_creator_pos"; var key = NaturesAura.MOD_ID + ":field_creator_pos";
var compound = player.getPersistentData(); var compound = player.getPersistentData();
if (!player.isShiftKeyDown() && compound.contains(key)) { if (!player.isCrouching() && compound.contains(key)) {
var stored = BlockPos.of(compound.getLong(key)); var stored = BlockPos.of(compound.getLong(key));
var creator = (BlockEntityFieldCreator) tile; var creator = (BlockEntityFieldCreator) tile;
if (!pos.equals(stored)) { if (!pos.equals(stored)) {

View file

@ -88,7 +88,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!player.isShiftKeyDown()) if (!player.isCrouching())
return InteractionResult.FAIL; return InteractionResult.FAIL;
var tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityGratedChute chute)) if (!(tile instanceof BlockEntityGratedChute chute))

View file

@ -21,7 +21,7 @@ public class BlockItemDistributor extends BlockContainerImpl implements ICustomB
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!player.isShiftKeyDown()) if (!player.isCrouching())
return InteractionResult.FAIL; return InteractionResult.FAIL;
var tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityItemDistributor)) if (!(tile instanceof BlockEntityItemDistributor))

View file

@ -29,7 +29,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@SubscribeEvent @SubscribeEvent
public void onPickup(EntityItemPickupEvent event) { public void onPickup(EntityItemPickupEvent event) {
var player = event.getEntity(); var player = event.getEntity();
if (player != null && !player.isShiftKeyDown()) { if (player != null && !player.isCrouching()) {
var item = event.getItem(); var item = event.getItem();
var pos = item.blockPosition(); var pos = item.blockPosition();
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> { Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {

View file

@ -41,7 +41,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
@Override @Override
public void inventoryTick(ItemStack stackIn, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) { public void inventoryTick(ItemStack stackIn, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (!levelIn.isClientSide && entityIn instanceof Player player) { if (!levelIn.isClientSide && entityIn instanceof Player player) {
if (player.isShiftKeyDown() && stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) { if (player.isCrouching() && stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent()) {
var container = stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); var container = stackIn.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null);
if (container.getStoredAura() <= 0) { if (container.getStoredAura() <= 0) {
return; return;

View file

@ -35,7 +35,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
var color = DyeColor.byId(blocks.indexOf(block)); var color = DyeColor.byId(blocks.indexOf(block));
if (firstColor == null || color == firstColor) { if (firstColor == null || color == firstColor) {
var stored = ItemColorChanger.getStoredColor(stack); var stored = ItemColorChanger.getStoredColor(stack);
if (player.isShiftKeyDown()) { if (player.isCrouching()) {
if (stored != color) { if (stored != color) {
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F); SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F);
@ -105,7 +105,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
@Override @Override
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) { public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
var stack = playerIn.getItemInHand(handIn); var stack = playerIn.getItemInHand(handIn);
if (playerIn.isShiftKeyDown() && ItemColorChanger.getStoredColor(stack) != null) { if (playerIn.isCrouching() && ItemColorChanger.getStoredColor(stack) != null) {
levelIn.playSound(playerIn, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.BUCKET_FILL_LAVA, SoundSource.PLAYERS, 0.65F, 1F); levelIn.playSound(playerIn, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.BUCKET_FILL_LAVA, SoundSource.PLAYERS, 0.65F, 1F);
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
ItemColorChanger.setFillMode(stack, !ItemColorChanger.isFillMode(stack)); ItemColorChanger.setFillMode(stack, !ItemColorChanger.isFillMode(stack));

View file

@ -52,7 +52,7 @@ public class ItemRangeVisualizer extends ItemImpl {
@Override @Override
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) { public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
var stack = playerIn.getItemInHand(handIn); var stack = playerIn.getItemInHand(handIn);
if (playerIn.isShiftKeyDown()) { if (playerIn.isCrouching()) {
ItemRangeVisualizer.clear(); ItemRangeVisualizer.clear();
playerIn.displayClientMessage(Component.translatable("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true); playerIn.displayClientMessage(Component.translatable("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack); return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);

View file

@ -55,7 +55,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
compound.putBoolean("air", false); compound.putBoolean("air", false);
if (!living.isShiftKeyDown()) if (!living.isCrouching())
return; return;
if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F) if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
return; return;

View file

@ -11,13 +11,10 @@ import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.BlockTags; 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.entity.player.Player;
import net.minecraft.world.item.AxeItem; import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; 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.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
@ -49,22 +46,14 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
} }
@Override @Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) { public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
if (stack.getItem() == ModItems.SKY_AXE && Helper.isToolEnabled(stack) && player.level.getBlockState(pos).is(BlockTags.LOGS)) { if (itemstack.getItem() == ModItems.SKY_AXE && !player.isShiftKeyDown() && player.level.getBlockState(pos).is(BlockTags.LOGS)) {
BlockEntityWoodStand.recurseTreeDestruction(player.level, pos, pos, false, true); BlockEntityWoodStand.recurseTreeDestruction(player.level, pos, pos, false, true);
return true; return true;
} }
return false; 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 @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
@ -73,8 +62,6 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@Override @Override
public void generateCustomItemModel(ItemModelGenerator generator) { public void generateCustomItemModel(ItemModelGenerator generator) {
if (this == ModItems.SKY_AXE)
return;
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName()); generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
} }

View file

@ -17,10 +17,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BushBlock; import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
@ -71,7 +68,7 @@ public class ItemHoe extends HoeItem implements IModItem, ICustomItemModel {
var offset = context.getClickedPos().offset(x, 0, z); var offset = context.getClickedPos().offset(x, 0, z);
var newResult = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), offset, context.isInside()); var newResult = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), offset, context.isInside());
var newContext = new UseOnContext(context.getPlayer(), context.getHand(), newResult); var newContext = new UseOnContext(context.getPlayer(), context.getHand(), newResult);
success |= super.useOn(newContext).consumesAction(); success |= super.useOn(newContext) == InteractionResult.SUCCESS;
} }
} }
return success ? InteractionResult.SUCCESS : InteractionResult.PASS; return success ? InteractionResult.SUCCESS : InteractionResult.PASS;
@ -81,9 +78,8 @@ public class ItemHoe extends HoeItem implements IModItem, ICustomItemModel {
@Override @Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) { public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
if (!player.isShiftKeyDown() && (stack.getItem() == ModItems.SKY_HOE || stack.getItem() == ModItems.DEPTH_HOE)) { if (stack.getItem() == ModItems.SKY_HOE) {
var block = player.level.getBlockState(pos).getBlock(); if (!(player.level.getBlockState(pos).getBlock() instanceof BushBlock))
if (!(block instanceof BushBlock) && (stack.getItem() != ModItems.DEPTH_HOE || !(block instanceof LeavesBlock)))
return false; return false;
if (!player.level.isClientSide) { if (!player.level.isClientSide) {
var range = 3; var range = 3;
@ -93,12 +89,9 @@ public class ItemHoe extends HoeItem implements IModItem, ICustomItemModel {
if (x == 0 && y == 0 && z == 0) if (x == 0 && y == 0 && z == 0)
continue; continue;
var offset = pos.offset(x, y, z); var offset = pos.offset(x, y, z);
var offState = player.level.getBlockState(offset); var otherState = player.level.getBlockState(offset);
if (offState.getBlock() instanceof BushBlock || stack.getItem() == ModItems.DEPTH_HOE && offState.getBlock() instanceof LeavesBlock) { if (otherState.getBlock() instanceof BushBlock)
var entity = offState.hasBlockEntity() ? player.level.getBlockEntity(offset) : null; player.level.destroyBlock(offset, true);
Block.dropResources(offState, player.level, offset, entity, null, ItemStack.EMPTY);
player.level.setBlock(offset, Blocks.AIR.defaultBlockState(), 3);
}
} }
} }
} }

View file

@ -14,9 +14,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -28,6 +26,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -90,21 +89,13 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
@Override @Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) { public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && Helper.isToolEnabled(itemstack) && player.level.getBlockState(pos).is(Tags.Blocks.ORES)) { if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && !player.isShiftKeyDown() && player.level.getBlockState(pos).is(Tags.Blocks.ORES)) {
Helper.mineRecursively(player.level, pos, pos, true, 5, 5, s -> s.is(Tags.Blocks.ORES)); Helper.mineRecursively(player.level, pos, pos, true, 5, 5, s -> s.is(Tags.Blocks.ORES));
return true; return true;
} }
return false; 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 @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
@ -113,8 +104,6 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
@Override @Override
public void generateCustomItemModel(ItemModelGenerator generator) { public void generateCustomItemModel(ItemModelGenerator generator) {
if (this == ModItems.DEPTH_PICKAXE)
return;
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName()); generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
} }

View file

@ -51,7 +51,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
damage = 5; damage = 5;
} }
} else { } else {
var range = player.isShiftKeyDown() ? 0 : 1; var range = player.isCrouching() ? 0 : 1;
for (var x = -range; x <= range; x++) { for (var x = -range; x <= range; x++) {
for (var y = -range; y <= range; y++) { for (var y = -range; y <= range; y++) {
var actualPos = pos.offset(x, 0, y); var actualPos = pos.offset(x, 0, y);

View file

@ -1,6 +1,5 @@
package de.ellpeck.naturesaura.proxy; package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
@ -46,13 +45,9 @@ public class ClientProxy implements IProxy {
MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new); MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new);
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"), ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"),
(stack, level, entity, i) -> ItemColorChanger.isFillMode(stack) ? 1 : 0); (stack, levelIn, entityIn, i) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F);
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"), ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"),
(stack, level, entity, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1 : 0); (stack, levelIn, entityIn, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F);
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 @Override

View file

@ -1,14 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/depth_pickaxe"
},
"overrides": [
{
"predicate": {
"naturesaura:enabled": 1
},
"model": "naturesaura:item/depth_pickaxe_enabled"
}
]
}

View file

@ -1,6 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/depth_pickaxe_enabled"
}
}

View file

@ -1,14 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_axe"
},
"overrides": [
{
"predicate": {
"naturesaura:enabled": 1
},
"model": "naturesaura:item/sky_axe_enabled"
}
]
}

View file

@ -1,6 +0,0 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_axe_enabled"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 B