Upload files to "src/openonyx/interaction/internal"
This commit is contained in:
1 parent
41ce7d6f8d
commit
8f7c0de72a
5 files changed
+299
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
package openonyx.interaction.internal;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import net.minecraft.util.Vec3i;
|
||||||
|
import openonyx.utilities.VecUtils;
|
||||||
|
|
||||||
|
final class PlacementOffsetPart {
|
||||||
|
private static final Comparator<Vec3i> COMPARATOR = Comparator.<Vec3i>comparingLong(VecUtils::L)
|
||||||
|
.thenComparingInt(Vec3i::getY)
|
||||||
|
.thenComparingInt(Vec3i::getX)
|
||||||
|
.thenComparingInt(Vec3i::getZ);
|
||||||
|
|
||||||
|
private PlacementOffsetPart() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package openonyx.interaction.internal;
|
||||||
|
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||||
|
import openonyx.protocol.group_m.Angles;
|
||||||
|
|
||||||
|
public record PlacementResult(BlockPos interactedBlockPos, BlockPos placedBlock, EnumFacing direction, double minPlacementY, Angles rotation) {
|
||||||
|
public boolean L(MovingObjectPosition movingObjectPosition) {
|
||||||
|
if (movingObjectPosition == null) {
|
||||||
|
return false;
|
||||||
|
} else if (movingObjectPosition.typeOfHit != MovingObjectType.BLOCK) {
|
||||||
|
return false;
|
||||||
|
} else if (!movingObjectPosition.getBlockPos().equals(this.interactedBlockPos)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return movingObjectPosition.sideHit != this.direction ? false : !(movingObjectPosition.hitVec.yCoord < this.minPlacementY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decrypt(String string) {
|
||||||
|
String string1 = string;
|
||||||
|
int n = --4 << 3 ^ 6;
|
||||||
|
String string2;
|
||||||
|
int p = (string2 = string1).length();
|
||||||
|
char[] e = new char[p];
|
||||||
|
boolean bl = true;
|
||||||
|
int j;
|
||||||
|
int o = j = p - 1;
|
||||||
|
char[] c = e;
|
||||||
|
byte b = 122;
|
||||||
|
byte d = 33;
|
||||||
|
int k = o;
|
||||||
|
int i = n;
|
||||||
|
|
||||||
|
while (k >= 0) {
|
||||||
|
int l = j;
|
||||||
|
int m = string2.charAt(j);
|
||||||
|
j--;
|
||||||
|
c[l] = (char)(m ^ i);
|
||||||
|
if (j < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m = j--;
|
||||||
|
c[m] = (char)(string2.charAt(m) ^ b);
|
||||||
|
k = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MovingObjectPosition L() {
|
||||||
|
return new MovingObjectPosition(Vec3.atCenterOf(this.interactedBlockPos), this.direction, this.interactedBlockPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package openonyx.interaction.internal;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import net.minecraft.util.Vec3i;
|
||||||
|
import openonyx.core.MinecraftAccess;
|
||||||
|
import openonyx.interaction.BlockUtils;
|
||||||
|
import openonyx.utilities.BoxUtils;
|
||||||
|
import openonyx.utilities.PlayerUtils;
|
||||||
|
|
||||||
|
public class PlacementSearchPattern implements MinecraftAccess {
|
||||||
|
private final List<? extends Vec3i> vec3is;
|
||||||
|
private final Comparator<BlockPos> comparator;
|
||||||
|
|
||||||
|
public static PlacementSearchPattern L() {
|
||||||
|
return new PlacementSearchPattern(PlacementOffset.NO_OFFSET.getBlockPosList(), Comparator.comparingDouble(blockPos -> {
|
||||||
|
BlockPos blockPos1 = blockPos;
|
||||||
|
Vec3 vec3 = PlayerUtils.D((Entity)mc.thePlayer);
|
||||||
|
return -BoxUtils.L(BlockUtils.L(blockPos1).offset(blockPos1.getX(), blockPos1.getY(), blockPos1.getZ()), vec3);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<? extends Vec3i> getVec3is() {
|
||||||
|
return this.vec3is;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator<BlockPos> getComparator() {
|
||||||
|
return this.comparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlacementSearchPattern(List<? extends Vec3i> list, Comparator<BlockPos> comparator) {
|
||||||
|
this.vec3is = list;
|
||||||
|
this.comparator = comparatorx;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package openonyx.interaction.internal;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import net.minecraft.util.Vec3i;
|
||||||
|
import openonyx.core.MinecraftAccess;
|
||||||
|
import openonyx.interaction.BlockUtils;
|
||||||
|
import openonyx.protocol.RotationHandler;
|
||||||
|
import openonyx.protocol.group_m.Angles;
|
||||||
|
import openonyx.utilities.BoxUtils;
|
||||||
|
import openonyx.utilities.internal.Box3;
|
||||||
|
|
||||||
|
public final class PlacementSolver implements MinecraftAccess {
|
||||||
|
private static final Comparator<PlacementSolverData> COMPARATOR = Comparator.<PlacementSolverData>comparingDouble(
|
||||||
|
placementSolverData -> placementSolverData.point.subtract(0.5, 0.5, 0.5).multiply(new Vec3(placementSolverData.side.getDirectionVec())).lengthSqr()
|
||||||
|
)
|
||||||
|
.thenComparingDouble(placementSolverData -> placementSolverData.point.yCoord);
|
||||||
|
|
||||||
|
private static boolean L(IBlockState iBlockState, BlockPos blockPos) {
|
||||||
|
AxisAlignedBB axisAlignedBB;
|
||||||
|
return L(iBlockState)
|
||||||
|
? false
|
||||||
|
: (axisAlignedBB = BlockUtils.L(iBlockState, blockPos)).maxY >= 1.0
|
||||||
|
&& axisAlignedBB.minX <= 0.5
|
||||||
|
&& axisAlignedBB.maxX >= 0.5
|
||||||
|
&& axisAlignedBB.minZ <= 0.5
|
||||||
|
&& axisAlignedBB.maxZ >= 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlacementSolverData L(
|
||||||
|
IBlockState iBlockState, BlockPos blockPos, PlacementSolverPart placementSolverPart, BlockPlacementContext blockPlacementContext
|
||||||
|
) {
|
||||||
|
IBlockState iBlockState1 = iBlockState;
|
||||||
|
List list = List.of(BlockUtils.L(iBlockState1, blockPos));
|
||||||
|
PlacementSolverData placementSolverData = null;
|
||||||
|
Iterator iterator = list.iterator();
|
||||||
|
|
||||||
|
label34:
|
||||||
|
while (true) {
|
||||||
|
for (Iterator iterator1 = iterator; iterator1.hasNext(); iterator1 = iterator) {
|
||||||
|
Box3 box32;
|
||||||
|
Box3 box3 = box32 = BoxUtils.L((AxisAlignedBB)iterator.next(), placementSolverPart.enumFacing);
|
||||||
|
if (box3.getVec3().yCoord >= 0.9) {
|
||||||
|
Box3 box31;
|
||||||
|
box3 = (box31 = box3.L(0.6).L()) != null ? box31 : box32;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 vec3;
|
||||||
|
if ((vec3 = blockPlacementContext.getAimPointOption().getAimPointStrategy().L(box3, blockPos)) != null) {
|
||||||
|
PlacementSolverData placementSolverData1 = new PlacementSolverData(box32, placementSolverPart.enumFacing, vec3);
|
||||||
|
if (placementSolverData == null || COMPARATOR.compare(placementSolverData1, placementSolverData) > 0) {
|
||||||
|
placementSolverData = placementSolverData1;
|
||||||
|
}
|
||||||
|
continue label34;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placementSolverData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean L(IBlockState iBlockState) {
|
||||||
|
IBlockState iBlockState1 = iBlockState;
|
||||||
|
Material material;
|
||||||
|
return (material = iBlockState1.getBlock().getMaterial()) == Material.air || material.isLiquid();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlacementSolverPart L(BlockPos blockPos, PlacementSolverMode placementSolverMode, BlockPlacementContext blockPlacementContext) {
|
||||||
|
BlockPos blockPos1 = blockPos;
|
||||||
|
Vec3 vec3 = blockPlacementContext.getEyePosition().L();
|
||||||
|
ArrayList arrayList = new ArrayList(6);
|
||||||
|
EnumFacing[] enumFacings;
|
||||||
|
int i = (enumFacings = EnumFacing.values()).length;
|
||||||
|
|
||||||
|
for (int k = j = 0; k < i; k = ++j) {
|
||||||
|
EnumFacing enumFacing = enumFacings[j];
|
||||||
|
PlacementSolverPart placementSolverPart;
|
||||||
|
if ((placementSolverPart = L(blockPos1, enumFacing, placementSolverMode)) != null
|
||||||
|
&& (blockPlacementContext.getAimPointOption().L() || !(placementSolverPart.L(vec3) < 0.0))) {
|
||||||
|
arrayList.add(placementSolverPart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Angles angles1 = RotationHandler.INSTANCE.getAngles5();
|
||||||
|
PlacementSolverPart placementSolverPart1 = null;
|
||||||
|
float f = Float.POSITIVE_INFINITY;
|
||||||
|
Iterator iterator = arrayList.iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
PlacementSolverPart placementSolverPart2;
|
||||||
|
Angles angles = Angles.L((placementSolverPart2 = (PlacementSolverPart)iterator.next()).vec3, vec3);
|
||||||
|
float g;
|
||||||
|
if ((g = angles1.L(angles)) < f) {
|
||||||
|
f = g;
|
||||||
|
placementSolverPart1 = placementSolverPart2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placementSolverPart1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlacementResult L(BlockPos blockPos, BlockPlacementContext blockPlacementContext) {
|
||||||
|
BlockPos blockPos1 = blockPos;
|
||||||
|
if (L(BlockUtils.d(blockPos1), blockPos1)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList arrayList = new ArrayList<>(blockPlacementContext.getPlacementSearchPattern().getVec3is());
|
||||||
|
Comparator comparator = blockPlacementContext.getPlacementSearchPattern().getComparator();
|
||||||
|
arrayList.sort((vec3i, vec3i1) -> comparator.compare(blockPos1.add(vec3i1), blockPos1.add(vec3ix)));
|
||||||
|
Iterator iterator;
|
||||||
|
Iterator iterator1 = iterator = arrayList.iterator();
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
Vec3i vec3i = (Vec3i)iterator.next();
|
||||||
|
IBlockState iBlockState;
|
||||||
|
BlockPos blockPos2;
|
||||||
|
if (L(iBlockState = BlockUtils.d(blockPos2 = blockPos1.add(vec3i)), blockPos2)) {
|
||||||
|
iterator1 = iterator;
|
||||||
|
} else {
|
||||||
|
PlacementSolverMode placementSolverMode = L(iBlockState) ? PlacementSolverMode.PLACE_AT_NEIGHBOR : PlacementSolverMode.REPLACE_EXISTING_BLOCK;
|
||||||
|
if (placementSolverMode == PlacementSolverMode.REPLACE_EXISTING_BLOCK
|
||||||
|
&& !BlockUtils.L(iBlockState, blockPos2, blockPlacementContext.getItemStack())) {
|
||||||
|
iterator1 = iterator;
|
||||||
|
} else {
|
||||||
|
PlacementSolverPart placementSolverPart;
|
||||||
|
if ((placementSolverPart = L(blockPos2, placementSolverMode, blockPlacementContext)) == null) {
|
||||||
|
iterator1 = iterator;
|
||||||
|
} else {
|
||||||
|
blockPos = placementSolverPart.blockPos;
|
||||||
|
PlacementSolverData placementSolverData;
|
||||||
|
if ((placementSolverData = L(BlockUtils.d(placementSolverPart.blockPos), blockPos, placementSolverPart, blockPlacementContext)) != null) {
|
||||||
|
Angles angles = Angles.L(
|
||||||
|
placementSolverData.point.add(blockPos.getX(), blockPos.getY(), blockPos.getZ()), blockPlacementContext.getEyePosition().L()
|
||||||
|
);
|
||||||
|
return new PlacementResult(
|
||||||
|
blockPos, blockPos2, placementSolverData.side, placementSolverData.face.getVec32().yCoord + blockPos.getY(), angles
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator1 = iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlacementSolverPart L(BlockPos blockPos, EnumFacing enumFacing, PlacementSolverMode placementSolverMode) {
|
||||||
|
switch (placementSolverMode) {
|
||||||
|
case PLACE_AT_NEIGHBOR:
|
||||||
|
while (false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
IBlockState iBlockState;
|
||||||
|
BlockPos blockPos1;
|
||||||
|
if ((iBlockState = BlockUtils.L(blockPos1 = blockPos.offset(enumFacing.getOpposite()))) == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return iBlockState.getBlock().isReplaceable(mc.theWorld, blockPos1) ? null : new PlacementSolverPart(blockPos1, enumFacing);
|
||||||
|
}
|
||||||
|
case REPLACE_EXISTING_BLOCK:
|
||||||
|
return new PlacementSolverPart(blockPos, enumFacing);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlacementSolver() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package openonyx.interaction.internal;
|
||||||
|
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import openonyx.utilities.internal.Box3;
|
||||||
|
|
||||||
|
record PlacementSolverData(Box3 face, EnumFacing side, Vec3 point) {
|
||||||
|
}
|
||||||
Reference in new issue
Block a user