mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-19 03:39:15 +00:00
Add most of code. Still missing some hint related stuff.
Signed-off-by: Glease <[email protected]>
This commit is contained in:
1 parent
b5166dbd1c
commit
dc12c4a1df
40 files changed
+4085
No files matched your search
@@ -0,0 +1,183 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.gtnewhorizon.structurelib.alignment.IAlignment.STATES_COUNT;
|
||||
|
||||
public class AlignmentLimits implements IAlignmentLimits {
|
||||
|
||||
protected final boolean[] validStates=new boolean[STATES_COUNT];
|
||||
|
||||
public AlignmentLimits() {
|
||||
allowAll();
|
||||
}
|
||||
|
||||
AlignmentLimits allowAll(){
|
||||
Arrays.fill(validStates,true);
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits denyAll(){
|
||||
Arrays.fill(validStates,false);
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits randomAll(Random random){
|
||||
for (int i = 0; i < validStates.length; i++) {
|
||||
validStates[i]=random.nextBoolean();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits deny(ExtendedFacing... deny){
|
||||
if(deny!=null){
|
||||
for (ExtendedFacing extendedFacing : deny) {
|
||||
validStates[extendedFacing.getIndex()]=false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits allow(ExtendedFacing... allow){
|
||||
if(allow!=null){
|
||||
for (ExtendedFacing extendedFacing : allow) {
|
||||
validStates[extendedFacing.getIndex()]=false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits deny(ForgeDirection... deny){
|
||||
if(deny!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (ForgeDirection direction : deny) {
|
||||
if (value.getDirection() == direction) {
|
||||
validStates[value.getIndex()] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits allow(ForgeDirection... allow){
|
||||
if(allow!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (ForgeDirection direction : allow) {
|
||||
if (value.getDirection() == direction) {
|
||||
validStates[value.getIndex()] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits deny(Rotation... deny){
|
||||
if(deny!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (Rotation rotation : deny) {
|
||||
if (value.getRotation() == rotation) {
|
||||
validStates[value.getIndex()] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits allow(Rotation... allow){
|
||||
if(allow!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (Rotation rotation : allow) {
|
||||
if (value.getRotation() == rotation) {
|
||||
validStates[value.getIndex()] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits deny(Flip... deny){
|
||||
if(deny!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (Flip flip : deny) {
|
||||
if (value.getFlip() == flip) {
|
||||
validStates[value.getIndex()] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits allow(Flip... allow){
|
||||
if(allow!=null){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
for (Flip flip : allow) {
|
||||
if (value.getFlip() == flip) {
|
||||
validStates[value.getIndex()] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits predicateApply(Function<ExtendedFacing,Optional<Boolean>> predicate){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
predicate.apply(value).ifPresent(bool->validStates[value.getIndex()]=bool);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
AlignmentLimits ensureDuplicates(){
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
if(validStates[value.getIndex()]){
|
||||
validStates[value.getDuplicate().getIndex()]=true;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefers rotation over flip, so both flip will get translated to opposite rotation and no flip
|
||||
* @param flip the preferred flip to be used Horizontal or vertical
|
||||
* @return this
|
||||
*/
|
||||
AlignmentLimits ensureNoDuplicates(Flip flip){
|
||||
if(flip==Flip.BOTH||flip==Flip.NONE){
|
||||
throw new IllegalArgumentException("Preffered Flip must be Horizontal or Vertical");
|
||||
}
|
||||
flip=flip.getOpposite();
|
||||
for (ExtendedFacing value : ExtendedFacing.VALUES) {
|
||||
if(validStates[value.getIndex()]){
|
||||
if(value.getFlip()==Flip.BOTH || value.getFlip()==flip){
|
||||
validStates[value.getIndex()]=false;
|
||||
validStates[value.getDuplicate().getIndex()]=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip) {
|
||||
return validStates[IAlignment.getAlignmentIndex(direction,rotation,flip)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class AlignmentMessage implements IMessage {
|
||||
int mPosX;
|
||||
int mPosY;
|
||||
int mPosZ;
|
||||
int mPosD;
|
||||
int mAlign;
|
||||
|
||||
public AlignmentMessage() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf pBuffer) {
|
||||
NBTTagCompound tTag = ByteBufUtils.readTag(pBuffer);
|
||||
mPosX = tTag.getInteger("posx");
|
||||
mPosY = tTag.getInteger("posy");
|
||||
mPosZ = tTag.getInteger("posz");
|
||||
mPosD = tTag.getInteger("posd");
|
||||
mAlign = tTag.getInteger("rotf");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf pBuffer) {
|
||||
NBTTagCompound tFXTag = new NBTTagCompound();
|
||||
tFXTag.setInteger("posx", mPosX);
|
||||
tFXTag.setInteger("posy", mPosY);
|
||||
tFXTag.setInteger("posz", mPosZ);
|
||||
tFXTag.setInteger("posd", mPosD);
|
||||
tFXTag.setInteger("rotf", mAlign);
|
||||
|
||||
ByteBufUtils.writeTag(pBuffer, tFXTag);
|
||||
}
|
||||
/*
|
||||
private AlignmentMessage(GT_MetaTileEntity_MultiblockBase_EM metaTile) {
|
||||
IGregTechTileEntity base=metaTile.getBaseMetaTileEntity();
|
||||
mPosX=base.getXCoord();
|
||||
mPosY=base.getYCoord();
|
||||
mPosZ=base.getZCoord();
|
||||
mPosD=base.getWorld().provider.dimensionId;
|
||||
mAlign =metaTile.getExtendedFacing().getIndex();
|
||||
}
|
||||
|
||||
private AlignmentMessage(World world, int x, int y, int z, IAlignment front) {
|
||||
mPosX=x;
|
||||
mPosY=y;
|
||||
mPosZ=z;
|
||||
mPosD=world.provider.dimensionId;
|
||||
mAlign =front.getExtendedFacing().getIndex();
|
||||
}
|
||||
|
||||
public static class AlignmentQuery extends AlignmentMessage {
|
||||
public AlignmentQuery() {
|
||||
}
|
||||
|
||||
public AlignmentQuery(GT_MetaTileEntity_MultiblockBase_EM metaTile) {
|
||||
super(metaTile);
|
||||
}
|
||||
|
||||
public AlignmentQuery(World world, int x, int y, int z, IAlignment front) {
|
||||
super(world,x,y,z,front);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AlignmentData extends AlignmentMessage {
|
||||
public AlignmentData() {
|
||||
}
|
||||
|
||||
private AlignmentData(AlignmentQuery query){
|
||||
mPosX=query.mPosX;
|
||||
mPosY=query.mPosY;
|
||||
mPosZ=query.mPosZ;
|
||||
mPosD=query.mPosD;
|
||||
mAlign =query.mAlign;
|
||||
}
|
||||
|
||||
public AlignmentData(GT_MetaTileEntity_MultiblockBase_EM metaTile) {
|
||||
super(metaTile);
|
||||
}
|
||||
|
||||
public AlignmentData(World world, int x, int y, int z, IAlignment front) {
|
||||
super(world,x,y,z,front);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientHandler extends AbstractClientMessageHandler<AlignmentData> {
|
||||
@Override
|
||||
public IMessage handleClientMessage(EntityPlayer pPlayer, AlignmentData pMessage, MessageContext pCtx) {
|
||||
if(pPlayer.worldObj.provider.dimensionId==pMessage.mPosD){
|
||||
TileEntity te=pPlayer.worldObj.getTileEntity(pMessage.mPosX,pMessage.mPosY,pMessage.mPosZ);
|
||||
if(te instanceof IGregTechTileEntity){
|
||||
IMetaTileEntity meta = ((IGregTechTileEntity) te).getMetaTileEntity();
|
||||
if(meta instanceof IAlignment){
|
||||
((IAlignment) meta).setExtendedFacing(ExtendedFacing.byIndex(pMessage.mAlign));
|
||||
}
|
||||
}else if (te instanceof IAlignment){
|
||||
((IAlignment) te).setExtendedFacing(ExtendedFacing.byIndex(pMessage.mAlign));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerHandler extends AbstractServerMessageHandler<AlignmentQuery> {
|
||||
@Override
|
||||
public IMessage handleServerMessage(EntityPlayer pPlayer, AlignmentQuery pMessage, MessageContext pCtx) {
|
||||
World world= DimensionManager.getWorld(pMessage.mPosD);
|
||||
if(world!=null) {
|
||||
TileEntity te = world.getTileEntity(pMessage.mPosX, pMessage.mPosY, pMessage.mPosZ);
|
||||
if (te instanceof IGregTechTileEntity) {
|
||||
IMetaTileEntity meta = ((IGregTechTileEntity) te).getMetaTileEntity();
|
||||
if (meta instanceof IAlignment) {
|
||||
pMessage.mAlign =((IAlignment) meta).getExtendedFacing().getIndex();
|
||||
return new AlignmentData(pMessage);
|
||||
}
|
||||
} else if (te instanceof IAlignment) {
|
||||
pMessage.mAlign =((IAlignment) te).getExtendedFacing().getIndex();
|
||||
return new AlignmentData(pMessage);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
public class AlignmentUtility {
|
||||
private AlignmentUtility(){
|
||||
}
|
||||
|
||||
public static boolean handle(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ){
|
||||
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
|
||||
if(tTileEntity==null || aPlayer instanceof FakePlayer) {
|
||||
return aPlayer instanceof EntityPlayerMP;
|
||||
}
|
||||
if (aPlayer instanceof EntityPlayerMP) {
|
||||
/* TODO Make GT tile entity implement this interface and delegate all functionality to MTE
|
||||
if (tTileEntity instanceof IGregTechTileEntity) {
|
||||
IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
|
||||
if (metaTE instanceof IAlignmentProvider) {
|
||||
IAlignment alignment = ((IAlignmentProvider) metaTE).getAlignment();
|
||||
if(aPlayer.isSneaking()){
|
||||
alignment.toolSetFlip(null);
|
||||
}else {
|
||||
alignment.toolSetRotation(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else */ if (tTileEntity instanceof IAlignmentProvider) {
|
||||
IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment();
|
||||
if(aPlayer.isSneaking()){
|
||||
alignment.toolSetFlip(null);
|
||||
}else {
|
||||
alignment.toolSetRotation(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Direction;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
|
||||
int DIRECTIONS_COUNT= Direction.VALUES.length;
|
||||
int ROTATIONS_COUNT= Rotation.VALUES.length;
|
||||
int FLIPS_COUNT= Flip.VALUES.length;
|
||||
int STATES_COUNT = ExtendedFacing.VALUES.length;
|
||||
|
||||
ExtendedFacing getExtendedFacing();
|
||||
|
||||
void setExtendedFacing(ExtendedFacing alignment);
|
||||
|
||||
IAlignmentLimits getAlignmentLimits();
|
||||
|
||||
void setAlignmentLimits(IAlignmentLimits limits);
|
||||
|
||||
@Override
|
||||
default IAlignment getAlignment(){
|
||||
return this;
|
||||
}
|
||||
|
||||
static int getAlignmentIndex(ForgeDirection direction, Rotation rotation, Flip flip){
|
||||
return (direction.ordinal()*ROTATIONS_COUNT+rotation.getIndex())*FLIPS_COUNT+flip.getIndex();
|
||||
}
|
||||
|
||||
default ForgeDirection getDirection(){
|
||||
return getExtendedFacing().getDirection();
|
||||
}
|
||||
|
||||
default void setDirection(ForgeDirection direction){
|
||||
setExtendedFacing(getExtendedFacing().with(direction));
|
||||
}
|
||||
|
||||
default Rotation getRotation(){
|
||||
return getExtendedFacing().getRotation();
|
||||
}
|
||||
|
||||
default void setRotation(Rotation rotation){
|
||||
setExtendedFacing(getExtendedFacing().with(rotation));
|
||||
}
|
||||
|
||||
default Flip getFlip(){
|
||||
return getExtendedFacing().getFlip();
|
||||
}
|
||||
|
||||
default void setFlip(Flip flip){
|
||||
setExtendedFacing(getExtendedFacing().with(flip));
|
||||
}
|
||||
|
||||
default boolean toolSetDirection(ForgeDirection direction){
|
||||
if(direction==null || direction==ForgeDirection.UNKNOWN){
|
||||
for (int i = 0,j=getDirection().ordinal()+1, valuesLength = Direction.VALUES.length; i < valuesLength; i++) {
|
||||
if(toolSetDirection(Direction.VALUES[j%valuesLength].getForgeDirection())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) {
|
||||
if(checkedSetExtendedFacing(extendedFacing)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean checkedSetDirection(ForgeDirection direction){
|
||||
if (isNewDirectionValid(direction)){
|
||||
setDirection(direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean canSetToDirectionAny(ForgeDirection direction){
|
||||
for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) {
|
||||
if(isNewExtendedFacingValid(extendedFacing)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean toolSetRotation(Rotation rotation) {
|
||||
if(rotation==null){
|
||||
int flips = Flip.VALUES.length;
|
||||
int rotations = Rotation.VALUES.length;
|
||||
for (int ii = 0,jj=getFlip().ordinal(); ii < flips; ii++) {
|
||||
for (int i = 0,j=getRotation().ordinal()+1; i < rotations; i++) {
|
||||
if(checkedSetExtendedFacing(ExtendedFacing.of(getDirection(),Rotation.VALUES[j%rotations],Flip.VALUES[jj%flips]))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}else {
|
||||
return checkedSetRotation(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
default boolean checkedSetRotation(Rotation rotation){
|
||||
if (isNewRotationValid(rotation)){
|
||||
setRotation(rotation);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean toolSetFlip(Flip flip){
|
||||
if(flip==null){
|
||||
for (int i = 0,j=getFlip().ordinal()+1, valuesLength = Flip.VALUES.length; i < valuesLength; i++) {
|
||||
if(toolSetFlip(Flip.VALUES[j%valuesLength])){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}else {
|
||||
return checkedSetFlip(flip);
|
||||
}
|
||||
}
|
||||
|
||||
default boolean checkedSetFlip(Flip flip){
|
||||
if (isNewFlipValid(flip)){
|
||||
setFlip(flip);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean toolSetExtendedFacing(ExtendedFacing extendedFacing){
|
||||
if(extendedFacing==null){
|
||||
for (int i = 0,j=getExtendedFacing().ordinal()+1, valuesLength = ExtendedFacing.VALUES.length; i < valuesLength; i++) {
|
||||
if(toolSetExtendedFacing(ExtendedFacing.VALUES[j%valuesLength])){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}else {
|
||||
return checkedSetExtendedFacing(extendedFacing);
|
||||
}
|
||||
}
|
||||
|
||||
default boolean checkedSetExtendedFacing(ExtendedFacing alignment){
|
||||
if (isNewExtendedFacingValid(alignment)){
|
||||
setExtendedFacing(alignment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isNewDirectionValid(ForgeDirection direction) {
|
||||
return isNewExtendedFacingValid(direction,getRotation(),getFlip());
|
||||
}
|
||||
|
||||
default boolean isNewRotationValid(Rotation rotation){
|
||||
return isNewExtendedFacingValid(getDirection(),rotation,getFlip());
|
||||
}
|
||||
|
||||
default boolean isNewFlipValid(Flip flip){
|
||||
return isNewExtendedFacingValid(getDirection(),getRotation(),flip);
|
||||
}
|
||||
|
||||
default boolean isExtendedFacingValid() {
|
||||
return isNewExtendedFacingValid(getDirection(),getRotation(),getFlip());
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip){
|
||||
return getAlignmentLimits().isNewExtendedFacingValid(direction, rotation, flip);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean isNewExtendedFacingValid(ExtendedFacing alignment){
|
||||
return getAlignmentLimits().isNewExtendedFacingValid(
|
||||
alignment.getDirection(),
|
||||
alignment.getRotation(),
|
||||
alignment.getFlip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IAlignmentLimits {
|
||||
|
||||
IAlignmentLimits UNLIMITED= (direction, rotation, flip) -> true;
|
||||
|
||||
boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip);
|
||||
|
||||
default boolean isNewExtendedFacingValid(ExtendedFacing alignment){
|
||||
return isNewExtendedFacingValid(
|
||||
alignment.getDirection(),
|
||||
alignment.getRotation(),
|
||||
alignment.getFlip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
public interface IAlignmentProvider {
|
||||
IAlignment getAlignment();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.gtnewhorizon.structurelib.alignment;
|
||||
|
||||
import com.gtnewhorizon.structurelib.util.Vec3Impl;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.Direction;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
public class IntegerAxisSwap {
|
||||
private final Vec3Impl forFirstAxis;
|
||||
private final Vec3Impl forSecondAxis;
|
||||
private final Vec3Impl forThirdAxis;
|
||||
|
||||
public IntegerAxisSwap(ForgeDirection forFirstAxis, ForgeDirection forSecondAxis, ForgeDirection forThirdAxis) {
|
||||
this.forFirstAxis = Direction.getAxisVector(forFirstAxis);
|
||||
this.forSecondAxis = Direction.getAxisVector(forSecondAxis);
|
||||
this.forThirdAxis = Direction.getAxisVector(forThirdAxis);
|
||||
if(abs(this.forFirstAxis.get0())+abs(this.forSecondAxis.get0())+abs(this.forThirdAxis.get0())!=1 ||
|
||||
abs(this.forFirstAxis.get1())+abs(this.forSecondAxis.get1())+abs(this.forThirdAxis.get1())!=1 ||
|
||||
abs(this.forFirstAxis.get2())+abs(this.forSecondAxis.get2())+abs(this.forThirdAxis.get2())!=1){
|
||||
throw new IllegalArgumentException("Axis are overlapping/missing! "+
|
||||
forFirstAxis.name()+" "+
|
||||
forSecondAxis.name()+" "+
|
||||
forThirdAxis.name());
|
||||
}
|
||||
}
|
||||
|
||||
public Vec3Impl translate(Vec3Impl point){
|
||||
return new Vec3Impl(
|
||||
forFirstAxis.get0()*point.get0() +forFirstAxis.get1()*point.get1() +forFirstAxis.get2()*point.get2(),
|
||||
forSecondAxis.get0()*point.get0()+forSecondAxis.get1()*point.get1()+forSecondAxis.get2()*point.get2(),
|
||||
forThirdAxis.get0()*point.get0() +forThirdAxis.get1()*point.get1() +forThirdAxis.get2()*point.get2()
|
||||
);
|
||||
}
|
||||
|
||||
public Vec3Impl inverseTranslate(Vec3Impl point){
|
||||
return new Vec3Impl(
|
||||
forFirstAxis.get0()*point.get0()+forSecondAxis.get0()*point.get1()+forThirdAxis.get0()*point.get2(),
|
||||
forFirstAxis.get1()*point.get0()+forSecondAxis.get1()*point.get1()+forThirdAxis.get1()*point.get2(),
|
||||
forFirstAxis.get2()*point.get0()+forSecondAxis.get2()*point.get1()+forThirdAxis.get2()*point.get2()
|
||||
);
|
||||
}
|
||||
|
||||
public Vec3 translate(Vec3 point){
|
||||
return Vec3.createVectorHelper(
|
||||
forFirstAxis.get0()*point.xCoord +forFirstAxis.get1()*point.yCoord +forFirstAxis.get2()*point.zCoord,
|
||||
forSecondAxis.get0()*point.xCoord+forSecondAxis.get1()*point.yCoord+forSecondAxis.get2()*point.zCoord,
|
||||
forThirdAxis.get0()*point.xCoord +forThirdAxis.get1()*point.yCoord +forThirdAxis.get2()*point.zCoord
|
||||
);
|
||||
}
|
||||
|
||||
public Vec3 inverseTranslate(Vec3 point){
|
||||
return Vec3.createVectorHelper(
|
||||
forFirstAxis.get0()*point.xCoord+forSecondAxis.get0()*point.yCoord+forThirdAxis.get0()*point.zCoord,
|
||||
forFirstAxis.get1()*point.xCoord+forSecondAxis.get1()*point.yCoord+forThirdAxis.get1()*point.zCoord,
|
||||
forFirstAxis.get2()*point.xCoord+forSecondAxis.get2()*point.yCoord+forThirdAxis.get2()*point.zCoord
|
||||
);
|
||||
}
|
||||
|
||||
public void translate(int[] point,int[] out){
|
||||
out[0]=forFirstAxis.get0()*point[0] +forFirstAxis.get1()*point[1] +forFirstAxis.get2()*point[2];
|
||||
out[1]=forSecondAxis.get0()*point[0]+forSecondAxis.get1()*point[1]+forSecondAxis.get2()*point[2];
|
||||
out[2]=forThirdAxis.get0()*point[0] +forThirdAxis.get1()*point[1] +forThirdAxis.get2()*point[2];
|
||||
}
|
||||
|
||||
public void inverseTranslate(int[] point,int[] out){
|
||||
out[0]=forFirstAxis.get0()*point[0]+forSecondAxis.get0()*point[1]+forThirdAxis.get0()*point[2];
|
||||
out[1]=forFirstAxis.get1()*point[0]+forSecondAxis.get1()*point[1]+forThirdAxis.get1()*point[2];
|
||||
out[2]=forFirstAxis.get2()*point[0]+forSecondAxis.get2()*point[1]+forThirdAxis.get2()*point[2];
|
||||
}
|
||||
|
||||
public void translate(double[] point,double[] out){
|
||||
out[0]=forFirstAxis.get0()*point[0] +forFirstAxis.get1()*point[1] +forFirstAxis.get2()*point[2];
|
||||
out[1]=forSecondAxis.get0()*point[0]+forSecondAxis.get1()*point[1]+forSecondAxis.get2()*point[2];
|
||||
out[2]=forThirdAxis.get0()*point[0] +forThirdAxis.get1()*point[1] +forThirdAxis.get2()*point[2];
|
||||
}
|
||||
|
||||
public void inverseTranslate(double[] point,double[] out){
|
||||
out[0]=forFirstAxis.get0()*point[0]+forSecondAxis.get0()*point[1]+forThirdAxis.get0()*point[2];
|
||||
out[1]=forFirstAxis.get1()*point[0]+forSecondAxis.get1()*point[1]+forThirdAxis.get1()*point[2];
|
||||
out[2]=forFirstAxis.get2()*point[0]+forSecondAxis.get2()*point[1]+forThirdAxis.get2()*point[2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.enumerable;
|
||||
|
||||
import com.gtnewhorizon.structurelib.util.Vec3Impl;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public enum Direction {
|
||||
DOWN(ForgeDirection.DOWN),
|
||||
UP(ForgeDirection.UP),
|
||||
NORTH(ForgeDirection.NORTH),
|
||||
SOUTH(ForgeDirection.SOUTH),
|
||||
WEST(ForgeDirection.WEST),
|
||||
EAST(ForgeDirection.EAST);
|
||||
|
||||
private final ForgeDirection forgeDirection;
|
||||
private final Vec3Impl axisVector;
|
||||
public static final Direction[] VALUES=values();
|
||||
|
||||
Direction(ForgeDirection forgeDirection) {
|
||||
this.forgeDirection = forgeDirection;
|
||||
axisVector=new Vec3Impl(forgeDirection.offsetX,forgeDirection.offsetY,forgeDirection.offsetZ);
|
||||
}
|
||||
|
||||
public ForgeDirection getForgeDirection() {
|
||||
return forgeDirection;
|
||||
}
|
||||
|
||||
public Vec3Impl getAxisVector() {
|
||||
return axisVector;
|
||||
}
|
||||
|
||||
public static Vec3Impl getAxisVector(ForgeDirection forgeDirection){
|
||||
return VALUES[forgeDirection.ordinal()].axisVector;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.enumerable;
|
||||
|
||||
import com.gtnewhorizon.structurelib.alignment.IAlignment;
|
||||
import com.gtnewhorizon.structurelib.alignment.IntegerAxisSwap;
|
||||
import com.gtnewhorizon.structurelib.util.Vec3Impl;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.gtnewhorizon.structurelib.alignment.IAlignment.FLIPS_COUNT;
|
||||
import static com.gtnewhorizon.structurelib.alignment.IAlignment.ROTATIONS_COUNT;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public enum ExtendedFacing {
|
||||
DOWN_NORMAL_NONE("down normal none"),
|
||||
DOWN_NORMAL_HORIZONTAL("down normal horizontal"),
|
||||
DOWN_NORMAL_VERTICAL("down normal vertical"),
|
||||
DOWN_NORMAL_BOTH("down normal both"),
|
||||
DOWN_CLOCKWISE_NONE("down clockwise none"),
|
||||
DOWN_CLOCKWISE_HORIZONTAL("down clockwise horizontal"),
|
||||
DOWN_CLOCKWISE_VERTICAL("down clockwise vertical"),
|
||||
DOWN_CLOCKWISE_BOTH("down clockwise both"),
|
||||
DOWN_UPSIDE_DOWN_NONE("down upside down none"),
|
||||
DOWN_UPSIDE_DOWN_HORIZONTAL("down upside down horizontal"),
|
||||
DOWN_UPSIDE_DOWN_VERTICAL("down upside down vertical"),
|
||||
DOWN_UPSIDE_DOWN_BOTH("down upside down both"),
|
||||
DOWN_COUNTER_CLOCKWISE_NONE("down counter clockwise none"),
|
||||
DOWN_COUNTER_CLOCKWISE_HORIZONTAL("down counter clockwise horizontal"),
|
||||
DOWN_COUNTER_CLOCKWISE_VERTICAL("down counter clockwise vertical"),
|
||||
DOWN_COUNTER_CLOCKWISE_BOTH("down counter clockwise both"),
|
||||
UP_NORMAL_NONE("up normal none"),
|
||||
UP_NORMAL_HORIZONTAL("up normal horizontal"),
|
||||
UP_NORMAL_VERTICAL("up normal vertical"),
|
||||
UP_NORMAL_BOTH("up normal both"),
|
||||
UP_CLOCKWISE_NONE("up clockwise none"),
|
||||
UP_CLOCKWISE_HORIZONTAL("up clockwise horizontal"),
|
||||
UP_CLOCKWISE_VERTICAL("up clockwise vertical"),
|
||||
UP_CLOCKWISE_BOTH("up clockwise both"),
|
||||
UP_UPSIDE_DOWN_NONE("up upside down none"),
|
||||
UP_UPSIDE_DOWN_HORIZONTAL("up upside down horizontal"),
|
||||
UP_UPSIDE_DOWN_VERTICAL("up upside down vertical"),
|
||||
UP_UPSIDE_DOWN_BOTH("up upside down both"),
|
||||
UP_COUNTER_CLOCKWISE_NONE("up counter clockwise none"),
|
||||
UP_COUNTER_CLOCKWISE_HORIZONTAL("up counter clockwise horizontal"),
|
||||
UP_COUNTER_CLOCKWISE_VERTICAL("up counter clockwise vertical"),
|
||||
UP_COUNTER_CLOCKWISE_BOTH("up counter clockwise both"),
|
||||
NORTH_NORMAL_NONE("north normal none"),
|
||||
NORTH_NORMAL_HORIZONTAL("north normal horizontal"),
|
||||
NORTH_NORMAL_VERTICAL("north normal vertical"),
|
||||
NORTH_NORMAL_BOTH("north normal both"),
|
||||
NORTH_CLOCKWISE_NONE("north clockwise none"),
|
||||
NORTH_CLOCKWISE_HORIZONTAL("north clockwise horizontal"),
|
||||
NORTH_CLOCKWISE_VERTICAL("north clockwise vertical"),
|
||||
NORTH_CLOCKWISE_BOTH("north clockwise both"),
|
||||
NORTH_UPSIDE_DOWN_NONE("north upside down none"),
|
||||
NORTH_UPSIDE_DOWN_HORIZONTAL("north upside down horizontal"),
|
||||
NORTH_UPSIDE_DOWN_VERTICAL("north upside down vertical"),
|
||||
NORTH_UPSIDE_DOWN_BOTH("north upside down both"),
|
||||
NORTH_COUNTER_CLOCKWISE_NONE("north counter clockwise none"),
|
||||
NORTH_COUNTER_CLOCKWISE_HORIZONTAL("north counter clockwise horizontal"),
|
||||
NORTH_COUNTER_CLOCKWISE_VERTICAL("north counter clockwise vertical"),
|
||||
NORTH_COUNTER_CLOCKWISE_BOTH("north counter clockwise both"),
|
||||
SOUTH_NORMAL_NONE("south normal none"),
|
||||
SOUTH_NORMAL_HORIZONTAL("south normal horizontal"),
|
||||
SOUTH_NORMAL_VERTICAL("south normal vertical"),
|
||||
SOUTH_NORMAL_BOTH("south normal both"),
|
||||
SOUTH_CLOCKWISE_NONE("south clockwise none"),
|
||||
SOUTH_CLOCKWISE_HORIZONTAL("south clockwise horizontal"),
|
||||
SOUTH_CLOCKWISE_VERTICAL("south clockwise vertical"),
|
||||
SOUTH_CLOCKWISE_BOTH("south clockwise both"),
|
||||
SOUTH_UPSIDE_DOWN_NONE("south upside down none"),
|
||||
SOUTH_UPSIDE_DOWN_HORIZONTAL("south upside down horizontal"),
|
||||
SOUTH_UPSIDE_DOWN_VERTICAL("south upside down vertical"),
|
||||
SOUTH_UPSIDE_DOWN_BOTH("south upside down both"),
|
||||
SOUTH_COUNTER_CLOCKWISE_NONE("south counter clockwise none"),
|
||||
SOUTH_COUNTER_CLOCKWISE_HORIZONTAL("south counter clockwise horizontal"),
|
||||
SOUTH_COUNTER_CLOCKWISE_VERTICAL("south counter clockwise vertical"),
|
||||
SOUTH_COUNTER_CLOCKWISE_BOTH("south counter clockwise both"),
|
||||
WEST_NORMAL_NONE("west normal none"),
|
||||
WEST_NORMAL_HORIZONTAL("west normal horizontal"),
|
||||
WEST_NORMAL_VERTICAL("west normal vertical"),
|
||||
WEST_NORMAL_BOTH("west normal both"),
|
||||
WEST_CLOCKWISE_NONE("west clockwise none"),
|
||||
WEST_CLOCKWISE_HORIZONTAL("west clockwise horizontal"),
|
||||
WEST_CLOCKWISE_VERTICAL("west clockwise vertical"),
|
||||
WEST_CLOCKWISE_BOTH("west clockwise both"),
|
||||
WEST_UPSIDE_DOWN_NONE("west upside down none"),
|
||||
WEST_UPSIDE_DOWN_HORIZONTAL("west upside down horizontal"),
|
||||
WEST_UPSIDE_DOWN_VERTICAL("west upside down vertical"),
|
||||
WEST_UPSIDE_DOWN_BOTH("west upside down both"),
|
||||
WEST_COUNTER_CLOCKWISE_NONE("west counter clockwise none"),
|
||||
WEST_COUNTER_CLOCKWISE_HORIZONTAL("west counter clockwise horizontal"),
|
||||
WEST_COUNTER_CLOCKWISE_VERTICAL("west counter clockwise vertical"),
|
||||
WEST_COUNTER_CLOCKWISE_BOTH("west counter clockwise both"),
|
||||
EAST_NORMAL_NONE("east normal none"),
|
||||
EAST_NORMAL_HORIZONTAL("east normal horizontal"),
|
||||
EAST_NORMAL_VERTICAL("east normal vertical"),
|
||||
EAST_NORMAL_BOTH("east normal both"),
|
||||
EAST_CLOCKWISE_NONE("east clockwise none"),
|
||||
EAST_CLOCKWISE_HORIZONTAL("east clockwise horizontal"),
|
||||
EAST_CLOCKWISE_VERTICAL("east clockwise vertical"),
|
||||
EAST_CLOCKWISE_BOTH("east clockwise both"),
|
||||
EAST_UPSIDE_DOWN_NONE("east upside down none"),
|
||||
EAST_UPSIDE_DOWN_HORIZONTAL("east upside down horizontal"),
|
||||
EAST_UPSIDE_DOWN_VERTICAL("east upside down vertical"),
|
||||
EAST_UPSIDE_DOWN_BOTH("east upside down both"),
|
||||
EAST_COUNTER_CLOCKWISE_NONE("east counter clockwise none"),
|
||||
EAST_COUNTER_CLOCKWISE_HORIZONTAL("east counter clockwise horizontal"),
|
||||
EAST_COUNTER_CLOCKWISE_VERTICAL("east counter clockwise vertical"),
|
||||
EAST_COUNTER_CLOCKWISE_BOTH("east counter clockwise both");
|
||||
|
||||
public static final ExtendedFacing DEFAULT=NORTH_NORMAL_NONE;
|
||||
public static final ExtendedFacing[] VALUES = values();
|
||||
public static final Map<ForgeDirection, List<ExtendedFacing>> FOR_FACING=new HashMap<>();
|
||||
static {
|
||||
stream(values()).forEach(extendedFacing ->
|
||||
FOR_FACING.compute(extendedFacing.direction,((forgeDirection, extendedFacings) -> {
|
||||
if(extendedFacings==null){
|
||||
extendedFacings = new ArrayList<>();
|
||||
}
|
||||
extendedFacings.add(extendedFacing);
|
||||
return extendedFacings;
|
||||
})));
|
||||
}
|
||||
private static final Map<String, ExtendedFacing> NAME_LOOKUP = stream(VALUES).collect(toMap(ExtendedFacing::getName2, (extendedFacing) -> extendedFacing));
|
||||
|
||||
private final ForgeDirection direction;
|
||||
private final ForgeDirection a,b,c;
|
||||
private final Rotation rotation;
|
||||
private final Flip flip;
|
||||
|
||||
private final String name;
|
||||
private final IntegerAxisSwap integerAxisSwap;
|
||||
|
||||
ExtendedFacing(String name) {
|
||||
this.name = name;
|
||||
direction= Direction.VALUES[ordinal()/(ROTATIONS_COUNT*FLIPS_COUNT)].getForgeDirection();
|
||||
rotation=Rotation.VALUES[ordinal()/FLIPS_COUNT-direction.ordinal()*ROTATIONS_COUNT];
|
||||
flip=Flip.VALUES[ordinal()%FLIPS_COUNT];
|
||||
ForgeDirection a,b,c;
|
||||
switch (direction){
|
||||
case DOWN:
|
||||
a= ForgeDirection.WEST;
|
||||
b= ForgeDirection.SOUTH;
|
||||
c= ForgeDirection.UP;
|
||||
break;
|
||||
case UP:
|
||||
a= ForgeDirection.EAST;
|
||||
b= ForgeDirection.SOUTH;
|
||||
c= ForgeDirection.DOWN;
|
||||
break;
|
||||
case NORTH:
|
||||
a= ForgeDirection.WEST;
|
||||
b= ForgeDirection.DOWN;
|
||||
c= ForgeDirection.SOUTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
a= ForgeDirection.EAST;
|
||||
b= ForgeDirection.DOWN;
|
||||
c= ForgeDirection.NORTH;
|
||||
break;
|
||||
case WEST:
|
||||
a= ForgeDirection.SOUTH;
|
||||
b= ForgeDirection.DOWN;
|
||||
c= ForgeDirection.EAST;
|
||||
break;
|
||||
case EAST:
|
||||
a= ForgeDirection.NORTH;
|
||||
b= ForgeDirection.DOWN;
|
||||
c= ForgeDirection.WEST;
|
||||
break;
|
||||
default:throw new RuntimeException("Is impossible...");
|
||||
}
|
||||
switch (flip){//This duplicates some axis swaps since flip boolean would do, but seems more convenient to use
|
||||
case HORIZONTAL:
|
||||
a=a.getOpposite();
|
||||
break;
|
||||
case BOTH:
|
||||
a=a.getOpposite();
|
||||
case VERTICAL:
|
||||
b=b.getOpposite();
|
||||
break;
|
||||
case NONE: break;
|
||||
default:throw new RuntimeException("Even more impossible...");
|
||||
}
|
||||
switch (rotation) {
|
||||
case CLOCKWISE: {
|
||||
ForgeDirection _a=a;
|
||||
a =b;
|
||||
b =_a.getOpposite();
|
||||
break;
|
||||
}
|
||||
case UPSIDE_DOWN:
|
||||
a=a.getOpposite();
|
||||
b=b.getOpposite();
|
||||
break;
|
||||
case COUNTER_CLOCKWISE: {
|
||||
ForgeDirection _a=a;
|
||||
a =b.getOpposite();
|
||||
b =_a;
|
||||
break;
|
||||
}
|
||||
case NORMAL: break;
|
||||
default:
|
||||
throw new RuntimeException("More impossible...");
|
||||
}
|
||||
this.a=a;
|
||||
this.b=b;
|
||||
this.c=c;
|
||||
integerAxisSwap =new IntegerAxisSwap(a,b,c);
|
||||
}
|
||||
|
||||
public static ExtendedFacing of(ForgeDirection direction, Rotation rotation, Flip flip){
|
||||
if(direction==ForgeDirection.UNKNOWN){
|
||||
return VALUES[IAlignment.getAlignmentIndex(ForgeDirection.NORTH, rotation, flip)];
|
||||
}
|
||||
return VALUES[IAlignment.getAlignmentIndex(direction, rotation, flip)];
|
||||
}
|
||||
|
||||
public static ExtendedFacing of(ForgeDirection direction){
|
||||
if(direction==ForgeDirection.UNKNOWN){
|
||||
return DEFAULT;
|
||||
}
|
||||
return VALUES[IAlignment.getAlignmentIndex(direction, Rotation.NORMAL, Flip.NONE)];
|
||||
}
|
||||
|
||||
public ExtendedFacing with(ForgeDirection direction){
|
||||
return of(direction,rotation,flip);
|
||||
}
|
||||
|
||||
public ExtendedFacing with(Rotation rotation){
|
||||
return of(direction,rotation,flip);
|
||||
}
|
||||
|
||||
public ExtendedFacing with(Flip flip){
|
||||
return of(direction,rotation,flip);
|
||||
}
|
||||
|
||||
public ExtendedFacing getOppositeDirection() {
|
||||
return of(direction.getOpposite(),rotation,flip);
|
||||
}
|
||||
|
||||
public ExtendedFacing getOppositeRotation() {
|
||||
return of(direction,rotation.getOpposite(),flip);
|
||||
}
|
||||
|
||||
public ExtendedFacing getOppositeFlip() {
|
||||
return of(direction,rotation,flip.getOpposite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the same effective facing achieved by different rot/flip combo
|
||||
* @return same effective facing, but different enum value
|
||||
*/
|
||||
public ExtendedFacing getDuplicate(){
|
||||
return of(direction,rotation.getOpposite(),flip.getOpposite());
|
||||
}
|
||||
|
||||
public int getIndex(){
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public String getName2() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static ExtendedFacing byName(String name) {
|
||||
return name == null ? null : NAME_LOOKUP.get(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static ExtendedFacing byIndex(int index) {
|
||||
return VALUES[abs(index % VALUES.length)];
|
||||
}
|
||||
|
||||
public static ExtendedFacing random(Random rand) {
|
||||
return VALUES[rand.nextInt(VALUES.length)];
|
||||
}
|
||||
|
||||
public ForgeDirection getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public Rotation getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public Flip getFlip() {
|
||||
return flip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates relative to front facing offset to world offset
|
||||
* @param abcOffset A,B,C offset (facing relative L-->R,U-->D,F-->B)
|
||||
* @return X,Y,Z offset in world
|
||||
*/
|
||||
public Vec3 getWorldOffset(Vec3 abcOffset) {
|
||||
return integerAxisSwap.inverseTranslate(abcOffset);
|
||||
}
|
||||
public Vec3Impl getWorldOffset(Vec3Impl abcOffset) {
|
||||
return integerAxisSwap.inverseTranslate(abcOffset);
|
||||
}
|
||||
public void getWorldOffset(int[] point,int[] out){
|
||||
integerAxisSwap.inverseTranslate(point,out);
|
||||
}
|
||||
public void getWorldOffset(double[] point,double[] out){
|
||||
integerAxisSwap.inverseTranslate(point,out);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates world offset to relative front facing offset
|
||||
* @param xyzOffset X,Y,Z offset in world
|
||||
* @return A,B,C offset (facing relative L-->R,U-->D,F-->B)
|
||||
*/
|
||||
public Vec3 getOffsetABC(Vec3 xyzOffset){
|
||||
return integerAxisSwap.translate(xyzOffset);
|
||||
}
|
||||
public Vec3Impl getOffsetABC(Vec3Impl xyzOffset){
|
||||
return integerAxisSwap.translate(xyzOffset);
|
||||
}
|
||||
public void getOffsetABC(int[] point,int[] out){
|
||||
integerAxisSwap.translate(point,out);
|
||||
}
|
||||
public void getOffsetABC(double[] point,double[] out){
|
||||
integerAxisSwap.translate(point,out);
|
||||
}
|
||||
|
||||
public IntegerAxisSwap getIntegerAxisSwap() {
|
||||
return integerAxisSwap;
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeLeftInWorld() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeRightInWorld() {
|
||||
return a.getOpposite();
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeDownInWorld() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeUpInWorld() {
|
||||
return b.getOpposite();
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeBackInWorld() {
|
||||
return c;
|
||||
}
|
||||
|
||||
public ForgeDirection getRelativeForwardInWorld() {
|
||||
return c.getOpposite();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.enumerable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public enum Flip {
|
||||
NONE(3, "none"),
|
||||
HORIZONTAL(2, "horizontal"),
|
||||
VERTICAL(1, "vertical"),
|
||||
BOTH(0, "both");
|
||||
|
||||
private final int opposite;
|
||||
private final String name;
|
||||
|
||||
public static final Flip[] VALUES = values();
|
||||
private static final Map<String, Flip> NAME_LOOKUP = stream(VALUES).collect(toMap(Flip::getName2, (flip) -> flip));
|
||||
|
||||
Flip(int oppositeIn, String nameIn) {
|
||||
this.opposite = oppositeIn;
|
||||
this.name = nameIn;
|
||||
}
|
||||
|
||||
public int getIndex(){
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public Flip getOpposite() {
|
||||
return VALUES[opposite];
|
||||
}
|
||||
|
||||
public String getName2() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static Flip byName(String name) {
|
||||
return name == null ? null : NAME_LOOKUP.get(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static Flip byIndex(int index) {
|
||||
return VALUES[abs(index % VALUES.length)];
|
||||
}
|
||||
|
||||
public static Flip random(@Nonnull Random rand) {
|
||||
return VALUES[rand.nextInt(VALUES.length)];
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isNotFlipped(){
|
||||
return this==NONE;
|
||||
}
|
||||
|
||||
public boolean isBothFlipped(){
|
||||
return this==BOTH;
|
||||
}
|
||||
|
||||
public boolean isHorizontallyFlipped() {
|
||||
return this==HORIZONTAL || isBothFlipped();
|
||||
}
|
||||
|
||||
public boolean isVerticallyFliped() {
|
||||
return this==VERTICAL || isBothFlipped();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.enumerable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public enum Rotation {
|
||||
NORMAL(2, "normal"),
|
||||
CLOCKWISE(3, "clockwise"),
|
||||
UPSIDE_DOWN(0, "upside down"),
|
||||
COUNTER_CLOCKWISE(1, "counter clockwise");
|
||||
|
||||
private final int opposite;
|
||||
private final String name;
|
||||
|
||||
public static final Rotation[] VALUES = values();
|
||||
private static final Map<String, Rotation> NAME_LOOKUP = stream(VALUES).collect(toMap(Rotation::getName2, (rotation) -> rotation));
|
||||
|
||||
Rotation(int oppositeIn, String nameIn) {
|
||||
this.opposite = oppositeIn;
|
||||
this.name = nameIn;
|
||||
}
|
||||
|
||||
public int getIndex(){
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public Rotation getOpposite() {
|
||||
return VALUES[opposite];
|
||||
}
|
||||
|
||||
public String getName2() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static Rotation byName(String name) {
|
||||
return name == null ? null : NAME_LOOKUP.get(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static Rotation byIndex(int index) {
|
||||
return VALUES[abs(index % VALUES.length)];
|
||||
}
|
||||
|
||||
public static Rotation random(@Nonnull Random rand) {
|
||||
return VALUES[rand.nextInt(VALUES.length)];
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isNotRotated(){
|
||||
return this==NORMAL;
|
||||
}
|
||||
|
||||
public boolean isClockwise(){
|
||||
return this==CLOCKWISE;
|
||||
}
|
||||
|
||||
public boolean isCounterClockwise(){
|
||||
return this==COUNTER_CLOCKWISE;
|
||||
}
|
||||
|
||||
public boolean isUpsideDown(){
|
||||
return this==UPSIDE_DOWN;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user