Fixed the Tools breaking on stripping and pathing and made the axe not capitate player placed logs
Signed-off-by: IM23a-cernik <cernik@bzz.ch>
This commit is contained in:
@@ -25,11 +25,11 @@ public class ModItems {
|
||||
|
||||
public static final DeferredItem<SwordItem> STALINIUM_SWORD = ITEMS.register("stalinium_sword",
|
||||
() -> new StaliniumSwordItem(ModTiers.STALINIUM, new Item.Properties()
|
||||
.attributes(SwordItem.createAttributes(ModTiers.STALINIUM, 3, -2.4f))));
|
||||
.attributes(SwordItem.createAttributes(ModTiers.STALINIUM, 3f, -2.4f))));
|
||||
|
||||
public static final DeferredItem<AxeItem> STALINIUM_AXE = ITEMS.register("stalinium_axe",
|
||||
() -> new StaliniumAxeItem(ModTiers.STALINIUM, new Item.Properties()
|
||||
.attributes(AxeItem.createAttributes(ModTiers.STALINIUM, 5, -3.0f))));
|
||||
.attributes(AxeItem.createAttributes(ModTiers.STALINIUM, 5f, -3.0f))));
|
||||
|
||||
public static final DeferredItem<ShovelItem> STALINIUM_SHOVEL = ITEMS.register("stalinium_shovel",
|
||||
() -> new StaliniumShovelItem(ModTiers.STALINIUM, new Item.Properties()
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package net.krituximon.stalinium.item;
|
||||
|
||||
import net.krituximon.stalinium.util.PlacedLogStorage;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
@@ -24,17 +28,21 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
cutDownTree(level, pos, (Player)miningEntity, stack);
|
||||
return true;
|
||||
}
|
||||
return super.mineBlock(stack, level, state, pos, miningEntity);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cutDownTree(Level level, BlockPos start, Player player, ItemStack stack) {
|
||||
Set<BlockPos> toBreak = new HashSet<>();
|
||||
Deque<BlockPos> queue = new ArrayDeque<>();
|
||||
queue.add(start);
|
||||
PlacedLogStorage storage = PlacedLogStorage.get((ServerLevel) level);
|
||||
|
||||
while (!queue.isEmpty() && toBreak.size() < 256) {
|
||||
BlockPos current = queue.removeFirst();
|
||||
if (toBreak.contains(current)) continue;
|
||||
BlockState bs = level.getBlockState(current);
|
||||
if (storage.contains(current)) continue;
|
||||
|
||||
if (bs.is(BlockTags.LOGS)) {
|
||||
toBreak.add(current);
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
@@ -57,7 +65,7 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,4 +77,13 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
public boolean isDamaged(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext ctx) {
|
||||
ItemStack stack = ctx.getItemInHand();
|
||||
int oldDamage = stack.getDamageValue();
|
||||
InteractionResult res = super.useOn(ctx);
|
||||
stack.setDamageValue(oldDamage);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.AxeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ShovelItem;
|
||||
import net.minecraft.world.item.Tier;
|
||||
@@ -15,6 +14,9 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
|
||||
public class StaliniumShovelItem extends ShovelItem {
|
||||
public StaliniumShovelItem(Tier tier, Properties properties) {
|
||||
super(tier, properties);
|
||||
@@ -27,9 +29,10 @@ public class StaliniumShovelItem extends ShovelItem {
|
||||
miningEntity.addEffect(haste);
|
||||
Level world = miningEntity.getCommandSenderWorld();
|
||||
var box = miningEntity.getBoundingBox().inflate(10.0);
|
||||
world.getEntitiesOfClass(LivingEntity.class, box, p -> p instanceof LivingEntity).forEach(
|
||||
p -> p.addEffect(haste)
|
||||
);
|
||||
List<Player> nearby = world.getEntitiesOfClass(Player.class, box, p -> p instanceof ServerPlayer && miningEntity.isAlliedTo(p));
|
||||
for (Player p : nearby) {
|
||||
p.addEffect(haste);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -46,6 +49,15 @@ public class StaliniumShovelItem extends ShovelItem {
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext ctx) {
|
||||
ItemStack stack = ctx.getItemInHand();
|
||||
int oldDamage = stack.getDamageValue();
|
||||
InteractionResult res = super.useOn(ctx);
|
||||
stack.setDamageValue(oldDamage);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class StaliniumSwordItem extends SwordItem {
|
||||
attacker.addEffect(strength);
|
||||
Level world = attacker.getCommandSenderWorld();
|
||||
var box = attacker.getBoundingBox().inflate(5.0);
|
||||
List<Player> nearby = world.getEntitiesOfClass(Player.class, box, p -> p instanceof ServerPlayer);
|
||||
List<Player> nearby = world.getEntitiesOfClass(Player.class, box, p -> p instanceof ServerPlayer && attacker.isAlliedTo(p));
|
||||
for (Player p : nearby) {
|
||||
p.addEffect(strength);
|
||||
}
|
||||
@@ -43,6 +43,11 @@ public class StaliniumSwordItem extends SwordItem {
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user