use of net.minecraft.util.Direction.Axis in project ChocolateQuestRepoured by TeamChocoQuest.
the class EntityAIHurtByTarget method getPathComplexity.
private static int getPathComplexity(Path path) {
if (path.getNodeCount() == 0) {
return 0;
}
int pathComplexity = 0;
Axis prevPrevPrevAxis = null;
Axis prevPrevAxis = null;
Axis prevAxis = null;
int prevX = path.getNode(0).x;
int prevZ = path.getNode(0).z;
for (int i = 0; i < path.getNodeCount(); i++) {
PathPoint point = path.getNode(i);
int x = point.x;
int z = point.z;
Axis axis;
if (x != prevX) {
axis = Axis.X;
} else if (z != prevZ) {
axis = Axis.Z;
} else {
axis = Axis.Y;
}
if (prevAxis == axis && prevAxis != prevPrevAxis && prevPrevAxis == prevPrevPrevAxis) {
pathComplexity++;
}
prevPrevPrevAxis = prevPrevAxis;
prevPrevAxis = prevAxis;
prevAxis = axis;
prevX = x;
prevZ = z;
}
return pathComplexity;
}
use of net.minecraft.util.Direction.Axis 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 net.minecraft.util.Direction.Axis in project Create_Aeronautics by Eriksonnaren.
the class RotationPropagatorMixin method isLargeToLargeGear.
private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
if (ICogWheel.isLargeCog(from) && ICogWheel.isLargeCog(to)) {
Axis fromAxis = (Axis) from.getValue(BlockStateProperties.AXIS);
Axis toAxis = (Axis) to.getValue(BlockStateProperties.AXIS);
if (fromAxis == toAxis) {
return false;
} else {
Axis[] var5 = Axis.values();
int var6 = var5.length;
for (int var7 = 0; var7 < var6; ++var7) {
Axis axis = var5[var7];
int axisDiff = axis.choose(diff.getX(), diff.getY(), diff.getZ());
if (axis != fromAxis && axis != toAxis) {
if (axisDiff != 0) {
return false;
}
} else if (axisDiff == 0) {
return false;
}
}
return true;
}
} else {
return false;
}
}
Aggregations