Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed Anvil-Dev#879
让电荷收集器有5x5x5的电网范围
为电荷收集器添加范围框
  • Loading branch information
ZhuRuoLing committed Jun 11, 2024
1 parent ae6d016 commit 8348e80
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void neighborChanged(
* @param devourerDirection 破坏方向
* @param range 破坏半径(正方形)
*/
@SuppressWarnings("unreachable")
public void devourBlock(ServerLevel level, BlockPos devourerPos, Direction devourerDirection, int range) {
BlockPos outputPos = devourerPos.relative(devourerDirection.getOpposite());
BlockPos devourCenterPos = devourerPos.relative(devourerDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public boolean canPlace(Level level, BlockPos pos) {
for (int y = 0; y <= range + 1; y++) {
for (int z = -range; z <= range; z++) {
BlockPos currentPos = pos.offset(x, y, z);
if (!level.isEmptyBlock(currentPos)) return false;
if (!level.isEmptyBlock(currentPos) || level.isOutsideBuildHeight(currentPos)) return false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import dev.dubhe.anvilcraft.api.power.IPowerProducer;
import dev.dubhe.anvilcraft.api.power.PowerGrid;
import dev.dubhe.anvilcraft.api.tooltip.IHasAffectRange;
import dev.dubhe.anvilcraft.init.ModBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ChargeCollectorBlockEntity extends BlockEntity implements IPowerProducer {
public class ChargeCollectorBlockEntity extends BlockEntity implements IPowerProducer, IHasAffectRange {

private static final double MAX_POWER_PER_INCOMING = 128;
private static final int COOLDOWN = 40;
Expand All @@ -36,6 +38,11 @@ private ChargeCollectorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockS
super(type, pos, blockState);
}

@Override
public int getRange() {
return 2;
}

@Override
public Level getCurrentLevel() {
return this.level;
Expand Down Expand Up @@ -94,4 +101,9 @@ public double incomingCharge(double num) {
this.chargeNum += num - surplus;
return surplus;
}

@Override
public AABB shape() {
return AABB.ofSize(getBlockPos().getCenter(), 5, 5, 5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.monster.Giant;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -40,7 +41,9 @@ public void accept(Entity oldEntity, Entity newEntity) {
|| itemStack.is(Items.CHIPPED_ANVIL)
|| itemStack.is(Items.DAMAGED_ANVIL)) {
o.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance());
n.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance());
if (newEntity instanceof Giant) {
n.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance());
}
if (n instanceof Mob mob) {
mob.setDropChance(
value == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ public void onLand(@NotNull AnvilFallOnLandEvent event) {
int range = (int) event.getFallDistance() + 2;
range = Math.min(range, 3);
level.setBlock(pos, state.setValue(BlockDevourerBlock.TRIGGERED, true), 2);
if (state.getValue(BlockDevourerBlock.FACING) == Direction.DOWN
&& level.isOutsideBuildHeight(pos.below())) {
level.scheduleTick(pos, devourerBlock, 4);
return;
}
devourerBlock.devourBlock(serverLevel, pos,
state.getValue(BlockDevourerBlock.FACING), range);
state.getValue(BlockDevourerBlock.FACING), range);
if (state.getValue(BlockDevourerBlock.FACING) == Direction.DOWN
&& level.getBlockState(pos.below()).getBlock().defaultDestroyTime() >= 0) {
&& level.getBlockState(pos.below()).getBlock().defaultDestroyTime() >= 0) {
level.setBlock(pos, Blocks.AIR.defaultBlockState(), 2);
level.setBlock(pos.below(), state.setValue(BlockDevourerBlock.TRIGGERED, true), 2);
level.scheduleTick(pos.below(), devourerBlock, 4);
Expand Down

0 comments on commit 8348e80

Please sign in to comment.