use of mekanism.common.network.to_client.PacketLightningRender in project Mekanism by mekanism.
the class ItemAtomicDisassembler method findPositions.
private static List<BlockPos> findPositions(BlockState state, BlockPos location, World world) {
List<BlockPos> found = new ArrayList<>();
Set<BlockPos> checked = new ObjectOpenHashSet<>();
found.add(location);
Block startBlock = state.getBlock();
int maxCount = MekanismConfig.gear.disassemblerMiningCount.get() - 1;
for (int i = 0; i < found.size(); i++) {
BlockPos blockPos = found.get(i);
checked.add(blockPos);
for (BlockPos pos : BlockPos.betweenClosed(blockPos.offset(-1, -1, -1), blockPos.offset(1, 1, 1))) {
// We can check contains as mutable
if (!checked.contains(pos)) {
Optional<BlockState> blockState = WorldUtils.getBlockState(world, pos);
if (blockState.isPresent() && startBlock == blockState.get().getBlock()) {
// Make sure to add it as immutable
found.add(pos.immutable());
// Note: We do this for all blocks we find/attempt to mine, not just ones we do mine, as it is a bit simpler
// and also represents those blocks getting checked by the vein mining for potentially being able to be mined
Mekanism.packetHandler.sendToAllTracking(new PacketLightningRender(LightningPreset.TOOL_AOE, Objects.hash(blockPos, pos), Vector3d.atCenterOf(blockPos), Vector3d.atCenterOf(pos), 10), world, blockPos);
if (found.size() > maxCount) {
return found;
}
}
}
}
}
return found;
}
use of mekanism.common.network.to_client.PacketLightningRender in project Mekanism by mekanism.
the class ModuleFarmingUnit method tillAOE.
private ActionResultType tillAOE(ItemUseContext context, ToolType toolType, SoundEvent sound, FloatingLong energyUsage) {
PlayerEntity player = context.getPlayer();
if (player == null || player.isShiftKeyDown()) {
// Skip if we don't have a player, or they are sneaking
return ActionResultType.PASS;
}
Direction sideHit = context.getClickedFace();
if (sideHit == Direction.DOWN) {
// Don't allow tilling a block from underneath
return ActionResultType.PASS;
}
int diameter = farmingRadius.get().getRadius();
if (diameter == 0) {
// If we don't have any blocks we are going to want to do, then skip it
return ActionResultType.PASS;
}
ItemStack stack = context.getItemInHand();
IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
if (energyContainer == null) {
return ActionResultType.FAIL;
}
FloatingLong energy = energyContainer.getEnergy();
if (energy.smallerThan(energyUsage)) {
// Fail if we don't have enough energy or using the item failed
return ActionResultType.FAIL;
}
World world = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockState tilledState = world.getBlockState(pos).getToolModifiedState(world, pos, player, stack, toolType);
if (tilledState == null) {
// Skip tilling the blocks if the one we clicked cannot be tilled
return ActionResultType.PASS;
}
BlockPos abovePos = pos.above();
BlockState aboveState = world.getBlockState(abovePos);
// Check to make sure the block above is not opaque
if (aboveState.isSolidRender(world, abovePos)) {
// If the block above our source is opaque, just skip tiling in general
return ActionResultType.PASS;
}
if (world.isClientSide) {
return ActionResultType.SUCCESS;
}
// Processing did not happen, so we need to process it
world.setBlock(pos, tilledState, BlockFlags.DEFAULT_AND_RERENDER);
Material aboveMaterial = aboveState.getMaterial();
if (aboveMaterial == Material.PLANT || aboveMaterial == Material.REPLACEABLE_PLANT) {
world.destroyBlock(abovePos, true);
}
world.playSound(null, pos, sound, SoundCategory.BLOCKS, 1.0F, 1.0F);
FloatingLong energyUsed = energyUsage.copy();
int radius = (diameter - 1) / 2;
for (BlockPos newPos : BlockPos.betweenClosed(pos.offset(-radius, 0, -radius), pos.offset(radius, 0, radius))) {
if (pos.equals(newPos)) {
// Skip the source position as it is free, and we manually handled it before the loop
continue;
} else if (energyUsed.add(energyUsage).greaterThan(energy)) {
break;
}
BlockState stateAbove = world.getBlockState(newPos.above());
// the same as the one we got on the initial block we interacted with
if (!stateAbove.isSolidRender(world, newPos.above()) && tilledState == world.getBlockState(newPos).getToolModifiedState(world, newPos, player, stack, toolType)) {
// Some of the below methods don't behave properly when the BlockPos is mutable, so now that we are onto ones where it may actually
// matter we make sure to get an immutable instance of newPos
newPos = newPos.immutable();
// Add energy cost
energyUsed = energyUsed.plusEqual(energyUsage);
// Replace the block. Note it just directly sets it (in the same way that HoeItem/ShovelItem do)
world.setBlock(newPos, tilledState, BlockFlags.DEFAULT_AND_RERENDER);
aboveMaterial = stateAbove.getMaterial();
if (aboveMaterial == Material.PLANT || aboveMaterial == Material.REPLACEABLE_PLANT) {
// If the block above the one we tilled is a plant, then we try to remove it
world.destroyBlock(newPos.above(), true);
}
world.playSound(null, newPos, sound, SoundCategory.BLOCKS, 1.0F, 1.0F);
Mekanism.packetHandler.sendToAllTracking(new PacketLightningRender(LightningPreset.TOOL_AOE, Objects.hash(pos, newPos), Vector3d.upFromBottomCenterOf(pos, 0.94), Vector3d.upFromBottomCenterOf(newPos, 0.94), 10), world, pos);
}
}
energyContainer.extract(energyUsed, Action.EXECUTE, AutomationType.MANUAL);
return ActionResultType.SUCCESS;
}
use of mekanism.common.network.to_client.PacketLightningRender in project Mekanism by mekanism.
the class ModuleMagneticAttractionUnit method pullItem.
private void pullItem(PlayerEntity player, ItemEntity item) {
Vector3d diff = player.position().subtract(item.position());
Vector3d motionNeeded = new Vector3d(Math.min(diff.x, 1), Math.min(diff.y, 1), Math.min(diff.z, 1));
Vector3d motionDiff = motionNeeded.subtract(player.getDeltaMovement());
item.setDeltaMovement(motionDiff.scale(0.2));
Mekanism.packetHandler.sendToAllTrackingAndSelf(new PacketLightningRender(LightningPreset.MAGNETIC_ATTRACTION, Objects.hash(player.getUUID(), item), player.position().add(0, 0.2, 0), item.position(), (int) (diff.length() * 4)), player);
}
use of mekanism.common.network.to_client.PacketLightningRender in project Mekanism by mekanism.
the class ModuleFarmingUnit method stripLogsAOE.
private ActionResultType stripLogsAOE(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
if (player == null || player.isShiftKeyDown()) {
// Skip if we don't have a player, or they are sneaking
return ActionResultType.PASS;
}
int diameter = farmingRadius.get().getRadius();
if (diameter == 0) {
// If we don't have any blocks we are going to want to do, then skip it
return ActionResultType.PASS;
}
ItemStack stack = context.getItemInHand();
IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
if (energyContainer == null) {
return ActionResultType.FAIL;
}
FloatingLong energy = energyContainer.getEnergy();
FloatingLong energyUsage = MekanismConfig.gear.mekaToolEnergyUsageAxe.get();
if (energy.smallerThan(energyUsage)) {
// Fail if we don't have enough energy or using the item failed
return ActionResultType.FAIL;
}
World world = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockState clickedState = world.getBlockState(pos);
BlockState strippedState = clickedState.getToolModifiedState(world, pos, player, stack, ToolType.AXE);
if (strippedState == null) {
// Skip stripping the blocks if the one we clicked cannot be stripped
return ActionResultType.PASS;
} else if (world.isClientSide) {
return ActionResultType.SUCCESS;
}
Axis axis = clickedState.getValue(RotatedPillarBlock.AXIS);
// Process the block we interacted with initially and play the sound
world.setBlock(pos, strippedState, BlockFlags.DEFAULT_AND_RERENDER);
world.playSound(null, pos, SoundEvents.AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
Direction side = context.getClickedFace();
FloatingLong energyUsed = energyUsage.copy();
Vector3d offset = Vector3d.atLowerCornerOf(side.getNormal()).scale(0.44);
for (BlockPos newPos : getStrippingArea(pos, side, (diameter - 1) / 2)) {
if (pos.equals(newPos)) {
// Skip the source position as it is free, and we manually handled it before the loop
continue;
} else if (energyUsed.add(energyUsage).greaterThan(energy)) {
break;
}
// Check to make that the result we would get from stripping the other block is the same as the one we got on the initial block we interacted with
// Also make sure that it is on the same axis as the block we initially clicked
BlockState state = world.getBlockState(newPos);
if (strippedState == state.getToolModifiedState(world, newPos, player, stack, ToolType.AXE) && axis == state.getValue(RotatedPillarBlock.AXIS)) {
// Some of the below methods don't behave properly when the BlockPos is mutable, so now that we are onto ones where it may actually
// matter we make sure to get an immutable instance of newPos
newPos = newPos.immutable();
// Add energy cost
energyUsed = energyUsed.plusEqual(energyUsage);
// Replace the block. Note it just directly sets it (in the same way that AxeItem does).
world.setBlock(newPos, strippedState, BlockFlags.DEFAULT_AND_RERENDER);
world.playSound(null, pos, SoundEvents.AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
Mekanism.packetHandler.sendToAllTracking(new PacketLightningRender(LightningPreset.TOOL_AOE, Objects.hash(pos, newPos), Vector3d.atCenterOf(pos).add(offset), Vector3d.atCenterOf(newPos).add(offset), 10), world, pos);
}
}
energyContainer.extract(energyUsed, Action.EXECUTE, AutomationType.MANUAL);
return ActionResultType.SUCCESS;
}
use of mekanism.common.network.to_client.PacketLightningRender in project Mekanism by mekanism.
the class ModuleVeinMiningUnit method findPositions.
public static Set<BlockPos> findPositions(BlockState state, BlockPos location, World world, int maxRange) {
Set<BlockPos> found = new LinkedHashSet<>();
Set<BlockPos> openSet = new LinkedHashSet<>();
openSet.add(location);
Block startBlock = state.getBlock();
int maxCount = MekanismConfig.gear.disassemblerMiningCount.get() - 1;
while (!openSet.isEmpty()) {
BlockPos blockPos = openSet.iterator().next();
found.add(blockPos);
openSet.remove(blockPos);
if (found.size() > maxCount) {
return found;
}
for (BlockPos pos : BlockPos.betweenClosed(blockPos.offset(-1, -1, -1), blockPos.offset(1, 1, 1))) {
// We can check contains as mutable
if (!found.contains(pos) && (maxRange == -1 || WorldUtils.distanceBetween(location, pos) <= maxRange)) {
Optional<BlockState> blockState = WorldUtils.getBlockState(world, pos);
if (blockState.isPresent() && startBlock == blockState.get().getBlock()) {
// Make sure to add it as immutable
if (openSet.add(pos.immutable())) {
// Note: We do this for all blocks we find/attempt to mine, not just ones we do mine, as it is a bit simpler
// and also represents those blocks getting checked by the vein mining for potentially being able to be mined
Mekanism.packetHandler.sendToAllTracking(new PacketLightningRender(LightningPreset.TOOL_AOE, Objects.hash(blockPos, pos), Vector3d.atCenterOf(blockPos), Vector3d.atCenterOf(pos), 10), world, blockPos);
}
}
}
}
}
return found;
}
Aggregations