Added ship movement preview to bounding box preview

This commit is contained in:
LemADEC 2020-07-18 21:26:53 +02:00
parent c96b82ad06
commit 0e1a12b94a
3 changed files with 86 additions and 3 deletions

View file

@ -17,6 +17,8 @@ import li.cil.oc.api.machine.Context;
import javax.annotation.Nonnull;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraftforge.fml.common.Optional;
@ -99,6 +101,32 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
return tagCompound;
}
@Nonnull
@Override
public NBTTagCompound getUpdateTag() {
final NBTTagCompound tagCompound = super.getUpdateTag();
tagCompound.setInteger("moveFront", moveFront);
tagCompound.setInteger("moveUp", moveUp);
tagCompound.setInteger("moveRight", moveRight);
tagCompound.setByte("rotationSteps", rotationSteps);
return tagCompound;
}
@Override
public void onDataPacket(@Nonnull final NetworkManager networkManager, @Nonnull final SPacketUpdateTileEntity packet) {
super.onDataPacket(networkManager, packet);
final NBTTagCompound tagCompound = packet.getNbtCompound();
setMovement(
tagCompound.getInteger("moveFront"),
tagCompound.getInteger("moveUp"),
tagCompound.getInteger("moveRight") );
setRotationSteps(tagCompound.getByte("rotationSteps"));
}
@Override
public NBTTagCompound writeItemDropNBT(NBTTagCompound tagCompound) {
tagCompound = super.writeItemDropNBT(tagCompound);

View file

@ -22,6 +22,7 @@ import cr0s.warpdrive.data.EnumShipMovementType;
import cr0s.warpdrive.data.GlobalRegionManager;
import cr0s.warpdrive.data.SoundEvents;
import cr0s.warpdrive.data.GlobalRegion;
import cr0s.warpdrive.data.Transformation;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
import cr0s.warpdrive.event.JumpSequencer;
@ -125,11 +126,44 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
final Vector3 vector3 = new Vector3(this);
vector3.translate(0.5D);
final Vector3 vMin = new Vector3(minX - 0.0D, minY - 0.0D, minZ - 0.0D);
final Vector3 vMax = new Vector3(maxX + 1.0D, maxY + 1.0D, maxZ + 1.0D);
FMLClientHandler.instance().getClient().effectRenderer.addEffect(
new EntityFXBoundingBox(world, vector3,
new Vector3(minX - 0.0D, minY - 0.0D, minZ - 0.0D),
new Vector3(maxX + 1.0D, maxY + 1.0D, maxZ + 1.0D),
vMin,
vMax,
1.0F, 0.8F, 0.3F, BOUNDING_BOX_INTERVAL_TICKS + 1) );
final VectorI vMovement = getMovement();
if (vMovement.getMagnitudeSquared() > 0) {
final VectorI movement = getMovement();
final VectorI shipSize = new VectorI(getFront() + 1 + getBack(),
getUp() + 1 + getDown(),
getRight() + 1 + getLeft());
final int maxDistance = 256;
if (Math.abs(movement.x) - shipSize.x > maxDistance) {
movement.x = (int) Math.signum(movement.x) * (shipSize.x + maxDistance);
}
if (Math.abs(movement.y) - shipSize.y > maxDistance) {
movement.y = (int) Math.signum(movement.y) * (shipSize.y + maxDistance);
}
if (Math.abs(movement.z) - shipSize.z > maxDistance) {
movement.z = (int) Math.signum(movement.z) * (shipSize.z + maxDistance);
}
facing = world.getBlockState(pos).getValue(BlockProperties.FACING_HORIZONTAL);
final int moveX = facing.getXOffset() * movement.x - facing.getZOffset() * movement.z;
final int moveY = movement.y;
final int moveZ = facing.getZOffset() * movement.x + facing.getXOffset() * movement.z;
final Transformation transformation = new Transformation(this, moveX, moveY, moveZ, getRotationSteps());
final Vec3d vMinTarget = transformation.apply(vMin.x, vMin.y, vMin.z);
final Vec3d vMaxTarget = transformation.apply(vMax.x, vMax.y, vMax.z);
FMLClientHandler.instance().getClient().effectRenderer.addEffect(
new EntityFXBoundingBox(world, vector3,
new Vector3(Math.min(vMinTarget.x, vMaxTarget.x), Math.min(vMinTarget.y, vMaxTarget.y), Math.min(vMinTarget.z, vMaxTarget.z)),
new Vector3(Math.max(vMinTarget.x, vMaxTarget.x), Math.max(vMinTarget.y, vMaxTarget.y), Math.max(vMinTarget.z, vMaxTarget.z)),
0.3F, 0.8F, 1.0F, BOUNDING_BOX_INTERVAL_TICKS + 1) );
}
}
@Override

View file

@ -1,6 +1,9 @@
package cr0s.warpdrive.data;
import cr0s.warpdrive.api.ITransformation;
import cr0s.warpdrive.block.movement.TileEntityShipCore;
import javax.annotation.Nonnull;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
@ -8,6 +11,9 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class Transformation implements ITransformation {
private final VectorI sourceCore;
@ -22,7 +28,7 @@ public class Transformation implements ITransformation {
private final int maxY;
private final int maxZ;
public Transformation(final JumpShip ship, final World targetWorld, final int moveX, final int moveY, final int moveZ, final byte rotationSteps) {
public Transformation(@Nonnull final JumpShip ship, @Nonnull final World targetWorld, final int moveX, final int moveY, final int moveZ, final byte rotationSteps) {
sourceCore = new VectorI(ship.core);
minX = ship.minX;
minY = ship.minY;
@ -36,6 +42,21 @@ public class Transformation implements ITransformation {
this.rotationSteps = (byte) ((rotationSteps + 4) % 4);
}
@SideOnly(Side.CLIENT)
public Transformation(@Nonnull final TileEntityShipCore tileEntityShipCore, final int moveX, final int moveY, final int moveZ, final byte rotationSteps) {
sourceCore = new VectorI(tileEntityShipCore);
minX = tileEntityShipCore.minX;
minY = tileEntityShipCore.minY;
minZ = tileEntityShipCore.minZ;
maxX = tileEntityShipCore.maxX;
maxY = tileEntityShipCore.maxY;
maxZ = tileEntityShipCore.maxZ;
this.targetWorld = null;
move = new VectorI(moveX, moveY, moveZ);
targetCore = sourceCore.add(move);
this.rotationSteps = (byte) ((rotationSteps + 4) % 4);
}
@Override
public World getTargetWorld() {
return targetWorld;