Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions src/main/java/cam72cam/mod/entity/boundingbox/BBVoxelShape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package cam72cam.mod.entity.boundingbox;

import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import net.minecraft.util.AxisRotation;
import net.minecraft.util.Direction;
import net.minecraft.util.Util;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.shapes.BitSetVoxelShapePart;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapeCube;
import net.minecraft.util.math.shapes.VoxelShapePart;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class BBVoxelShape extends VoxelShape {
//Though I don't understand what doe this mean...
private static final VoxelShape FULL_CUBE1 = Util.make(() -> {
VoxelShapePart lvt_0_1_ = new BitSetVoxelShapePart(200, 200, 200, -100, -100, -100, 99, 99, 99);
for (int i = -100; i <= 99; i++) {
for (int i1 = -100; i1 <= 99; i1++) {
for (int i2 = -100; i2 <= 99; i2++) {
lvt_0_1_.setFilled(1, i1, i2, false, true);
}
}
}
return new VoxelShapeCube(lvt_0_1_);
});

private BoundingBox bb;

public BBVoxelShape(BoundingBox boundingBox) {
super(FULL_CUBE1.part);
this.bb = boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox() {
return this.bb;
}

@Override
public List<AxisAlignedBB> toBoundingBoxList() {
return Collections.singletonList(bb);
}

@Override
protected boolean contains(double p_211542_1_, double p_211542_3_, double p_211542_5_) {
return bb.contains(p_211542_1_, p_211542_3_, p_211542_5_);
}

@Override
protected double getAllowedOffset(AxisRotation movementAxis, AxisAlignedBB collisionBox, double desiredOffset) {
if (this.isEmpty()) {
return desiredOffset;
} else if (Math.abs(desiredOffset) < 1.0E-7D) {
return 0.0D;
} else {
boolean colliding = bb.intersects(collisionBox.minX, collisionBox.minY, collisionBox.minZ, collisionBox.maxX, collisionBox.maxY, collisionBox.maxZ);
boolean willZCollide = !colliding
&& bb.intersects(collisionBox.minX, collisionBox.minY, collisionBox.minZ + desiredOffset, collisionBox.maxX, collisionBox.maxY, collisionBox.maxZ + desiredOffset);
boolean willXCollide = !colliding
&& bb.intersects(collisionBox.minX + desiredOffset, collisionBox.minY, collisionBox.minZ, collisionBox.maxX + desiredOffset, collisionBox.maxY, collisionBox.maxZ);
switch (movementAxis) {
case FORWARD: //Z
case NONE: //X
if (willXCollide || willZCollide) {
return 0;
} else {
return desiredOffset;
}
case BACKWARD: //Y
default:
//Add a small offset so jump won't get blocked
return bb.internal.calculateYOffset(IBoundingBox.from(collisionBox), desiredOffset) + 0.01;
}
}
}

@Override
protected DoubleList getValues(Direction.Axis axis) {
switch(axis) {
case X:
return DoubleArrayList.wrap(Arrays.copyOf(new double[]{bb.minX, bb.maxX}, part.getXSize() + 1));
case Y:
return DoubleArrayList.wrap(Arrays.copyOf(new double[]{bb.minY, bb.maxY}, part.getYSize() + 1));
case Z:
return DoubleArrayList.wrap(Arrays.copyOf(new double[]{bb.minZ, bb.maxZ}, part.getZSize() + 1));
default:
throw new IllegalArgumentException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cam72cam.mod.mixin.fix.collision;

import cam72cam.mod.entity.boundingbox.BBVoxelShape;
import cam72cam.mod.entity.boundingbox.BoundingBox;
import net.minecraft.util.Direction;
import net.minecraft.util.Util;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.shapes.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(VoxelShapes.class)
public class MixinVoxelShapes {
@Inject(method = "create(Lnet/minecraft/util/math/AxisAlignedBB;)Lnet/minecraft/util/math/shapes/VoxelShape;",
at = @At("HEAD"), cancellable = true)
private static void inj(AxisAlignedBB aabb, CallbackInfoReturnable<VoxelShape> cir) {
if (aabb instanceof BoundingBox) {
cir.setReturnValue(new BBVoxelShape((BoundingBox) aabb));
cir.cancel();
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public net.minecraft.resources.FolderPack func_195768_c(Ljava/lang/String;)Z # n
public net.minecraft.resources.FolderPack func_195766_a(Ljava/lang/String;)Ljava/io/InputStream; # net/minecraft/resources/ResourcePack/getInputStream (Ljava/lang/String;)Ljava/io/InputStream;
public net.minecraft.world.server.ChunkManager func_223491_f()Ljava/lang/Iterable; # net/minecraft/world/server/ChunkManager/getLoadedChunksIterable ()Ljava/lang/Iterable;
public net.minecraft.client.world.ClientWorld field_73035_a #connection
public net.minecraft.client.gui.widget.button.CheckboxButton field_212943_a # checked
public net.minecraft.client.gui.widget.button.CheckboxButton field_212943_a # checked
public net.minecraft.util.math.shapes.VoxelShape <init>(Lnet/minecraft/util/math/shapes/VoxelShapePart;)V
public net.minecraft.util.math.shapes.VoxelShape field_197768_g # part
public net.minecraft.util.math.shapes.VoxelShapeCube <init>(Lnet/minecraft/util/math/shapes/VoxelShapePart;)V
1 change: 1 addition & 0 deletions src/main/resources/mixins.fix.universalmodcore.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"compatibilityLevel": "JAVA_8",
"mixinPriority": 1301,
"mixins": [
"collision.MixinVoxelShapes"
],
"client": [
]
Expand Down
Loading