reformat project according to .editorconfig

Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
This commit is contained in:
Glease committed 2022-07-08 17:14:18 +08:00
1 parent 33d377cea7
commit 8de7026a00
36 files changed
+2507 -2467

No files matched your search

@@ -18,8 +18,8 @@ public class GuiModConfig extends GuiConfig {
private static List<IConfigElement> getConfigElements() {
final Configuration config = ConfigurationHandler.INSTANCE.getConfig();
return config.getCategoryNames().stream()
.filter(name -> name.indexOf('.') == -1)
.map(name -> new ConfigElement(config.getCategory(name)))
.collect(Collectors.toList());
.filter(name -> name.indexOf('.') == -1)
.map(name -> new ConfigElement(config.getCategory(name)))
.collect(Collectors.toList());
}
}
@@ -28,51 +28,51 @@ import org.apache.logging.log4j.Logger;
*/
@Mod(modid = StructureLibAPI.MOD_ID, name = "StructureLib", version = "GRADLETOKEN_VERSION", acceptableRemoteVersions = "*", guiFactory = "com.gtnewhorizon.structurelib.GuiFactory")
public class StructureLib {
public static boolean DEBUG_MODE = Boolean.getBoolean("structurelib.debug");
public static Logger LOGGER = LogManager.getLogger("StructureLib");
public static boolean DEBUG_MODE = Boolean.getBoolean("structurelib.debug");
public static Logger LOGGER = LogManager.getLogger("StructureLib");
@SidedProxy(serverSide = "com.gtnewhorizon.structurelib.proxy.CommonProxy", clientSide = "com.gtnewhorizon.structurelib.proxy.ClientProxy")
static CommonProxy proxy;
static SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID);
@SidedProxy(serverSide = "com.gtnewhorizon.structurelib.proxy.CommonProxy", clientSide = "com.gtnewhorizon.structurelib.proxy.ClientProxy")
static CommonProxy proxy;
static SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID);
static {
net.registerMessage(AlignmentMessage.ServerHandler.class, AlignmentMessage.AlignmentQuery.class, 0, Side.SERVER);
net.registerMessage(AlignmentMessage.ClientHandler.class, AlignmentMessage.AlignmentData.class, 1, Side.CLIENT);
}
static {
net.registerMessage(AlignmentMessage.ServerHandler.class, AlignmentMessage.AlignmentQuery.class, 0, Side.SERVER);
net.registerMessage(AlignmentMessage.ClientHandler.class, AlignmentMessage.AlignmentData.class, 1, Side.CLIENT);
}
public static final XSTR RANDOM = new XSTR();
public static final XSTR RANDOM = new XSTR();
static Block blockHint;
static Item itemBlockHint;
static Item itemFrontRotationTool;
static Item itemConstructableTrigger;
public static final CreativeTabs creativeTab = new CreativeTabs("structurelib") {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return StructureLibAPI.getItemBlockHint();
}
};
static Block blockHint;
static Item itemBlockHint;
static Item itemFrontRotationTool;
static Item itemConstructableTrigger;
public static final CreativeTabs creativeTab = new CreativeTabs("structurelib") {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return StructureLibAPI.getItemBlockHint();
}
};
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile());
GameRegistry.registerBlock(blockHint = new BlockHint(), ItemBlockHint.class, "blockhint");
itemBlockHint = ItemBlock.getItemFromBlock(StructureLibAPI.getBlockHint());
GameRegistry.registerItem(itemFrontRotationTool = new ItemFrontRotationTool(), itemFrontRotationTool.getUnlocalizedName());
GameRegistry.registerItem(itemConstructableTrigger = new ItemConstructableTrigger(), itemConstructableTrigger.getUnlocalizedName());
proxy.preInit(e);
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile());
GameRegistry.registerBlock(blockHint = new BlockHint(), ItemBlockHint.class, "blockhint");
itemBlockHint = ItemBlock.getItemFromBlock(StructureLibAPI.getBlockHint());
GameRegistry.registerItem(itemFrontRotationTool = new ItemFrontRotationTool(), itemFrontRotationTool.getUnlocalizedName());
GameRegistry.registerItem(itemConstructableTrigger = new ItemConstructableTrigger(), itemConstructableTrigger.getUnlocalizedName());
proxy.preInit(e);
}
public static void addClientSideChatMessages(String... messages) {
proxy.addClientSideChatMessages(messages);
}
public static void addClientSideChatMessages(String... messages) {
proxy.addClientSideChatMessages(messages);
}
public static EntityPlayer getCurrentPlayer() {
return proxy.getCurrentPlayer();
}
public static EntityPlayer getCurrentPlayer() {
return proxy.getCurrentPlayer();
}
public static boolean isCurrentPlayer(EntityPlayer player) {
return proxy.isCurrentPlayer(player);
}
public static boolean isCurrentPlayer(EntityPlayer player) {
return proxy.isCurrentPlayer(player);
}
}
@@ -18,114 +18,119 @@ import static com.gtnewhorizon.structurelib.StructureLib.proxy;
* A stable interface into the structure lib's internals. Backwards compatibility is maintained to the maximum extend possible.
*/
public class StructureLibAPI {
public static final String MOD_ID = "structurelib";
public static final int HINT_BLOCK_META_GENERIC_0 = 0;
public static final int HINT_BLOCK_META_GENERIC_1 = 1;
public static final int HINT_BLOCK_META_GENERIC_2 = 2;
public static final int HINT_BLOCK_META_GENERIC_3 = 3;
public static final int HINT_BLOCK_META_GENERIC_4 = 4;
public static final int HINT_BLOCK_META_GENERIC_5 = 5;
public static final int HINT_BLOCK_META_GENERIC_6 = 6;
public static final int HINT_BLOCK_META_GENERIC_7 = 7;
public static final int HINT_BLOCK_META_GENERIC_8 = 8;
public static final int HINT_BLOCK_META_GENERIC_9 = 9;
public static final int HINT_BLOCK_META_GENERIC_10 = 10;
public static final int HINT_BLOCK_META_GENERIC_11 = 11;
public static final int HINT_BLOCK_META_DEFAULT = 12;
public static final int HINT_BLOCK_META_AIR = 13;
public static final int HINT_BLOCK_META_NOT_AIR = 14;
public static final int HINT_BLOCK_META_ERROR = 15;
public static final String MOD_ID = "structurelib";
public static final int HINT_BLOCK_META_GENERIC_0 = 0;
public static final int HINT_BLOCK_META_GENERIC_1 = 1;
public static final int HINT_BLOCK_META_GENERIC_2 = 2;
public static final int HINT_BLOCK_META_GENERIC_3 = 3;
public static final int HINT_BLOCK_META_GENERIC_4 = 4;
public static final int HINT_BLOCK_META_GENERIC_5 = 5;
public static final int HINT_BLOCK_META_GENERIC_6 = 6;
public static final int HINT_BLOCK_META_GENERIC_7 = 7;
public static final int HINT_BLOCK_META_GENERIC_8 = 8;
public static final int HINT_BLOCK_META_GENERIC_9 = 9;
public static final int HINT_BLOCK_META_GENERIC_10 = 10;
public static final int HINT_BLOCK_META_GENERIC_11 = 11;
public static final int HINT_BLOCK_META_DEFAULT = 12;
public static final int HINT_BLOCK_META_AIR = 13;
public static final int HINT_BLOCK_META_NOT_AIR = 14;
public static final int HINT_BLOCK_META_ERROR = 15;
/**
* Start a batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram.
*
* You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)}
*/
public static void startHinting(World w) {
proxy.startHinting(w);
}
/**
* Start a batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram.
* <p>
* You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)}
*/
public static void startHinting(World w) {
proxy.startHinting(w);
}
/**
* Start current batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram.
*
* You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)}
*/
public static void endHinting(World w) {
proxy.endHinting(w);
}
/**
* Start current batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram.
* <p>
* You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)}
*/
public static void endHinting(World w) {
proxy.endHinting(w);
}
public static void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {
proxy.hintParticleTinted(w, x, y, z, icons, RGBa);
}
public static void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {
proxy.hintParticleTinted(w, x, y, z, icons, RGBa);
}
public static void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) {
proxy.hintParticleTinted(w, x, y, z, block, meta, RGBa);
}
public static void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) {
proxy.hintParticleTinted(w, x, y, z, block, meta, RGBa);
}
public static void hintParticle(World w, int x, int y, int z, IIcon[] icons) {
proxy.hintParticle(w, x, y, z, icons);
}
public static void hintParticle(World w, int x, int y, int z, IIcon[] icons) {
proxy.hintParticle(w, x, y, z, icons);
}
public static void hintParticle(World w, int x, int y, int z, Block block, int meta) {
proxy.hintParticle(w, x, y, z, block, meta);
}
public static void hintParticle(World w, int x, int y, int z, Block block, int meta) {
proxy.hintParticle(w, x, y, z, block, meta);
}
/**
* Query the ExtendedFacing of this tile entity.
* The ExtendedFacing will later be set onto given tile entity via {@link com.gtnewhorizon.structurelib.alignment.IAlignment#setExtendedFacing(ExtendedFacing)}
* upon arrival of server reply.
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void queryAlignment(IAlignmentProvider provider) {
StructureLib.net.sendToServer(new AlignmentMessage.AlignmentQuery(provider));
}
/**
* Query the ExtendedFacing of this tile entity.
* The ExtendedFacing will later be set onto given tile entity via {@link com.gtnewhorizon.structurelib.alignment.IAlignment#setExtendedFacing(ExtendedFacing)}
* upon arrival of server reply.
*
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void queryAlignment(IAlignmentProvider provider) {
StructureLib.net.sendToServer(new AlignmentMessage.AlignmentQuery(provider));
}
/**
* Send the ExtendedFacing of this Tile Entity to all players. Can be called on server side only.
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider) {
StructureLib.net.sendToAll(new AlignmentMessage.AlignmentData(provider));
}
/**
* Send the ExtendedFacing of this Tile Entity to all players. Can be called on server side only.
*
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider) {
StructureLib.net.sendToAll(new AlignmentMessage.AlignmentData(provider));
}
/**
* Send the ExtendedFacing of this Tile Entity to given player. Can be called on server side only.
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, EntityPlayerMP player) {
StructureLib.net.sendTo(new AlignmentMessage.AlignmentData(provider), player);
}
/**
* Send the ExtendedFacing of this Tile Entity to given player. Can be called on server side only.
*
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, EntityPlayerMP player) {
StructureLib.net.sendTo(new AlignmentMessage.AlignmentData(provider), player);
}
/**
* Send the ExtendedFacing of this Tile Entity to all players around target point. Can be called on server side only.
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, NetworkRegistry.TargetPoint targetPoint) {
StructureLib.net.sendToAllAround(new AlignmentMessage.AlignmentData(provider), targetPoint);
}
/**
* Send the ExtendedFacing of this Tile Entity to all players around target point. Can be called on server side only.
*
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, NetworkRegistry.TargetPoint targetPoint) {
StructureLib.net.sendToAllAround(new AlignmentMessage.AlignmentData(provider), targetPoint);
}
/**
* Send the ExtendedFacing of this Tile Entity to all players in that dimension. Can be called on server side only.
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, World dimension) {
StructureLib.net.sendToDimension(new AlignmentMessage.AlignmentData(provider), dimension.provider.dimensionId);
}
/**
* Send the ExtendedFacing of this Tile Entity to all players in that dimension. Can be called on server side only.
*
* @throws IllegalArgumentException if is not tile entity or provided a null alignment
*/
public static void sendAlignment(IAlignmentProvider provider, World dimension) {
StructureLib.net.sendToDimension(new AlignmentMessage.AlignmentData(provider), dimension.provider.dimensionId);
}
public static Block getBlockHint() {
return StructureLib.blockHint;
}
public static Block getBlockHint() {
return StructureLib.blockHint;
}
public static Item getItemBlockHint() {
return StructureLib.itemBlockHint;
}
public static Item getItemBlockHint() {
return StructureLib.itemBlockHint;
}
public static boolean isDebugEnabled() {
return StructureLib.DEBUG_MODE;
}
public static boolean isDebugEnabled() {
return StructureLib.DEBUG_MODE;
}
public static void setDebugEnabled(boolean enabled) {
StructureLib.DEBUG_MODE = enabled;
}
public static void setDebugEnabled(boolean enabled) {
StructureLib.DEBUG_MODE = enabled;
}
}
@@ -7,10 +7,10 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
public class AlignmentUtility {
private AlignmentUtility(){
private AlignmentUtility() {
}
public static boolean handle(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ){
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;
@@ -6,10 +6,10 @@ 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;
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.STATES_COUNT;
ExtendedFacing getExtendedFacing();
@@ -23,48 +23,48 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
IAlignmentLimits getAlignmentLimits();
@Override
default IAlignment getAlignment(){
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();
static int getAlignmentIndex(ForgeDirection direction, Rotation rotation, Flip flip) {
return (direction.ordinal() * ROTATIONS_COUNT + rotation.getIndex()) * FLIPS_COUNT + flip.getIndex();
}
default ForgeDirection getDirection(){
default ForgeDirection getDirection() {
return getExtendedFacing().getDirection();
}
default void setDirection(ForgeDirection direction){
default void setDirection(ForgeDirection direction) {
setExtendedFacing(getExtendedFacing().with(direction));
}
default Rotation getRotation(){
default Rotation getRotation() {
return getExtendedFacing().getRotation();
}
default void setRotation(Rotation rotation){
default void setRotation(Rotation rotation) {
setExtendedFacing(getExtendedFacing().with(rotation));
}
default Flip getFlip(){
default Flip getFlip() {
return getExtendedFacing().getFlip();
}
default void setFlip(Flip flip){
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++) {
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 + i) % valuesLength].getForgeDirection())) {
return true;
}
}
}else {
} else {
for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) {
if(checkedSetExtendedFacing(extendedFacing)){
if (checkedSetExtendedFacing(extendedFacing)) {
return true;
}
}
@@ -72,17 +72,17 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
return false;
}
default boolean checkedSetDirection(ForgeDirection direction){
if (isNewDirectionValid(direction)){
default boolean checkedSetDirection(ForgeDirection direction) {
if (isNewDirectionValid(direction)) {
setDirection(direction);
return true;
}
return false;
}
default boolean canSetToDirectionAny(ForgeDirection direction){
default boolean canSetToDirectionAny(ForgeDirection direction) {
for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) {
if(isNewExtendedFacingValid(extendedFacing)){
if (isNewExtendedFacingValid(extendedFacing)) {
return true;
}
}
@@ -90,10 +90,10 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
}
default boolean toolSetRotation(Rotation rotation) {
if(rotation==null){
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 ii = 0, jj = getFlip().ordinal(); ii < flips; ii++) {
for (int i = 1, j = getRotation().ordinal(); i < rotations; i++) {
if (checkedSetExtendedFacing(ExtendedFacing.of(getDirection(), Rotation.VALUES[(j + i) % rotations], Flip.VALUES[(jj + ii) % flips]))) {
return true;
@@ -101,55 +101,55 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
}
}
return false;
}else {
} else {
return checkedSetRotation(rotation);
}
}
default boolean checkedSetRotation(Rotation rotation){
if (isNewRotationValid(rotation)){
default boolean checkedSetRotation(Rotation rotation) {
if (isNewRotationValid(rotation)) {
setRotation(rotation);
return true;
}
return false;
}
default boolean toolSetFlip(Flip flip){
if(flip==null){
default boolean toolSetFlip(Flip flip) {
if (flip == null) {
for (int i = 1, j = getFlip().ordinal(), valuesLength = Flip.VALUES.length; i < valuesLength; i++) {
if (checkedSetFlip(Flip.VALUES[(j + i) % valuesLength])) {
return true;
}
}
return false;
}else {
} else {
return checkedSetFlip(flip);
}
}
default boolean checkedSetFlip(Flip flip){
if (isNewFlipValid(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 (checkedSetExtendedFacing(ExtendedFacing.VALUES[(j + i)%valuesLength])){
default boolean toolSetExtendedFacing(ExtendedFacing extendedFacing) {
if (extendedFacing == null) {
for (int i = 0, j = getExtendedFacing().ordinal() + 1, valuesLength = ExtendedFacing.VALUES.length; i < valuesLength; i++) {
if (checkedSetExtendedFacing(ExtendedFacing.VALUES[(j + i) % valuesLength])) {
return true;
}
}
return false;
}else {
} else {
return checkedSetExtendedFacing(extendedFacing);
}
}
default boolean checkedSetExtendedFacing(ExtendedFacing alignment){
if (isNewExtendedFacingValid(alignment)){
default boolean checkedSetExtendedFacing(ExtendedFacing alignment) {
if (isNewExtendedFacingValid(alignment)) {
setExtendedFacing(alignment);
return true;
}
@@ -157,31 +157,31 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider {
}
default boolean isNewDirectionValid(ForgeDirection direction) {
return isNewExtendedFacingValid(direction,getRotation(),getFlip());
return isNewExtendedFacingValid(direction, getRotation(), getFlip());
}
default boolean isNewRotationValid(Rotation rotation){
return isNewExtendedFacingValid(getDirection(),rotation,getFlip());
default boolean isNewRotationValid(Rotation rotation) {
return isNewExtendedFacingValid(getDirection(), rotation, getFlip());
}
default boolean isNewFlipValid(Flip flip){
return isNewExtendedFacingValid(getDirection(),getRotation(),flip);
default boolean isNewFlipValid(Flip flip) {
return isNewExtendedFacingValid(getDirection(), getRotation(), flip);
}
default boolean isExtendedFacingValid() {
return isNewExtendedFacingValid(getDirection(),getRotation(),getFlip());
return isNewExtendedFacingValid(getDirection(), getRotation(), getFlip());
}
@Override
default boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip){
default boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip) {
return getAlignmentLimits().isNewExtendedFacingValid(direction, rotation, flip);
}
@Override
default boolean isNewExtendedFacingValid(ExtendedFacing alignment){
default boolean isNewExtendedFacingValid(ExtendedFacing alignment) {
return getAlignmentLimits().isNewExtendedFacingValid(
alignment.getDirection(),
alignment.getRotation(),
alignment.getFlip());
alignment.getDirection(),
alignment.getRotation(),
alignment.getFlip());
}
}
}
@@ -1,4 +1,5 @@
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;
@@ -18,9 +19,9 @@ public interface IAlignmentLimits {
default boolean isNewExtendedFacingValid(ExtendedFacing alignment) {
return isNewExtendedFacingValid(
alignment.getDirection(),
alignment.getRotation(),
alignment.getFlip());
alignment.getDirection(),
alignment.getRotation(),
alignment.getFlip());
}
static IAlignmentLimits allowOnly(ExtendedFacing... allowedFacings) {
@@ -42,7 +43,8 @@ public interface IAlignmentLimits {
class Builder {
protected final boolean[] validStates = new boolean[STATES_COUNT];
private Builder() {}
private Builder() {
}
public static Builder allowAll() {
Builder b = new Builder();
@@ -16,69 +16,69 @@ public class IntegerAxisSwap {
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());
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){
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()
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){
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()
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){
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
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){
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
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 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 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 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];
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];
}
}
@@ -43,10 +43,10 @@ public class ConstructableUtility {
IMultiblockInfoContainer<TileEntity> iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass());
if (tTileEntity instanceof IAlignment) {
iMultiblockInfoContainer.construct(aStack, false, tTileEntity,
((IAlignment) tTileEntity).getExtendedFacing());
((IAlignment) tTileEntity).getExtendedFacing());
} else {
iMultiblockInfoContainer.construct(aStack, false, tTileEntity,
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
}
}
}
@@ -68,10 +68,10 @@ public class ConstructableUtility {
IMultiblockInfoContainer<TileEntity> iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass());
if (tTileEntity instanceof IAlignment) {
iMultiblockInfoContainer.construct(aStack, true, tTileEntity,
((IAlignment) tTileEntity).getExtendedFacing());
((IAlignment) tTileEntity).getExtendedFacing());
} else {
iMultiblockInfoContainer.construct(aStack, true, tTileEntity,
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
}
StructureLib.addClientSideChatMessages(IMultiblockInfoContainer.get(tTileEntity.getClass()).getDescription(aStack));
return false;
@@ -6,9 +6,9 @@ import javax.annotation.Nullable;
* Implement this interface if this tile entity MIGHT be constructable
*/
public interface IConstructableProvider {
/**
* @return null if not constructable, an instance otherwise.
*/
@Nullable
IConstructable getConstructable();
/**
* @return null if not constructable, an instance otherwise.
*/
@Nullable
IConstructable getConstructable();
}
@@ -13,11 +13,11 @@ public enum Direction {
private final ForgeDirection forgeDirection;
private final Vec3Impl axisVector;
public static final Direction[] VALUES=values();
public static final Direction[] VALUES = values();
Direction(ForgeDirection forgeDirection) {
this.forgeDirection = forgeDirection;
axisVector=new Vec3Impl(forgeDirection.offsetX,forgeDirection.offsetY,forgeDirection.offsetZ);
axisVector = new Vec3Impl(forgeDirection.offsetX, forgeDirection.offsetY, forgeDirection.offsetZ);
}
public ForgeDirection getForgeDirection() {
@@ -28,7 +28,7 @@ public enum Direction {
return axisVector;
}
public static Vec3Impl getAxisVector(ForgeDirection forgeDirection){
public static Vec3Impl getAxisVector(ForgeDirection forgeDirection) {
return VALUES[forgeDirection.ordinal()].axisVector;
}
}
@@ -114,19 +114,20 @@ public enum ExtendedFacing {
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 DEFAULT = NORTH_NORMAL_NONE;
public static final ExtendedFacing[] VALUES = values();
public static final Map<ForgeDirection, List<ExtendedFacing>> FOR_FACING=new HashMap<>();
public static final Map<ForgeDirection, List<ExtendedFacing>> FOR_FACING = new HashMap<>();
public static final int STATES_COUNT = VALUES.length;
static {
stream(values()).forEach(extendedFacing ->
FOR_FACING.compute(extendedFacing.direction, ((forgeDirection, extendedFacings) -> {
if (extendedFacings == null) {
extendedFacings = new ArrayList<>();
}
extendedFacings.add(extendedFacing);
return extendedFacings;
})));
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));
@@ -143,133 +144,146 @@ public enum ExtendedFacing {
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){
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;
a = ForgeDirection.WEST;
b = ForgeDirection.SOUTH;
c = ForgeDirection.UP;
break;
case UP:
a= ForgeDirection.EAST;
b= ForgeDirection.SOUTH;
c= ForgeDirection.DOWN;
a = ForgeDirection.EAST;
b = ForgeDirection.SOUTH;
c = ForgeDirection.DOWN;
break;
case NORTH:
a= ForgeDirection.WEST;
b= ForgeDirection.DOWN;
c= ForgeDirection.SOUTH;
a = ForgeDirection.WEST;
b = ForgeDirection.DOWN;
c = ForgeDirection.SOUTH;
break;
case SOUTH:
a= ForgeDirection.EAST;
b= ForgeDirection.DOWN;
c= ForgeDirection.NORTH;
a = ForgeDirection.EAST;
b = ForgeDirection.DOWN;
c = ForgeDirection.NORTH;
break;
case WEST:
a= ForgeDirection.SOUTH;
b= ForgeDirection.DOWN;
c= ForgeDirection.EAST;
a = ForgeDirection.SOUTH;
b = ForgeDirection.DOWN;
c = ForgeDirection.EAST;
break;
case EAST:
a= ForgeDirection.NORTH;
b= ForgeDirection.DOWN;
c= ForgeDirection.WEST;
a = ForgeDirection.NORTH;
b = ForgeDirection.DOWN;
c = ForgeDirection.WEST;
break;
default:throw new RuntimeException("Is impossible...");
default:
throw new RuntimeException("Is impossible...");
}
switch (flip){//This duplicates some axis swaps since flip boolean would do, but seems more convenient to use
switch (flip) {//This duplicates some axis swaps since flip boolean would do, but seems more convenient to use
case HORIZONTAL:
a=a.getOpposite();
a = a.getOpposite();
break;
case BOTH:
a=a.getOpposite();
a = a.getOpposite();
case VERTICAL:
b=b.getOpposite();
b = b.getOpposite();
break;
case NONE: break;
default:throw new RuntimeException("Even more impossible...");
case NONE:
break;
default:
throw new RuntimeException("Even more impossible...");
}
switch (rotation) {
case CLOCKWISE: {
ForgeDirection _a=a;
a =b;
b =_a.getOpposite();
ForgeDirection _a = a;
a = b;
b = _a.getOpposite();
break;
}
case UPSIDE_DOWN:
a=a.getOpposite();
b=b.getOpposite();
a = a.getOpposite();
b = b.getOpposite();
break;
case COUNTER_CLOCKWISE: {
ForgeDirection _a=a;
a =b.getOpposite();
b =_a;
ForgeDirection _a = a;
a = b.getOpposite();
b = _a;
break;
}
case NORMAL: 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);
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){
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){
public static ExtendedFacing of(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN) {
return DEFAULT;
}
return VALUES[IAlignment.getAlignmentIndex(direction, Rotation.NORMAL, Flip.NONE)];
}
public static ImmutableSet<ExtendedFacing> getAllWith(ForgeDirection direction) { return LOOKUP_BY_DIRECTION.get(direction);}
public static ImmutableSet<ExtendedFacing> getAllWith(Rotation rotation) { return LOOKUP_BY_ROTATION.get(rotation);}
public static ImmutableSet<ExtendedFacing> getAllWith(Flip flip) { return LOOKUP_BY_FLIP.get(flip);}
public ExtendedFacing with(ForgeDirection direction){
return of(direction,rotation,flip);
public static ImmutableSet<ExtendedFacing> getAllWith(ForgeDirection direction) {
return LOOKUP_BY_DIRECTION.get(direction);
}
public ExtendedFacing with(Rotation rotation){
return of(direction,rotation,flip);
public static ImmutableSet<ExtendedFacing> getAllWith(Rotation rotation) {
return LOOKUP_BY_ROTATION.get(rotation);
}
public ExtendedFacing with(Flip flip){
return of(direction,rotation,flip);
public static ImmutableSet<ExtendedFacing> getAllWith(Flip flip) {
return LOOKUP_BY_FLIP.get(flip);
}
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);
return of(direction.getOpposite(), rotation, flip);
}
public ExtendedFacing getOppositeRotation() {
return of(direction,rotation.getOpposite(),flip);
return of(direction, rotation.getOpposite(), flip);
}
public ExtendedFacing getOppositeFlip() {
return of(direction,rotation,flip.getOpposite());
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 ExtendedFacing getDuplicate() {
return of(direction, rotation.getOpposite(), flip.getOpposite());
}
public int getIndex(){
public int getIndex() {
return ordinal();
}
@@ -307,39 +321,47 @@ public enum ExtendedFacing {
/**
* 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
* @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(int[] point, int[] out) {
integerAxisSwap.inverseTranslate(point, out);
}
public void getWorldOffset(double[] point,double[] 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)
* @return A, B, C offset (facing relative L-->R,U-->D,F-->B)
*/
public Vec3 getOffsetABC(Vec3 xyzOffset){
public Vec3 getOffsetABC(Vec3 xyzOffset) {
return integerAxisSwap.translate(xyzOffset);
}
public Vec3Impl getOffsetABC(Vec3Impl xyzOffset){
public Vec3Impl getOffsetABC(Vec3Impl xyzOffset) {
return integerAxisSwap.translate(xyzOffset);
}
public void getOffsetABC(int[] point,int[] out){
integerAxisSwap.translate(point,out);
public void getOffsetABC(int[] point, int[] out) {
integerAxisSwap.translate(point, out);
}
public void getOffsetABC(double[] point,double[] out){
integerAxisSwap.translate(point,out);
public void getOffsetABC(double[] point, double[] out) {
integerAxisSwap.translate(point, out);
}
public IntegerAxisSwap getIntegerAxisSwap() {
@@ -26,7 +26,7 @@ public enum Flip {
this.name = nameIn;
}
public int getIndex(){
public int getIndex() {
return ordinal();
}
@@ -58,19 +58,19 @@ public enum Flip {
return this.name;
}
public boolean isNotFlipped(){
return this==NONE;
public boolean isNotFlipped() {
return this == NONE;
}
public boolean isBothFlipped(){
return this==BOTH;
public boolean isBothFlipped() {
return this == BOTH;
}
public boolean isHorizontallyFlipped() {
return this==HORIZONTAL || isBothFlipped();
return this == HORIZONTAL || isBothFlipped();
}
public boolean isVerticallyFliped() {
return this==VERTICAL || isBothFlipped();
return this == VERTICAL || isBothFlipped();
}
}
@@ -26,7 +26,7 @@ public enum Rotation {
this.name = nameIn;
}
public int getIndex(){
public int getIndex() {
return ordinal();
}
@@ -58,19 +58,19 @@ public enum Rotation {
return this.name;
}
public boolean isNotRotated(){
return this==NORMAL;
public boolean isNotRotated() {
return this == NORMAL;
}
public boolean isClockwise(){
return this==CLOCKWISE;
public boolean isClockwise() {
return this == CLOCKWISE;
}
public boolean isCounterClockwise(){
return this==COUNTER_CLOCKWISE;
public boolean isCounterClockwise() {
return this == COUNTER_CLOCKWISE;
}
public boolean isUpsideDown(){
return this==UPSIDE_DOWN;
public boolean isUpsideDown() {
return this == UPSIDE_DOWN;
}
}
@@ -16,52 +16,52 @@ import net.minecraft.world.IBlockAccess;
import java.util.List;
public class BlockHint extends Block {
private static final IIcon[] hint = new IIcon[16];
private static final IIcon[] hint = new IIcon[16];
public BlockHint() {
super(Material.iron);
setBlockName("structurelib.blockhint");
setCreativeTab(StructureLib.creativeTab);
}
public BlockHint() {
super(Material.iron);
setBlockName("structurelib.blockhint");
setCreativeTab(StructureLib.creativeTab);
}
@Override
public void registerBlockIcons(IIconRegister aIconRegister) {
//super.registerBlockIcons(aIconRegister);
hint[0] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_0");
hint[1] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_1");
hint[2] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_2");
hint[3] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_3");
hint[4] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_4");
hint[5] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_5");
hint[6] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_6");
hint[7] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_7");
hint[8] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_8");
hint[9] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_9");
hint[10] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_10");
hint[11] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_11");
hint[12] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_DEFAULT");
hint[13] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_AIR");
hint[14] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_NOAIR");
hint[15] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_ERROR");
}
@Override
public void registerBlockIcons(IIconRegister aIconRegister) {
//super.registerBlockIcons(aIconRegister);
hint[0] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_0");
hint[1] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_1");
hint[2] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_2");
hint[3] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_3");
hint[4] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_4");
hint[5] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_5");
hint[6] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_6");
hint[7] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_7");
hint[8] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_8");
hint[9] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_9");
hint[10] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_10");
hint[11] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_11");
hint[12] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_DEFAULT");
hint[13] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_AIR");
hint[14] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_NOAIR");
hint[15] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_ERROR");
}
@Override
public IIcon getIcon(int aSide, int aMeta) {
return hint[aMeta];
}
@Override
public IIcon getIcon(int aSide, int aMeta) {
return hint[aMeta];
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess aWorld, int xCoord, int yCoord, int zCoord, int aSide) {
int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord);
return getIcon(aSide, tMeta);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess aWorld, int xCoord, int yCoord, int zCoord, int aSide) {
int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord);
return getIcon(aSide, tMeta);
}
@Override
@SuppressWarnings("unchecked")
public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) {
for (int i = 0; i <= 15; i++) {
aList.add(new ItemStack(aItem, 1, i));
}
}
@Override
@SuppressWarnings("unchecked")
public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) {
for (int i = 0; i <= 15; i++) {
aList.add(new ItemStack(aItem, 1, i));
}
}
}
@@ -15,14 +15,13 @@ import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class EntityFXBlockHint extends EntityFX {
private IIcon[] icons;
private short[] mRGBa = {255,255,255,0};
private short[] mRGBa = {255, 255, 255, 0};
public EntityFXBlockHint(World world){
this(world,0,0,0, Blocks.stone,0);
public EntityFXBlockHint(World world) {
this(world, 0, 0, 0, Blocks.stone, 0);
}
/**
*
* @param world
* @param x
* @param y
@@ -37,11 +36,11 @@ public class EntityFXBlockHint extends EntityFX {
prevPosZ = posZ;
noClip = true;
particleMaxAge = 2000 + StructureLib.RANDOM.nextInt(200);
this.icons=icons;
this.icons = icons;
}
public EntityFXBlockHint(World world, int x, int y, int z, Block block, int meta) {
super(world, x+.25, y+.5, z+.25);
super(world, x + .25, y + .5, z + .25);
particleGravity = 0;
prevPosX = posX;
prevPosY = posY;
@@ -54,8 +53,8 @@ public class EntityFXBlockHint extends EntityFX {
}
}
public EntityFXBlockHint withColorTint(short[] coloure){
this.mRGBa =coloure;
public EntityFXBlockHint withColorTint(short[] coloure) {
this.mRGBa = coloure;
return this;
}
@@ -71,15 +70,15 @@ public class EntityFXBlockHint extends EntityFX {
//var8, var9 - X U
//var 10, var 11 - Y V
for(int i=0;i<6;i++){
if(icons[i]==null) {
for (int i = 0; i < 6; i++) {
if (icons[i] == null) {
continue;
}
double u=icons[i].getMinU();
double U=icons[i].getMaxU();
double v=icons[i].getMinV();
double V=icons[i].getMaxV();
switch (i){//{DOWN, UP, NORTH, SOUTH, WEST, EAST}
double u = icons[i].getMinU();
double U = icons[i].getMaxU();
double v = icons[i].getMinV();
double V = icons[i].getMaxV();
switch (i) {//{DOWN, UP, NORTH, SOUTH, WEST, EAST}
case 0:
tes.addVertexWithUV(X, Y, Z + size, u, V);
tes.addVertexWithUV(X, Y, Z, u, v);
@@ -129,7 +128,7 @@ public class EntityFXBlockHint extends EntityFX {
@Override
public boolean shouldRenderInPass(int pass) {
return pass==2;
return pass == 2;
}
@Override
@@ -6,31 +6,27 @@ import net.minecraft.client.particle.EntityFX;
import net.minecraft.world.World;
@SideOnly(Side.CLIENT)
public class WeightlessParticleFX extends EntityFX
{
public WeightlessParticleFX(World p_i1205_1_, double p_i1205_2_, double p_i1205_4_, double p_i1205_6_, double p_i1205_8_, double p_i1205_10_, double p_i1205_12_)
{
public class WeightlessParticleFX extends EntityFX {
public WeightlessParticleFX(World p_i1205_1_, double p_i1205_2_, double p_i1205_4_, double p_i1205_6_, double p_i1205_8_, double p_i1205_10_, double p_i1205_12_) {
super(p_i1205_1_, p_i1205_2_, p_i1205_4_, p_i1205_6_, p_i1205_8_, p_i1205_10_, p_i1205_12_);
this.motionX = p_i1205_8_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F);
this.motionY = p_i1205_10_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F);
this.motionZ = p_i1205_12_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F);
this.motionX = p_i1205_8_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F);
this.motionY = p_i1205_10_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F);
this.motionZ = p_i1205_12_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F);
this.particleRed = this.particleGreen = this.particleBlue = this.rand.nextFloat() * 0.3F + 0.7F;
this.particleScale = this.rand.nextFloat() * this.rand.nextFloat() * 6.0F + 1.0F;
this.particleMaxAge = (int)(16.0D / ((double)this.rand.nextFloat() * 0.8D + 0.2D)) + 2;
this.noClip=true;
this.particleMaxAge = (int) (16.0D / ((double) this.rand.nextFloat() * 0.8D + 0.2D)) + 2;
this.noClip = true;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
public void onUpdate() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.particleAge++ >= this.particleMaxAge)
{
if (this.particleAge++ >= this.particleMaxAge) {
this.setDead();
}
@@ -12,55 +12,55 @@ import java.util.List;
import static net.minecraft.util.StatCollector.translateToLocal;
public class ItemBlockHint extends ItemBlock {
public ItemBlockHint(Block p_i45328_1_) {
super(p_i45328_1_);
setMaxDamage(0);
setHasSubtypes(true);
setCreativeTab(CreativeTabs.tabBlock);
}
public ItemBlockHint(Block p_i45328_1_) {
super(p_i45328_1_);
setMaxDamage(0);
setHasSubtypes(true);
setCreativeTab(CreativeTabs.tabBlock);
}
@Override
@SuppressWarnings("unchecked")
public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) {
aList.add(translateToLocal("structurelib.blockhint.desc.0"));//Helps while building
switch (aStack.getItemDamage()) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.1"));//Placeholder for a certain group.
break;
case 12:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.2"));//General placeholder.
break;
case 13:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.3"));//Make sure it contains Air material.
break;
case 14:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.4"));//Make sure it does not contain Air material.
break;
case 15:
aList.add(EnumChatFormatting.BLUE.toString() + translateToLocal("structurelib.blockhint.desc.5"));//ERROR, what did u expect?
break;
default://WTF?
aList.add("Damn son where did you get that!?");
aList.add(EnumChatFormatting.BLUE.toString() + "From outer space... I guess...");
}
}
@Override
@SuppressWarnings("unchecked")
public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) {
aList.add(translateToLocal("structurelib.blockhint.desc.0"));//Helps while building
switch (aStack.getItemDamage()) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.1"));//Placeholder for a certain group.
break;
case 12:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.2"));//General placeholder.
break;
case 13:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.3"));//Make sure it contains Air material.
break;
case 14:
aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.4"));//Make sure it does not contain Air material.
break;
case 15:
aList.add(EnumChatFormatting.BLUE.toString() + translateToLocal("structurelib.blockhint.desc.5"));//ERROR, what did u expect?
break;
default://WTF?
aList.add("Damn son where did you get that!?");
aList.add(EnumChatFormatting.BLUE.toString() + "From outer space... I guess...");
}
}
public int getMetadata(int aMeta) {
return aMeta;
}
public int getMetadata(int aMeta) {
return aMeta;
}
public String getUnlocalizedName(ItemStack aStack) {
return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack);
}
public String getUnlocalizedName(ItemStack aStack) {
return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack);
}
}
@@ -16,23 +16,23 @@ import static com.gtnewhorizon.structurelib.StructureLibAPI.MOD_ID;
import static net.minecraft.util.StatCollector.translateToLocal;
public class ItemFrontRotationTool extends Item {
public ItemFrontRotationTool() {
setMaxStackSize(1);
setUnlocalizedName("structurelib.frontRotationTool");
setTextureName(MOD_ID + ":itemFrontRotationTool");
setCreativeTab(StructureLib.creativeTab);
}
public ItemFrontRotationTool() {
setMaxStackSize(1);
setUnlocalizedName("structurelib.frontRotationTool");
setTextureName(MOD_ID + ":itemFrontRotationTool");
setCreativeTab(StructureLib.creativeTab);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
return AlignmentUtility.handle(player, world, x, y, z);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
return AlignmentUtility.handle(player, world, x, y, z);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) {
aList.add(translateToLocal("item.structurelib.frontRotationTool.desc.0"));//Triggers Front Rotation Interface
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1"));//Rotates only the front panel,
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2"));//which allows structure rotation.
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) {
aList.add(translateToLocal("item.structurelib.frontRotationTool.desc.0"));//Triggers Front Rotation Interface
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1"));//Rotates only the front panel,
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2"));//which allows structure rotation.
}
}
@@ -7,20 +7,35 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class CommonProxy {
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa){}
public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa){}
public void hintParticle(World w, int x, int y, int z, IIcon[] icons){}
public void hintParticle(World w, int x, int y, int z, Block block, int meta){}
public EntityPlayer getCurrentPlayer() {
return null;
}
public boolean isCurrentPlayer(EntityPlayer player) {
return false;
}
public void addClientSideChatMessages(String... messages){
}
public void startHinting(World w) {}
public void endHinting(World w) {}
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {
}
public void preInit(FMLPreInitializationEvent e) {}
public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) {
}
public void hintParticle(World w, int x, int y, int z, IIcon[] icons) {
}
public void hintParticle(World w, int x, int y, int z, Block block, int meta) {
}
public EntityPlayer getCurrentPlayer() {
return null;
}
public boolean isCurrentPlayer(EntityPlayer player) {
return false;
}
public void addClientSideChatMessages(String... messages) {
}
public void startHinting(World w) {
}
public void endHinting(World w) {
}
public void preInit(FMLPreInitializationEvent e) {
}
}
@@ -3,5 +3,5 @@ package com.gtnewhorizon.structurelib.structure;
import net.minecraft.world.World;
public interface IBlockPosConsumer {
void consume(World world, int x, int y, int z);
void consume(World world, int x, int y, int z);
}
@@ -4,15 +4,15 @@ import net.minecraft.block.Block;
import net.minecraft.world.World;
public interface ICustomBlockSetting {
/**
* Default block setting calls {@link World#setBlock(int x, int y, int z, Block block, int meta, int updateType)} like:
* {@code world.setBlock(x,y,z,this/block,meta,2)} where updateType 2 means to update lighting and stuff
*
* @param world world that should be affected
* @param x x position to set
* @param y y position to set
* @param z z position to set
* @param meta required meta
*/
void setBlock(World world, int x, int y, int z, int meta);
/**
* Default block setting calls {@link World#setBlock(int x, int y, int z, Block block, int meta, int updateType)} like:
* {@code world.setBlock(x,y,z,this/block,meta,2)} where updateType 2 means to update lighting and stuff
*
* @param world world that should be affected
* @param x x position to set
* @param y y position to set
* @param z z position to set
* @param meta required meta
*/
void setBlock(World world, int x, int y, int z, int meta);
}
@@ -10,169 +10,169 @@ import java.util.Arrays;
import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE;
public interface IStructureDefinition<T> {
/**
* Used internally
*
* Might, but is not required, to throw {@link java.util.NoSuchElementException} if the given structure piece is not found.
*
* @param name same name as for other methods here
* @return the array of elements to process
* @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly matches
*/
IStructureElement<T>[] getStructureFor(String name);
/**
* Used internally
* <p>
* Might, but is not required, to throw {@link java.util.NoSuchElementException} if the given structure piece is not found.
*
* @param name same name as for other methods here
* @return the array of elements to process
* @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly matches
*/
IStructureElement<T>[] getStructureFor(String name);
default boolean check(T object, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean forceCheckAllBlocks) {
return iterate(object, null, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, false, forceCheckAllBlocks);
}
default boolean check(T object, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean forceCheckAllBlocks) {
return iterate(object, null, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, false, forceCheckAllBlocks);
}
default boolean hints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, true, null);
}
default boolean hints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, true, null);
}
default boolean build(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, false, null);
}
default boolean build(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, false, null);
}
default boolean buildOrHints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean hintsOnly) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, hintsOnly, null);
}
default boolean buildOrHints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean hintsOnly) {
return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ,
basePositionA, basePositionB, basePositionC, hintsOnly, null);
}
static <T> boolean iterate(T object, ItemStack trigger, IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue) {
if (world.isRemote ^ hintsOnly) {
return false;
}
static <T> boolean iterate(T object, ItemStack trigger, IStructureElement<T>[] elements, World world, ExtendedFacing extendedFacing,
int basePositionX, int basePositionY, int basePositionZ,
int basePositionA, int basePositionB, int basePositionC,
boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue) {
if (world.isRemote ^ hintsOnly) {
return false;
}
//change base position to base offset
basePositionA = -basePositionA;
basePositionB = -basePositionB;
basePositionC = -basePositionC;
//change base position to base offset
basePositionA = -basePositionA;
basePositionB = -basePositionB;
basePositionC = -basePositionC;
int[] abc = new int[]{basePositionA, basePositionB, basePositionC};
int[] xyz = new int[3];
int[] abc = new int[]{basePositionA, basePositionB, basePositionC};
int[] xyz = new int[3];
if (checkBlocksIfNotNullForceCheckAllIfTrue != null) {
if (checkBlocksIfNotNullForceCheckAllIfTrue) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (checkBlocksIfNotNullForceCheckAllIfTrue != null) {
if (checkBlocksIfNotNullForceCheckAllIfTrue) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
abc[0] += 1;
}
}
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
abc[0] += 1;
}
}
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
}
abc[0] += 1;
}
}
}
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] pass");
}
} else {
if (hintsOnly) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " +
Arrays.toString(xyz) + " " + Arrays.toString(abc));
}
}
abc[0] += 1;
}
}
}
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] pass");
}
} else {
if (hintsOnly) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger);
element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger);
abc[0] += 1;
}
}
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
abc[0] += 1;
}
}
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger);
}
abc[0] += 1;
}
}
}
}
return true;
}
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger);
}
abc[0] += 1;
}
}
}
}
return true;
}
static <T> StructureDefinition.Builder<T> builder() {
return StructureDefinition.builder();
}
static <T> StructureDefinition.Builder<T> builder() {
return StructureDefinition.builder();
}
}
@@ -7,37 +7,37 @@ import net.minecraft.world.World;
* Use StructureUtility to instantiate
*/
public interface IStructureElement<T> {
boolean check(T t, World world, int x, int y, int z);
boolean check(T t, World world, int x, int y, int z);
boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger);
boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger);
boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger);
boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger);
default int getStepA() {
return 1;
}
default int getStepA() {
return 1;
}
default int getStepB() {
return 0;
}
default int getStepB() {
return 0;
}
default int getStepC() {
return 0;
}
default int getStepC() {
return 0;
}
default boolean resetA() {
return false;
}
default boolean resetA() {
return false;
}
default boolean resetB() {
return false;
}
default boolean resetB() {
return false;
}
default boolean resetC() {
return false;
}
default boolean resetC() {
return false;
}
default boolean isNavigating() {
return false;
}
default boolean isNavigating() {
return false;
}
}
@@ -7,35 +7,35 @@ import net.minecraft.world.World;
* Use StructureUtility to instantiate
*/
public interface IStructureElementChain<T> extends IStructureElement<T> {
IStructureElement<T>[] fallbacks();
IStructureElement<T>[] fallbacks();
@Override
default boolean check(T t, World world, int x, int y, int z) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.check(t, world, x, y, z)) {
return true;
}
}
return false;
}
@Override
default boolean check(T t, World world, int x, int y, int z) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.check(t, world, x, y, z)) {
return true;
}
}
return false;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.spawnHint(t, world, x, y, z, trigger)) {
return true;
}
}
return false;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.spawnHint(t, world, x, y, z, trigger)) {
return true;
}
}
return false;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.placeBlock(t, world, x, y, z, trigger)) {
return true;
}
}
return false;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
for (IStructureElement<T> fallback : fallbacks()) {
if (fallback.placeBlock(t, world, x, y, z, trigger)) {
return true;
}
}
return false;
}
}
@@ -4,13 +4,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IStructureElementCheckOnly<T> extends IStructureElement<T> {
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
}
@@ -4,8 +4,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IStructureElementNoPlacement<T> extends IStructureElement<T> {
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return false;
}
}
@@ -7,22 +7,22 @@ import net.minecraft.world.World;
* Use StructureUtility to instantiate
*/
interface IStructureNavigate<T> extends IStructureElement<T> {
@Override
default boolean check(T t, World world, int x, int y, int z) {
return true;
}
@Override
default boolean check(T t, World world, int x, int y, int z) {
return true;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return true;
}
@Override
default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return true;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return true;
}
@Override
default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return true;
}
default boolean isNavigating() {
return true;
}
default boolean isNavigating() {
return true;
}
}
@@ -4,6 +4,7 @@ import net.minecraft.block.Block;
/**
* a function to extract tier info from a block.
*
* @param <TIER>
*/
@FunctionalInterface
@@ -5,8 +5,9 @@ package com.gtnewhorizon.structurelib.structure;
* temporary states that don't need to live in your main context, which would usually live for the whole lifetime of the
* structure than just during structure check. Usually just save some few bytes, but becomes non trivial if you need to
* record too much stuff.
*
* <p>
* You will have to reset the context yourself though. The API can't guess when the old context becomes invalid.
*
* @param <CTX> the temporary state context
*/
public interface IWithExtendedContext<CTX> {
@@ -6,33 +6,33 @@ import net.minecraft.world.World;
import java.util.function.Function;
class LazyStructureElement<T> implements IStructureElementDeferred<T> {
private Function<T, IStructureElement<T>> to;
private IStructureElement<T> elem;
private Function<T, IStructureElement<T>> to;
private IStructureElement<T> elem;
public LazyStructureElement(Function<T, IStructureElement<T>> to) {
this.to = to;
}
public LazyStructureElement(Function<T, IStructureElement<T>> to) {
this.to = to;
}
private IStructureElement<T> get(T t) {
if (to != null) {
elem = to.apply(t);
to = null;
}
return elem;
}
private IStructureElement<T> get(T t) {
if (to != null) {
elem = to.apply(t);
to = null;
}
return elem;
}
@Override
public boolean check(T t, World world, int x, int y, int z) {
return get(t).check(t, world, x, y, z);
}
@Override
public boolean check(T t, World world, int x, int y, int z) {
return get(t).check(t, world, x, y, z);
}
@Override
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return get(t).placeBlock(t, world, x, y, z, trigger);
}
@Override
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return get(t).placeBlock(t, world, x, y, z, trigger);
}
@Override
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return get(t).spawnHint(t, world, x, y, z, trigger);
}
@Override
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
return get(t).spawnHint(t, world, x, y, z, trigger);
}
}
@@ -9,193 +9,193 @@ import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.*;
public class StructureDefinition<T> implements IStructureDefinition<T> {
private final Map<Character, IStructureElement<T>> elements;
private final Map<String, String> shapes;
private final Map<String, IStructureElement<T>[]> structures;
private final Map<Character, IStructureElement<T>> elements;
private final Map<String, String> shapes;
private final Map<String, IStructureElement<T>[]> structures;
public static <B> Builder<B> builder() {
return new Builder<>();
}
public static <B> Builder<B> builder() {
return new Builder<>();
}
private StructureDefinition(
Map<Character, IStructureElement<T>> elements,
Map<String, String> shapes,
Map<String, IStructureElement<T>[]> structures) {
this.elements = elements;
this.shapes = shapes;
this.structures = structures;
}
private StructureDefinition(
Map<Character, IStructureElement<T>> elements,
Map<String, String> shapes,
Map<String, IStructureElement<T>[]> structures) {
this.elements = elements;
this.shapes = shapes;
this.structures = structures;
}
public static class Builder<T> {
private static final char A = '\uA000';
private static final char B = '\uB000';
private static final char C = '\uC000';
private char d = '\uD000';
private final Map<Vec3Impl, Character> navigates;
private final Map<Character, IStructureElement<T>> elements;
private final Map<String, String> shapes;
public static class Builder<T> {
private static final char A = '\uA000';
private static final char B = '\uB000';
private static final char C = '\uC000';
private char d = '\uD000';
private final Map<Vec3Impl, Character> navigates;
private final Map<Character, IStructureElement<T>> elements;
private final Map<String, String> shapes;
private Builder() {
navigates = new HashMap<>();
elements = new HashMap<>();
shapes = new HashMap<>();
}
private Builder() {
navigates = new HashMap<>();
elements = new HashMap<>();
shapes = new HashMap<>();
}
public Map<Character, IStructureElement<T>> getElements() {
return elements;
}
public Map<Character, IStructureElement<T>> getElements() {
return elements;
}
public Map<String, String> getShapes() {
return shapes;
}
public Map<String, String> getShapes() {
return shapes;
}
/**
* Adds shape
* + is anything but air
* - is air checks
* space bar is skip
* ~ is also skip (but marks controller position, optional and logically it is a space...)
* rest needs to be defined
* <p>
* next char is next block(a)
* next string is next line(b)
* next string[] is next slice(c)
* <p>
* char A000-FFFF range is reserved for generated skips
*
* @param name unlocalized/code name
* @param structurePiece generated or written struct - DO NOT STORE IT ANYWHERE, or at least set them to null afterwards
* @return this builder
*/
public Builder<T> addShape(String name, String[][] structurePiece) {
StringBuilder builder = new StringBuilder();
if (structurePiece.length > 0) {
for (String[] strings : structurePiece) {
if (strings.length > 0) {
for (String string : strings) {
builder.append(string).append(B);
}
builder.setLength(builder.length() - 1);
}
builder.append(C);
}
builder.setLength(builder.length() - 1);
}
int a = 0, b = 0, c = 0;
for (int i = 0; i < builder.length(); i++) {
char ch = builder.charAt(i);
if (ch == ' ' || ch == '~') {
builder.setCharAt(i, A);
ch = A;
}
if (ch == A) {
a++;
} else if (ch == B) {
a = 0;
b++;
} else if (ch == C) {
a = 0;
b = 0;
c++;
} else if (a != 0 || b != 0 || c != 0) {
Vec3Impl vec3 = new Vec3Impl(a, b, c);
Character navigate = navigates.get(vec3);
if (navigate == null) {
navigate = d++;
navigates.put(vec3, navigate);
addElement(navigate, step(vec3));
}
builder.setCharAt(i - 1, navigate);
a = 0;
b = 0;
c = 0;
}
}
/**
* Adds shape
* + is anything but air
* - is air checks
* space bar is skip
* ~ is also skip (but marks controller position, optional and logically it is a space...)
* rest needs to be defined
* <p>
* next char is next block(a)
* next string is next line(b)
* next string[] is next slice(c)
* <p>
* char A000-FFFF range is reserved for generated skips
*
* @param name unlocalized/code name
* @param structurePiece generated or written struct - DO NOT STORE IT ANYWHERE, or at least set them to null afterwards
* @return this builder
*/
public Builder<T> addShape(String name, String[][] structurePiece) {
StringBuilder builder = new StringBuilder();
if (structurePiece.length > 0) {
for (String[] strings : structurePiece) {
if (strings.length > 0) {
for (String string : strings) {
builder.append(string).append(B);
}
builder.setLength(builder.length() - 1);
}
builder.append(C);
}
builder.setLength(builder.length() - 1);
}
int a = 0, b = 0, c = 0;
for (int i = 0; i < builder.length(); i++) {
char ch = builder.charAt(i);
if (ch == ' ' || ch == '~') {
builder.setCharAt(i, A);
ch = A;
}
if (ch == A) {
a++;
} else if (ch == B) {
a = 0;
b++;
} else if (ch == C) {
a = 0;
b = 0;
c++;
} else if (a != 0 || b != 0 || c != 0) {
Vec3Impl vec3 = new Vec3Impl(a, b, c);
Character navigate = navigates.get(vec3);
if (navigate == null) {
navigate = d++;
navigates.put(vec3, navigate);
addElement(navigate, step(vec3));
}
builder.setCharAt(i - 1, navigate);
a = 0;
b = 0;
c = 0;
}
}
String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]", "");
String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]", "");
if (built.contains("+")) {
addElement('+', notAir());
}
if (built.contains("-")) {
addElement('-', isAir());
}
shapes.put(name, built);
return this;
}
if (built.contains("+")) {
addElement('+', notAir());
}
if (built.contains("-")) {
addElement('-', isAir());
}
shapes.put(name, built);
return this;
}
public Builder<T> addElement(Character name, IStructureElement<T> structurePiece) {
elements.putIfAbsent(name, structurePiece);
return this;
}
public Builder<T> addElement(Character name, IStructureElement<T> structurePiece) {
elements.putIfAbsent(name, structurePiece);
return this;
}
public IStructureDefinition<T> build() {
Map<String, IStructureElement<T>[]> structures = compileStructureMap();
if (DEBUG_MODE) {
return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), structures);
} else {
return structures::get;
}
}
public IStructureDefinition<T> build() {
Map<String, IStructureElement<T>[]> structures = compileStructureMap();
if (DEBUG_MODE) {
return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), structures);
} else {
return structures::get;
}
}
@SuppressWarnings("unchecked")
private Map<String, IStructureElement<T>[]> compileElementSetMap() {
Set<Integer> missing = findMissing();
if (missing.isEmpty()) {
return shapes.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> e.getValue().chars()
.mapToObj(c -> (char) c)
.distinct()
.map(elements::get)
.toArray(IStructureElement[]::new)
));
} else {
throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " +
Arrays.toString(missing.toArray()));
}
}
@SuppressWarnings("unchecked")
private Map<String, IStructureElement<T>[]> compileElementSetMap() {
Set<Integer> missing = findMissing();
if (missing.isEmpty()) {
return shapes.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> e.getValue().chars()
.mapToObj(c -> (char) c)
.distinct()
.map(elements::get)
.toArray(IStructureElement[]::new)
));
} else {
throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " +
Arrays.toString(missing.toArray()));
}
}
@SuppressWarnings("unchecked")
private Map<String, IStructureElement<T>[]> compileStructureMap() {
Set<Integer> missing = findMissing();
if (missing.isEmpty()) {
return shapes.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> e.getValue().chars().mapToObj(c -> elements.get((char) c)).toArray(IStructureElement[]::new)
));
} else {
throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " +
Arrays.toString(missing.toArray()));
}
}
@SuppressWarnings("unchecked")
private Map<String, IStructureElement<T>[]> compileStructureMap() {
Set<Integer> missing = findMissing();
if (missing.isEmpty()) {
return shapes.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> e.getValue().chars().mapToObj(c -> elements.get((char) c)).toArray(IStructureElement[]::new)
));
} else {
throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " +
Arrays.toString(missing.toArray()));
}
}
private Set<Integer> findMissing() {
return shapes.values().stream()
.flatMapToInt(CharSequence::chars)
.filter(i -> !elements.containsKey((char) i))
.boxed()
.collect(Collectors.toSet());
}
}
private Set<Integer> findMissing() {
return shapes.values().stream()
.flatMapToInt(CharSequence::chars)
.filter(i -> !elements.containsKey((char) i))
.boxed()
.collect(Collectors.toSet());
}
}
public Map<Character, IStructureElement<T>> getElements() {
return elements;
}
public Map<Character, IStructureElement<T>> getElements() {
return elements;
}
public Map<String, String> getShapes() {
return shapes;
}
public Map<String, String> getShapes() {
return shapes;
}
public Map<String, IStructureElement<T>[]> getStructures() {
return structures;
}
public Map<String, IStructureElement<T>[]> getStructures() {
return structures;
}
@Override
public IStructureElement<T>[] getStructureFor(String name) {
IStructureElement<T>[] elements = structures.get(name);
if (elements == null)
throw new NoSuchElementException(name);
return elements;
}
}
@Override
public IStructureElement<T>[] getStructureFor(String name) {
IStructureElement<T>[] elements = structures.get(name);
if (elements == null)
throw new NoSuchElementException(name);
return elements;
}
}
File diff suppressed because it is too large. Load diff
@@ -4,12 +4,12 @@ package com.gtnewhorizon.structurelib.structure.adders;
import net.minecraft.block.Block;
public interface IBlockAdder<T> {
/**
* Callback on block added, needs to check if block is valid (and add it)
*
* @param block block attempted to add
* @param meta meta of block attempted to add
* @return is structure still valid
*/
boolean apply(T t, Block block, int meta);
/**
* Callback on block added, needs to check if block is valid (and add it)
*
* @param block block attempted to add
* @param meta meta of block attempted to add
* @return is structure still valid
*/
boolean apply(T t, Block block, int meta);
}
@@ -3,11 +3,11 @@ package com.gtnewhorizon.structurelib.structure.adders;
import net.minecraft.tileentity.TileEntity;
public interface ITileAdder<T> {
/**
* Callback to add hatch, needs to check if tile is valid (and add it)
*
* @param tileEntity tile
* @return managed to add hatch (structure still valid)
*/
boolean apply(T t, TileEntity tileEntity);
/**
* Callback to add hatch, needs to check if tile is valid (and add it)
*
* @param tileEntity tile
* @return managed to add hatch (structure still valid)
*/
boolean apply(T t, TileEntity tileEntity);
}
@@ -23,11 +23,15 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
* Gets the coordinate.
*/
public int get(int index) {
switch (index){
case 0: return val0;
case 1: return val1;
case 2: return val2;
default: return 0;
switch (index) {
case 0:
return val0;
case 1:
return val1;
case 2:
return val2;
default:
return 0;
}
}
@@ -64,17 +68,17 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
return new Vec3Impl(val0 - pos.val0, val1 - pos.val1, val2 - pos.val2);
}
public Vec3Impl add(int pos0,int pos1,int pos2) {
public Vec3Impl add(int pos0, int pos1, int pos2) {
return new Vec3Impl(val0 + pos0, val1 + pos1, val2 + pos2);
}
public Vec3Impl sub(int pos0,int pos1,int pos2) {
public Vec3Impl sub(int pos0, int pos1, int pos2) {
return new Vec3Impl(val0 - pos0, val1 - pos1, val2 - pos2);
}
public Vec3Impl crossProduct(Vec3Impl vec) {
return new Vec3Impl(val1 * vec.val2 - val2 * vec.val1, val2 * vec.val0 - val0 * vec.val2,
val0 * vec.val1 - val1 * vec.val0);
val0 * vec.val1 - val1 * vec.val0);
}
public boolean withinDistance(Vec3Impl to, double distance) {
@@ -95,17 +99,17 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
public double distanceSq(double x, double y, double z, boolean useCenter) {
double d0 = useCenter ? 0.5D : 0.0D;
double d1 = (double)val0 + d0 - x;
double d2 = (double)val1 + d0 - y;
double d3 = (double)val2 + d0 - z;
double d1 = (double) val0 + d0 - x;
double d2 = (double) val1 + d0 - y;
double d3 = (double) val2 + d0 - z;
return d1 * d1 + d2 * d2 + d3 * d3;
}
public int manhattanDistance(Vec3Impl to) {
float f = (float)Math.abs(to.val0 - val0);
float f1 = (float)Math.abs(to.val1 - val1);
float f2 = (float)Math.abs(to.val2 - val2);
return (int)(f + f1 + f2);
float f = (float) Math.abs(to.val0 - val0);
float f1 = (float) Math.abs(to.val1 - val1);
float f2 = (float) Math.abs(to.val2 - val2);
return (int) (f + f1 + f2);
}
@Override
@@ -114,14 +118,14 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
}
public Vec3Impl abs() {
return new Vec3Impl(Math.abs(val0),Math.abs(val1),Math.abs(val2));
return new Vec3Impl(Math.abs(val0), Math.abs(val1), Math.abs(val2));
}
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof Vec3Impl) {
Vec3Impl vec3i = (Vec3Impl)o;
Vec3Impl vec3i = (Vec3Impl) o;
return val0 == vec3i.val0 && val1 == vec3i.val1 && val2 == vec3i.val2;
}
return false;
@@ -130,4 +134,4 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
public int hashCode() {
return (val1 + val2 * 31) * 31 + val0;
}
}
}
@@ -43,10 +43,10 @@ public class XSTR extends Random {
private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
private static final AtomicLong seedUniquifier = new AtomicLong(8682522807148012L);
public static final XSTR XSTR_INSTANCE=new XSTR(){
public static final XSTR XSTR_INSTANCE = new XSTR() {
@Override
public synchronized void setSeed(long seed) {
if(!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) {
if (!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) {
throw new NoSuchMethodError("This is meant to be shared!, leave seed state alone!");
}
}
@@ -275,4 +275,4 @@ public class XSTR extends Random {
}
}
}
}
}