- 22
- 0
всем привет, делаю мод на версию майна 1.16.5, forge 36.1.0
Java:
package org.psinka.lololowka_mod.item;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ModExcavatorItem extends PickaxeItem {
private final int harvestLevel;
private final int maxUses;
private final float efficiency;
private final float attackDamage;
private final int enchantability;
public ModExcavatorItem(IItemTier tier, int attackDamageIn, int attackSpeedIn, float efficiency, float attackDamage, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
this.harvestLevel = 3;
this.efficiency = 8.0F;
this.attackDamage = 4.0F;
this.maxUses = 0;
this.enchantability = 1;
}
@Override
public boolean canHarvestBlock(net.minecraft.block.BlockState blockIn) {
return true;
}
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
if (!worldIn.isRemote()) {
PlayerEntity player = (PlayerEntity) entityLiving;
if (!player.isCreative()) {
int radius = 1; // Радиус копания 3x3
destroyBlocksInRadius(worldIn, player, pos, radius);
}
}
return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}
private void destroyBlocksInRadius(World worldIn, PlayerEntity player, BlockPos centerPos, int radius) {
for (int yOffset = -radius; yOffset <= radius; yOffset++) {
for (int xOffset = -radius; xOffset <= radius; xOffset++) {
for (int zOffset = -radius; zOffset <= radius; zOffset++) {
BlockPos targetPos = centerPos.add(xOffset, yOffset, zOffset);
BlockState targetState = worldIn.getBlockState(targetPos);
Block targetBlock = targetState.getBlock();
// Добавьте здесь блоки, которые вы хотите запретить на разрушение
// Пропускаем блоки, которые не должны быть разрушены
if (targetBlock == Blocks.BEDROCK || targetBlock == Blocks.END_PORTAL_FRAME) {
continue;
}
if (this.canHarvestBlock(targetState) && !worldIn.isAirBlock(targetPos)) {
worldIn.destroyBlock(targetPos, true, player);
}
}
}
}
}
}