Upload files to "src/openonyx/interaction"
This commit is contained in:
1 parent
8fe58141d2
commit
23c280f210
2 files changed
+206
No files matched your search
@@ -0,0 +1,140 @@
|
||||
package openonyx.interaction;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import openonyx.core.MinecraftAccess;
|
||||
import openonyx.utilities.HotbarManager;
|
||||
|
||||
public class BlockUtils implements MinecraftAccess {
|
||||
public static final AxisAlignedBB AXIS_ALIGNED_BB = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
|
||||
|
||||
public static boolean L(MovingObjectPosition movingObjectPosition) {
|
||||
MovingObjectPosition movingObjectPosition1 = movingObjectPosition;
|
||||
ItemStack itemStack;
|
||||
int i = (itemStack = mc.thePlayer.inventory.getStackInSlot(HotbarManager.INSTANCE.L())) == null ? 0 : itemStack.stackSize;
|
||||
if (!mc.playerController
|
||||
.onPlayerRightClick(
|
||||
mc.thePlayer, mc.theWorld, itemStack, movingObjectPosition1.getBlockPos(), movingObjectPosition1.sideHit, movingObjectPosition1.hitVec
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStack != null && itemStack.stackSize == 0) {
|
||||
mc.thePlayer.inventory.mainInventory[HotbarManager.INSTANCE.L()] = null;
|
||||
} else if (itemStack != null && (itemStack.stackSize != i || mc.playerController.isInCreativeMode())) {
|
||||
mc.entityRenderer.itemRenderer.resetEquippedProgress();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AxisAlignedBB L(IBlockState iBlockState, BlockPos blockPos) {
|
||||
IBlockState iBlockState1 = iBlockState;
|
||||
Block block;
|
||||
(block = iBlockState1.getBlock()).setBlockBoundsBasedOnState(mc.theWorld, blockPos);
|
||||
AxisAlignedBB axisAlignedBB;
|
||||
boolean bl = (axisAlignedBB = new AxisAlignedBB(
|
||||
block.getBlockBoundsMinX(),
|
||||
block.getBlockBoundsMinY(),
|
||||
block.getBlockBoundsMinZ(),
|
||||
block.getBlockBoundsMaxX(),
|
||||
block.getBlockBoundsMaxY(),
|
||||
block.getBlockBoundsMaxZ()
|
||||
))
|
||||
.getXsize()
|
||||
<= 0.0
|
||||
|| axisAlignedBB.getYsize() <= 0.0
|
||||
|| axisAlignedBB.getZsize() <= 0.0;
|
||||
return bl ? AXIS_ALIGNED_BB : axisAlignedBB;
|
||||
}
|
||||
|
||||
public static BlockPos L(MovingObjectPosition movingObjectPosition) {
|
||||
return movingObjectPosition.getBlockPos().offset(movingObjectPosition.sideHit);
|
||||
}
|
||||
|
||||
public static Block L(BlockPos blockPos) {
|
||||
BlockPos blockPos1 = blockPos;
|
||||
IBlockState iBlockState;
|
||||
return (iBlockState = L(blockPos1)) == null ? null : iBlockState.getBlock();
|
||||
}
|
||||
|
||||
public static boolean d(BlockPos blockPos) {
|
||||
BlockPos blockPos1 = blockPos;
|
||||
Block block;
|
||||
return (block = L(blockPos1)) == null || block.getMaterial() == Material.air;
|
||||
}
|
||||
|
||||
public static IBlockState d(BlockPos blockPos) {
|
||||
BlockPos blockPos1 = blockPos;
|
||||
IBlockState iBlockState;
|
||||
return (iBlockState = L(blockPos1)) != null ? iBlockState : Blocks.air.getDefaultState();
|
||||
}
|
||||
|
||||
public static void L(MovingObjectPosition movingObjectPosition) {
|
||||
L(movingObjectPosition, () -> true, () -> true, SwingMode.DO_NOT_HIDE);
|
||||
}
|
||||
|
||||
public static boolean L(IBlockState iBlockState, BlockPos blockPos, ItemStack itemStack) {
|
||||
return iBlockState.getBlock().isReplaceable(mc.theWorld, blockPos);
|
||||
}
|
||||
|
||||
public static IBlockState L(BlockPos blockPos) {
|
||||
return mc.theWorld == null ? null : mc.theWorld.getBlockState(blockPos);
|
||||
}
|
||||
|
||||
public static void L(MovingObjectPosition movingObjectPosition, BooleanSupplier booleanSupplier, BooleanSupplier booleanSupplier1, SwingMode swingMode) {
|
||||
MovingObjectPosition movingObjectPosition1 = movingObjectPosition;
|
||||
ItemStack itemStack;
|
||||
int i = (itemStack = mc.thePlayer.inventory.getStackInSlot(HotbarManager.INSTANCE.L())) == null ? 0 : itemStack.stackSize;
|
||||
if (!mc.playerController
|
||||
.onPlayerRightClick(
|
||||
mc.thePlayer, mc.theWorld, itemStack, movingObjectPosition1.getBlockPos(), movingObjectPosition1.sideHit, movingObjectPosition1.hitVec
|
||||
)) {
|
||||
if (itemStack != null) {
|
||||
if (mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, itemStack)) {
|
||||
if (booleanSupplier1.getAsBoolean()) {
|
||||
swingMode.L();
|
||||
}
|
||||
|
||||
mc.entityRenderer.itemRenderer.resetEquippedProgress2();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (booleanSupplier.getAsBoolean()) {
|
||||
swingMode.L();
|
||||
}
|
||||
|
||||
if (itemStack != null && itemStack.stackSize == 0) {
|
||||
mc.thePlayer.inventory.mainInventory[HotbarManager.INSTANCE.L()] = null;
|
||||
} else {
|
||||
if (itemStack != null && (itemStack.stackSize != i || mc.playerController.isInCreativeMode())) {
|
||||
mc.entityRenderer.itemRenderer.resetEquippedProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AxisAlignedBB L(BlockPos blockPos) {
|
||||
BlockPos blockPos1 = blockPos;
|
||||
IBlockState iBlockState;
|
||||
return (iBlockState = L(blockPos1)) != null && iBlockState.getBlock().getMaterial() != Material.air ? L(iBlockState, blockPos1) : AXIS_ALIGNED_BB;
|
||||
}
|
||||
|
||||
public static boolean L(Block block) {
|
||||
return block instanceof BlockSlab || block instanceof BlockStairs;
|
||||
}
|
||||
|
||||
public static boolean L(BlockPos blockPos) {
|
||||
return L(blockPos) != null && World.doesBlockHaveSolidTopSurface(mc.theWorld, blockPos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package openonyx.interaction;
|
||||
|
||||
import net.minecraft.network.play.client.C0APacketAnimation;
|
||||
import openonyx.core.MinecraftAccess;
|
||||
import openonyx.history.DisplayNamed;
|
||||
|
||||
public enum SwingMode implements DisplayNamed, Runnable, MinecraftAccess {
|
||||
HIDE_BOTH("Hide for both", false),
|
||||
HIDE_SERVER("Hide for server", false),
|
||||
HIDE_CLIENT("Hide for client", true),
|
||||
DO_NOT_HIDE("Do not hide", true);
|
||||
|
||||
private final boolean i;
|
||||
private final String e;
|
||||
|
||||
public boolean L() {
|
||||
return this.i;
|
||||
}
|
||||
|
||||
private static SwingMode[] L() {
|
||||
SwingMode[] swingModes = new SwingMode[4];
|
||||
boolean bl = true;
|
||||
swingModes[0] = DO_NOT_HIDE;
|
||||
swingModes[1] = HIDE_BOTH;
|
||||
swingModes[2] = HIDE_CLIENT;
|
||||
swingModes[3] = HIDE_SERVER;
|
||||
return swingModes;
|
||||
}
|
||||
|
||||
SwingMode(String string1, boolean bl) {
|
||||
this.e = string1;
|
||||
this.i = bl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (this) {
|
||||
case HIDE_BOTH:
|
||||
while (false) {
|
||||
}
|
||||
|
||||
mc.thePlayer.swingItem();
|
||||
return;
|
||||
case HIDE_SERVER:
|
||||
return;
|
||||
case HIDE_CLIENT:
|
||||
mc.getNetHandler().addToSendQueue(new C0APacketAnimation());
|
||||
return;
|
||||
case DO_NOT_HIDE:
|
||||
mc.thePlayer.swingItemClientOnly();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public void L() {
|
||||
this.run();
|
||||
}
|
||||
|
||||
public String d() {
|
||||
return this.e;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user