Compare commits

...

3 commits

Author SHA1 Message Date
Ell
06a6b7f0fb i thought i was being clear 2023-02-28 14:36:46 +01:00
Ell
764e662c2d added depth sword ability 2023-02-28 14:30:19 +01:00
Ell
43c8976298 added depth axe ability 2023-02-28 14:00:57 +01:00
13 changed files with 69 additions and 29 deletions

View file

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

View file

@ -340,25 +340,28 @@ public final class Helper {
public static void mineRecursively(Level level, BlockPos pos, BlockPos start, boolean drop, int horizontalRange, int verticalRange, Predicate<BlockState> filter) {
if (Math.abs(pos.getX() - start.getX()) >= horizontalRange || Math.abs(pos.getZ() - start.getZ()) >= horizontalRange || Math.abs(pos.getY() - start.getY()) >= verticalRange)
return;
if (drop) {
level.destroyBlock(pos, true);
} else {
// in this case we don't want the block breaking particles, so we can't use destroyBlock
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.TR_DISAPPEAR));
}
for (var x = -1; x <= 1; x++) {
for (var y = -1; y <= 1; y++) {
for (var z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0)
continue;
var offset = pos.offset(x, y, z);
var state = level.getBlockState(offset);
if (filter.test(state)) {
if (drop) {
level.destroyBlock(offset, true);
} else {
// in this case we don't want the block breaking particles, so we can't use destroyBlock
level.setBlockAndUpdate(offset, Blocks.AIR.defaultBlockState());
PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.TR_DISAPPEAR));
}
if (filter.test(state))
Helper.mineRecursively(level, offset, start, drop, horizontalRange, verticalRange, filter);
}
}
}
}
}
public static boolean isToolEnabled(ItemStack stack) {
return stack.hasTag() && !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":disabled");

View file

@ -81,7 +81,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true;
});
BlockEntityWoodStand.recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false);
Helper.mineRecursively(this.level, this.ritualPos, this.ritualPos, false, 6, 32, s -> s.is(BlockTags.LOGS) || s.getBlock() instanceof LeavesBlock);
var item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
@ -122,10 +122,6 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
}
public static void recurseTreeDestruction(Level level, BlockPos pos, BlockPos start, boolean includeLeaves, boolean drop) {
Helper.mineRecursively(level, pos, start, drop, 6, 32, s -> s.is(BlockTags.LOGS) || includeLeaves && s.getBlock() instanceof LeavesBlock);
}
private boolean isRitualOkay() {
if (!Multiblocks.TREE_RITUAL.isComplete(this.level, this.ritualPos)) {
return false;

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.items.tools;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomItemModel;
@ -50,8 +49,9 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@Override
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);
if ((stack.getItem() == ModItems.SKY_AXE || stack.getItem() == ModItems.DEPTH_AXE) && Helper.isToolEnabled(stack) && player.level.getBlockState(pos).is(BlockTags.LOGS)) {
var horRange = stack.getItem() == ModItems.DEPTH_AXE ? 6 : 1;
Helper.mineRecursively(player.level, pos, pos, true, horRange, 32, s -> s.is(BlockTags.LOGS));
return true;
}
return false;
@ -60,7 +60,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@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))
if ((stack.getItem() == ModItems.SKY_AXE || stack.getItem() == ModItems.DEPTH_AXE) && Helper.toggleToolEnabled(player, stack))
return InteractionResultHolder.success(stack);
return super.use(level, player, hand);
}
@ -73,7 +73,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@Override
public void generateCustomItemModel(ItemModelGenerator generator) {
if (this == ModItems.SKY_AXE)
if (this == ModItems.SKY_AXE || this == ModItems.DEPTH_AXE)
return;
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
}

View file

@ -74,6 +74,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
stack.hurtAndBreak(damage, player, p -> p.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
} else if (this == ModItems.SKY_SHOVEL) {
if (this.getDestroySpeed(stack, state) <= 1)
return super.useOn(context);
@ -89,7 +90,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
return super.useOn(context);
}
@Override

View file

@ -8,13 +8,21 @@ import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
@ -39,10 +47,28 @@ public class ItemSword extends SwordItem implements IModItem, ICustomItemModel {
target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 60, 2));
} else if (this == ModItems.SKY_SWORD) {
target.addEffect(new MobEffectInstance(MobEffects.LEVITATION, 60, 2));
} else if (this == ModItems.DEPTH_SWORD && attacker instanceof Player player) {
// this is just a modified copy of Player.attack's sweeping damage code
var damage = (float) player.getAttributeValue(Attributes.ATTACK_DAMAGE) * 0.75F;
for (var other : player.level.getEntitiesOfClass(LivingEntity.class, stack.getSweepHitBox(player, target))) {
if (other != player && other != target && !player.isAlliedTo(other) && (!(other instanceof ArmorStand stand) || !stand.isMarker()) && player.canHit(other, 0)) {
other.knockback(0.4F, Mth.sin(player.getYRot() * (Mth.PI / 180)), -Mth.cos(player.getYRot() * (Mth.PI / 180)));
other.hurt(DamageSource.playerAttack(player), damage);
}
}
// this just displays the particles
player.sweepAttack();
}
return super.hurtEnemy(stack, target, attacker);
}
@Override
public @NotNull AABB getSweepHitBox(@NotNull ItemStack stack, @NotNull Player player, @NotNull Entity target) {
if (this == ModItems.DEPTH_SWORD)
return target.getBoundingBox().inflate(2, 1, 2);
return super.getSweepHitBox(stack, player, target);
}
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {

View file

@ -49,7 +49,7 @@ public class ClientProxy implements IProxy {
(stack, level, entity, i) -> ItemColorChanger.isFillMode(stack) ? 1 : 0);
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"),
(stack, level, entity, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1 : 0);
for (var item : new Item[]{ModItems.SKY_AXE, ModItems.DEPTH_PICKAXE}) {
for (var item : new Item[]{ModItems.SKY_AXE, ModItems.DEPTH_PICKAXE, ModItems.DEPTH_AXE}) {
ItemProperties.register(item, new ResourceLocation(NaturesAura.MOD_ID, "enabled"),
(stack, level, entity, i) -> Helper.isToolEnabled(stack) ? 1 : 0);
}

View file

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

View file

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

View file

@ -15,7 +15,7 @@
},
{
"type": "crafting",
"text": "The $(item)Skyseeker's Handaxe$() is very efficient at chopping $(thing)trees$(), doing so in one fell swoop.",
"text": "The $(item)Skyseeker's Handaxe$() is very efficient at chopping $(thing)small trees$(), doing so in one fell swoop.",
"recipe": "naturesaura:sky_axe"
},
{

View file

@ -28,7 +28,7 @@
"type": "spotlight",
"item": "naturesaura:vacuum_bottle",
"link_recipe": true,
"text": "Lastly, some areas have a severe lack of $(aura), much lower than the $(l:items/eye)Environmental Eye$() can display, and whose air is subsequently nearly devoid of oxygen. Using a $(item)Bottle and Cork$() in areas like these allows bottling up this air and capturing a nearly perfect vacuum in the bottle."
"text": "Lastly, some areas have a severe lack of $(aura), much lower than the $(l:items/eye)Environmental Eye$() can display, and whose air is subsequently nearly devoid of oxygen. Using a $(item)Bottle and Cork$() in areas like these allows bottling up this air and capturing a nearly perfect $(aura) vacuum in the bottle."
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 B

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 B