Browse Source

WIP support for model rotations, more API coverage

master
asie 1 year ago
parent
commit
48275994a7
46 changed files with 2801 additions and 38 deletions
  1. 19
    0
      src/main/java/pl/asie/minetestbridge/MinetestBridge.java
  2. 19
    0
      src/main/java/pl/asie/minetestbridge/MinetestGroupProxy.java
  3. 74
    2
      src/main/java/pl/asie/minetestbridge/MinetestLib.java
  4. 19
    0
      src/main/java/pl/asie/minetestbridge/MinetestMod.java
  5. 19
    0
      src/main/java/pl/asie/minetestbridge/MinetestSettingsLib.java
  6. 19
    0
      src/main/java/pl/asie/minetestbridge/ProxyClient.java
  7. 19
    0
      src/main/java/pl/asie/minetestbridge/ProxyCommon.java
  8. 19
    0
      src/main/java/pl/asie/minetestbridge/backwards/BackwardsBlockItemPopulator.java
  9. 19
    0
      src/main/java/pl/asie/minetestbridge/backwards/EntityWrapped.java
  10. 55
    0
      src/main/java/pl/asie/minetestbridge/backwards/ItemStackWrapped.java
  11. 19
    0
      src/main/java/pl/asie/minetestbridge/client/ItemNodeColorHandler.java
  12. 57
    1
      src/main/java/pl/asie/minetestbridge/client/ModelRegistry.java
  13. 4
    4
      src/main/java/pl/asie/minetestbridge/client/TextureAtlasSpriteCustom.java
  14. 19
    0
      src/main/java/pl/asie/minetestbridge/client/TextureMinetestSprite.java
  15. 19
    0
      src/main/java/pl/asie/minetestbridge/client/TextureRegistry.java
  16. 4
    4
      src/main/java/pl/asie/minetestbridge/client/util/BaseBakedModel.java
  17. 4
    4
      src/main/java/pl/asie/minetestbridge/client/util/CharsetFaceBakery.java
  18. 216
    0
      src/main/java/pl/asie/minetestbridge/client/util/ModelTransformer.java
  19. 19
    0
      src/main/java/pl/asie/minetestbridge/client/util/NodeboxBakedModel.java
  20. 4
    4
      src/main/java/pl/asie/minetestbridge/client/util/RenderUtils.java
  21. 4
    4
      src/main/java/pl/asie/minetestbridge/client/util/SimpleBakedModel.java
  22. 112
    0
      src/main/java/pl/asie/minetestbridge/client/util/TransformingBakedModel.java
  23. 5
    5
      src/main/java/pl/asie/minetestbridge/client/util/WrappedBakedModel.java
  24. 19
    0
      src/main/java/pl/asie/minetestbridge/node/BlockNode.java
  25. 19
    0
      src/main/java/pl/asie/minetestbridge/node/IBlockNode.java
  26. 19
    0
      src/main/java/pl/asie/minetestbridge/node/IItemNode.java
  27. 25
    0
      src/main/java/pl/asie/minetestbridge/node/ITileNode.java
  28. 19
    0
      src/main/java/pl/asie/minetestbridge/node/ItemBlockNode.java
  29. 27
    0
      src/main/java/pl/asie/minetestbridge/node/ItemNode.java
  30. 22
    1
      src/main/java/pl/asie/minetestbridge/node/TileEntityNode.java
  31. 19
    0
      src/main/java/pl/asie/minetestbridge/recipe/IMinetestRecipe.java
  32. 19
    0
      src/main/java/pl/asie/minetestbridge/recipe/MinetestRecipeProxy.java
  33. 19
    0
      src/main/java/pl/asie/minetestbridge/recipe/MinetestShapedRecipe.java
  34. 19
    0
      src/main/java/pl/asie/minetestbridge/recipe/MinetestShapelessRecipe.java
  35. 4
    4
      src/main/java/pl/asie/minetestbridge/util/EntityUtils.java
  36. 19
    0
      src/main/java/pl/asie/minetestbridge/util/LuaField.java
  37. 19
    0
      src/main/java/pl/asie/minetestbridge/util/LuaMethod.java
  38. 19
    0
      src/main/java/pl/asie/minetestbridge/util/LuaProxy.java
  39. 61
    0
      src/main/java/pl/asie/minetestbridge/util/MathUtils.java
  40. 19
    0
      src/main/java/pl/asie/minetestbridge/util/MethodHandleHelper.java
  41. 341
    0
      src/main/java/pl/asie/minetestbridge/util/Orientation.java
  42. 480
    0
      src/main/java/pl/asie/minetestbridge/util/Quaternion.java
  43. 225
    0
      src/main/java/pl/asie/minetestbridge/util/RayTraceUtils.java
  44. 597
    0
      src/main/java/pl/asie/minetestbridge/util/SpaceUtils.java
  45. 5
    5
      src/main/java/pl/asie/minetestbridge/util/TileBase.java
  46. 19
    0
      src/main/java/pl/asie/minetestbridge/util/UnlistedPropertyInteger.java

+ 19
- 0
src/main/java/pl/asie/minetestbridge/MinetestBridge.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import net.minecraft.block.Block;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/MinetestGroupProxy.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import com.google.common.collect.BiMap;

+ 74
- 2
src/main/java/pl/asie/minetestbridge/MinetestLib.java View File

@@ -1,7 +1,27 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
@@ -16,6 +36,8 @@ import org.luaj.vm2.lib.TwoArgFunction;
import org.luaj.vm2.lib.ZeroArgFunction;
import pl.asie.minetestbridge.backwards.ItemStackWrapped;
import pl.asie.minetestbridge.node.BlockNode;
import pl.asie.minetestbridge.node.ITileNode;
import pl.asie.minetestbridge.node.TileEntityNode;
import pl.asie.minetestbridge.recipe.MinetestRecipeProxy;
import pl.asie.minetestbridge.util.LuaField;
import pl.asie.minetestbridge.util.LuaMethod;
@@ -156,6 +178,11 @@ public class MinetestLib extends ZeroArgFunction {
return mod != null ? LuaValue.valueOf(mod.getName()) : LuaValue.NIL;
}

@LuaMethod
public LuaValue get_player_privs(String name) {
return LuaValue.tableOf(); // TODO
}

@LuaMethod
public LuaValue get_last_run_mod() {
MinetestMod mod = MinetestBridge.getLastRunMod();
@@ -205,16 +232,61 @@ public class MinetestLib extends ZeroArgFunction {
(w.getLightFor(EnumSkyBlock.BLOCK, mcPos) & 0xF)
| ((w.getLight(mcPos) & 0xF) << 4)
));
result.set("param2", LuaValue.valueOf(0));
int param2 = 0;
if (state.getBlock() instanceof BlockNode) {
// TODO: copy over param2 from TileEntityNode
TileEntity tile = w.getTileEntity(mcPos);
if (tile instanceof ITileNode) {
param2 = ((ITileNode) tile).getParam2();
}
}
result.set("param2", LuaValue.valueOf(param2));
return result;
} else {
return LuaValue.NIL;
}
}

@LuaMethod
public LuaValue check_for_falling(LuaValue pos) {
// TODO: Correct?
BlockPos mcPos = MinetestBridge.toMcPos(pos);
World w = MinetestBridge.getCurrentWorld();
w.neighborChanged(mcPos, w.getBlockState(mcPos).getBlock(), mcPos);
return null;
}

@LuaMethod
public LuaValue swap_node(LuaValue pos, LuaValue node) {
BlockPos mcPos = MinetestBridge.toMcPos(pos);
World w = MinetestBridge.getCurrentWorld();
IBlockState state = w.getBlockState(mcPos);
String currName = MinetestBridge.asMtName(state.getBlock().getRegistryName());
if (!currName.equals(node.get("name").optjstring("ignore"))) {
MinetestBridge.logger.warn("Swapping nodes of different types is not supported yet!");
}

LuaValue param2 = node.get("param2");
if (param2.isnumber() && state.getBlock() instanceof BlockNode) {
TileEntity tile = w.getTileEntity(mcPos);
if (tile instanceof ITileNode) {
((ITileNode) tile).setParam2(param2.toint());
}
}

return null;
}

@LuaMethod
public LuaValue set_node(LuaValue pos, LuaValue node) {
MinetestBridge.logger.warn("TODO: set_node");
return null;
}

@LuaMethod
public LuaValue add_node(LuaValue pos, LuaValue node) {
return set_node(pos, node);
}

@LuaMethod
public LuaValue remove_node(LuaValue pos) {
BlockPos mcPos = MinetestBridge.toMcPos(pos);

+ 19
- 0
src/main/java/pl/asie/minetestbridge/MinetestMod.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import com.google.common.base.Charsets;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/MinetestSettingsLib.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import org.luaj.vm2.LuaTable;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/ProxyClient.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import net.minecraft.item.Item;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/ProxyCommon.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge;

import net.minecraft.item.Item;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/backwards/BackwardsBlockItemPopulator.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.backwards;

import net.minecraft.block.Block;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/backwards/EntityWrapped.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.backwards;

import net.minecraft.entity.Entity;

+ 55
- 0
src/main/java/pl/asie/minetestbridge/backwards/ItemStackWrapped.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.backwards;

import net.minecraft.item.Item;
@@ -45,6 +64,38 @@ public class ItemStackWrapped extends LuaTable {
return stack;
}

@LuaMethod
public LuaValue get_wear(LuaValue wrap) {
if (!stack.isItemStackDamageable()) {
return LuaValue.valueOf(0);
}

return LuaValue.valueOf(stack.getItemDamage() * 65535 / stack.getMaxDamage());
}

@LuaMethod
public LuaValue set_wear(LuaValue wrap, LuaValue amount) {
if (stack.isItemStackDamageable()) {
stack.setItemDamage(stack.getItemDamage() + (amount.optint(0) * stack.getMaxDamage() / 65535));
}

return LuaValue.valueOf(stack.getItemDamage() == 0);
}

@LuaMethod
public LuaValue add_wear(LuaValue wrap, LuaValue amount) {
if (stack.isItemStackDamageable()) {
stack.setItemDamage((amount.optint(0) * stack.getMaxDamage() / 65535));
}

return null;
}

@LuaMethod
public LuaValue is_known(LuaValue wrap) {
return LuaValue.valueOf(true);
}

@LuaMethod
public LuaValue is_empty(LuaValue wrap) {
return LuaValue.valueOf(stack.isEmpty());
@@ -52,6 +103,10 @@ public class ItemStackWrapped extends LuaTable {

@LuaMethod
public LuaValue get_name(LuaValue wrap) {
if (stack.isEmpty()) {
return LuaValue.valueOf("ignore");
}

return LuaValue.valueOf(MinetestBridge.asMtName(stack.getItem().getRegistryName()));
}


+ 19
- 0
src/main/java/pl/asie/minetestbridge/client/ItemNodeColorHandler.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client;

import net.minecraft.client.renderer.color.IItemColor;

+ 57
- 1
src/main/java/pl/asie/minetestbridge/client/ModelRegistry.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client;

import com.google.common.collect.ImmutableList;
@@ -25,12 +44,13 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.ast.Str;
import pl.asie.charset.lib.utils.Orientation;
import pl.asie.minetestbridge.MinetestBridge;
import pl.asie.minetestbridge.MinetestLib;
import pl.asie.minetestbridge.client.util.NodeboxBakedModel;
import pl.asie.minetestbridge.client.util.TransformingBakedModel;
import pl.asie.minetestbridge.node.BlockNode;
import pl.asie.minetestbridge.node.ItemNode;
import pl.asie.minetestbridge.util.Orientation;

import java.util.HashMap;
import java.util.Map;
@@ -121,6 +141,11 @@ public class ModelRegistry implements IStateMapper {
bm = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
}

ITransformation[] transformations = getTransformations(value);
if (transformations.length > 1) {
bm = new TransformingBakedModel(bm, transformations);
}

if (bm != null) {
event.getModelRegistry().putObject(new ModelResourceLocation(loc, "normal"), bm);
event.getModelRegistry().putObject(new ModelResourceLocation(loc, "inventory"), bm);
@@ -134,6 +159,37 @@ public class ModelRegistry implements IStateMapper {

static {
types.put("none", new ITransformation[]{ModelRotation.X0_Y0});
types.put("facedir", new ITransformation[] {
Orientation.FACE_UP_POINT_NORTH,
Orientation.FACE_UP_POINT_EAST,
Orientation.FACE_UP_POINT_SOUTH,
Orientation.FACE_UP_POINT_WEST,

Orientation.FACE_SOUTH_POINT_UP,
Orientation.FACE_SOUTH_POINT_EAST,
Orientation.FACE_SOUTH_POINT_DOWN,
Orientation.FACE_SOUTH_POINT_WEST,

Orientation.FACE_NORTH_POINT_UP,
Orientation.FACE_NORTH_POINT_EAST,
Orientation.FACE_NORTH_POINT_DOWN,
Orientation.FACE_NORTH_POINT_WEST,

Orientation.FACE_EAST_POINT_UP,
Orientation.FACE_EAST_POINT_SOUTH,
Orientation.FACE_EAST_POINT_DOWN,
Orientation.FACE_EAST_POINT_NORTH,

Orientation.FACE_WEST_POINT_UP,
Orientation.FACE_WEST_POINT_SOUTH,
Orientation.FACE_WEST_POINT_DOWN,
Orientation.FACE_WEST_POINT_NORTH,

Orientation.FACE_DOWN_POINT_NORTH,
Orientation.FACE_DOWN_POINT_EAST,
Orientation.FACE_DOWN_POINT_SOUTH,
Orientation.FACE_DOWN_POINT_WEST,
});
}

private ITransformation[] getTransformations(LuaValue value) {

+ 4
- 4
src/main/java/pl/asie/minetestbridge/client/TextureAtlasSpriteCustom.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/client/TextureMinetestSprite.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/client/TextureRegistry.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client;

import com.google.common.eventbus.Subscribe;

+ 4
- 4
src/main/java/pl/asie/minetestbridge/client/util/BaseBakedModel.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

+ 4
- 4
src/main/java/pl/asie/minetestbridge/client/util/CharsetFaceBakery.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

+ 216
- 0
src/main/java/pl/asie/minetestbridge/client/util/ModelTransformer.java View File

@@ -0,0 +1,216 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.LightUtil;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.ITransformation;
import net.minecraftforge.common.model.TRSRTransformation;
import org.lwjgl.util.vector.Vector3f;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Function;

public final class ModelTransformer {
private ModelTransformer() {

}

public static IBakedModel transform(IBakedModel model, IBlockState state, long rand, IVertexTransformer transformer) {
return transform(model, state, rand, transformer, null);
}

public static IBakedModel transform(IBakedModel model, IBlockState state, long rand, IVertexTransformer transformer, @Nullable Function<BakedQuad, VertexFormat> format) {
SimpleBakedModel out = new SimpleBakedModel(model);

for (int i = 0; i <= 6; i++) {
EnumFacing side = (i == 6 ? null : EnumFacing.byIndex(i));
for (BakedQuad quad : model.getQuads(state, side, rand)) {
out.addQuad(side, transform(quad, transformer, format));
}
}

return out;
}

public static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer) {
return transform(quad, transformer, null);
}

public static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer, @Nullable Function<BakedQuad, VertexFormat> format2) {
VertexFormat format = format2 != null ? format2.apply(quad) : quad.getFormat();
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
LightUtil.putBakedQuad(new VertexTransformerWrapper(builder, quad, transformer), quad);
return builder.build();
}

private static final class VertexTransformerWrapper implements IVertexConsumer {
private final IVertexConsumer parent;
private final BakedQuad parentQuad;
private final VertexFormat format;
private final IVertexTransformer transformer;

public VertexTransformerWrapper(IVertexConsumer parent, BakedQuad parentQuad, IVertexTransformer transformer) {
this.parent = parent;
this.parentQuad = parentQuad;
this.format = parent.getVertexFormat();
this.transformer = transformer;
}

@Override
public VertexFormat getVertexFormat() {
return format;
}

@Override
public void setQuadTint(int tint) {
parent.setQuadTint(tint);
}

@Override
public void setQuadOrientation(EnumFacing orientation) {
parent.setQuadOrientation(orientation);
}

@Override
public void setApplyDiffuseLighting(boolean diffuse) {
parent.setApplyDiffuseLighting(diffuse);
}

@Override
public void setTexture(TextureAtlasSprite texture) {
parent.setTexture(texture);
}

@Override
public void put(int elementId, float... data) {
VertexFormatElement element = format.getElement(elementId);
parent.put(elementId, transformer.transform(parentQuad, element, data));
}
}

public interface IVertexTransformer {
float[] transform(BakedQuad quad, VertexFormatElement element, float... data);

static IVertexTransformer transform(IModelState state, @Nullable ItemCameraTransforms.TransformType type) {
Optional<TRSRTransformation> transformation = state.apply(Optional.ofNullable(type));
if (transformation.isPresent()) {
return transform(transformation.get());
} else {
return (q, e, d) -> d;
}
}

static IVertexTransformer transform(ITransformation transformation) {
return (quad, element, data) -> {
switch (element.getUsage()) {
case POSITION:
case NORMAL:
Vector3f vec = new Vector3f(data[0], data[1], data[2]);
ForgeHooksClient.transform(vec, transformation.getMatrix());
if (element.getUsage() == VertexFormatElement.EnumUsage.NORMAL) {
vec.normalise();
}
return new float[] { vec.x, vec.y, vec.z, data[3] };
default:
return data;
}
};
}

static IVertexTransformer tint(int color) {
float[] c = new float[] {
((color >> 24) & 0xFF) / 255.0f,
((color >> 16) & 0xFF) / 255.0f,
((color >> 8) & 0xFF) / 255.0f,
((color) & 0xFF) / 255.0f
};
return tint(c);
}

static IVertexTransformer tint(float[] color) {
return (quad, element, data) -> {
switch (element.getUsage()) {
case COLOR:
return new float[]{data[0] * color[1], data[1] * color[2], data[2] * color[3], data[3] * color[0]};
default:
return data;
}
};
}

static IVertexTransformer tintByIndex(int[] colorInts) {
final float[][] color = new float[colorInts.length][];

return (quad, element, data) -> {
if (element.getUsage() == VertexFormatElement.EnumUsage.COLOR) {
if (quad.getTintIndex() >= 0 && quad.getTintIndex() < color.length) {
if (color[quad.getTintIndex()] == null) {
color[quad.getTintIndex()] = new float[]{
((colorInts[quad.getTintIndex()] >> 24) & 0xFF) / 255.0f,
((colorInts[quad.getTintIndex()] >> 16) & 0xFF) / 255.0f,
((colorInts[quad.getTintIndex()] >> 8) & 0xFF) / 255.0f,
((colorInts[quad.getTintIndex()]) & 0xFF) / 255.0f
};
}

return new float[]{data[0] * color[quad.getTintIndex()][1], data[1] * color[quad.getTintIndex()][2], data[2] * color[quad.getTintIndex()][3], data[3] * color[quad.getTintIndex()][0]};
}
}

return data;
};
}

static IVertexTransformer tintByIndex(float[][] color) {
return (quad, element, data) -> {
if (element.getUsage() == VertexFormatElement.EnumUsage.COLOR) {
if (quad.getTintIndex() >= 0 && quad.getTintIndex() < color.length) {
return new float[]{data[0] * color[quad.getTintIndex()][1], data[1] * color[quad.getTintIndex()][2], data[2] * color[quad.getTintIndex()][3], data[3] * color[quad.getTintIndex()][0]};
}
}

return data;
};
}

static IVertexTransformer compose(IVertexTransformer... ts) {
return (quad, element, data) -> {
for (IVertexTransformer t : ts) {
data = t.transform(quad, element, data);
}
return data;
};
}
}
}

+ 19
- 0
src/main/java/pl/asie/minetestbridge/client/util/NodeboxBakedModel.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

import net.minecraft.block.state.IBlockState;

+ 4
- 4
src/main/java/pl/asie/minetestbridge/client/util/RenderUtils.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

+ 4
- 4
src/main/java/pl/asie/minetestbridge/client/util/SimpleBakedModel.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

+ 112
- 0
src/main/java/pl/asie/minetestbridge/client/util/TransformingBakedModel.java View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.model.ITransformation;
import net.minecraftforge.common.property.IExtendedBlockState;
import org.apache.commons.lang3.tuple.Pair;
import pl.asie.minetestbridge.node.BlockNode;

import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.ArrayList;
import java.util.List;

public class TransformingBakedModel implements IBakedModel {
protected final IBakedModel parent;
private final ITransformation[] transformations;

public TransformingBakedModel(IBakedModel parent, ITransformation[] transformations) {
this.parent = parent;
this.transformations = transformations;
}

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
// TODO: cache you, cache me
if (state instanceof IExtendedBlockState) {
int i = ((IExtendedBlockState) state).getValue(BlockNode.PARAM2) % MathHelper.smallestEncompassingPowerOfTwo(transformations.length);
ITransformation transformation = i >= transformations.length ? transformations[0] : transformations[i];
List<BakedQuad> quads = parent.getQuads(state, side == null ? null : transformation.rotate(side), rand);

List<BakedQuad> newQuads = new ArrayList<>(quads.size());
for (BakedQuad quad : quads) {
newQuads.add(
ModelTransformer.transform(quad,
ModelTransformer.IVertexTransformer.transform(transformation)
)
);
}

return newQuads;
} else {
List<BakedQuad> quads = parent.getQuads(state, side, rand);
return quads;
}
}

@Override
public boolean isAmbientOcclusion() {
return parent.isAmbientOcclusion();
}

@Override
public boolean isGui3d() {
return parent.isGui3d();
}

@Override
public boolean isBuiltInRenderer() {
return false;
}

@Override
public TextureAtlasSprite getParticleTexture() {
return parent.getParticleTexture();
}

@Override
public ItemOverrideList getOverrides() {
return parent.getOverrides();
}

@Override
public ItemCameraTransforms getItemCameraTransforms() {
return parent.getItemCameraTransforms();
}

@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
Pair<? extends IBakedModel, Matrix4f> pair = parent.handlePerspective(cameraTransformType);
if (pair.getLeft() == parent) {
return Pair.of(this, pair.getRight());
} else {
return pair;
}
}
}

+ 5
- 5
src/main/java/pl/asie/minetestbridge/client/util/WrappedBakedModel.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.client.util;
@@ -29,7 +29,7 @@ import javax.annotation.Nullable;
import java.util.List;

public class WrappedBakedModel extends BaseBakedModel {
private final IBakedModel parent;
protected final IBakedModel parent;
private final TextureAtlasSprite particleSprite;

public WrappedBakedModel(IBakedModel parent) {

+ 19
- 0
src/main/java/pl/asie/minetestbridge/node/BlockNode.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import net.minecraft.block.Block;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/node/IBlockNode.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import org.luaj.vm2.LuaTable;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/node/IItemNode.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import org.luaj.vm2.LuaTable;

+ 25
- 0
src/main/java/pl/asie/minetestbridge/node/ITileNode.java View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

public interface ITileNode {
int getParam2();
void setParam2(int param2);
}

+ 19
- 0
src/main/java/pl/asie/minetestbridge/node/ItemBlockNode.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import net.minecraft.block.Block;

+ 27
- 0
src/main/java/pl/asie/minetestbridge/node/ItemNode.java View File

@@ -1,6 +1,26 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
@@ -17,10 +37,17 @@ import pl.asie.minetestbridge.backwards.ItemStackWrapped;

public class ItemNode extends Item implements IItemNode {
private final LuaTable table;
private final boolean isTool;

public ItemNode(LuaTable table) {
this.table = table;
this.isTool = table.get("type").optjstring("").equals("tool");
setCreativeTab(MinetestBridge.tab);
setMaxStackSize(table.get("stack_max").optint(Items.AIR.getItemStackLimit()));

if (isTool) {
setMaxDamage(16383);
}
}

@Override

+ 22
- 1
src/main/java/pl/asie/minetestbridge/node/TileEntityNode.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.node;

import net.minecraft.block.state.IBlockState;
@@ -7,17 +26,19 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import pl.asie.minetestbridge.util.TileBase;

public class TileEntityNode extends TileBase {
public class TileEntityNode extends TileBase implements ITileNode {
private int param2;

public TileEntityNode() {

}

@Override
public int getParam2() {
return param2;
}

@Override
public void setParam2(int val) {
if (val != param2) {
param2 = val;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/recipe/IMinetestRecipe.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.recipe;

import net.minecraft.item.crafting.IRecipe;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/recipe/MinetestRecipeProxy.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.recipe;

import net.minecraft.inventory.InventoryCrafting;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/recipe/MinetestShapedRecipe.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.recipe;

import net.minecraft.inventory.InventoryCrafting;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/recipe/MinetestShapelessRecipe.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.recipe;

import net.minecraft.inventory.InventoryCrafting;

+ 4
- 4
src/main/java/pl/asie/minetestbridge/util/EntityUtils.java View File

@@ -1,20 +1,20 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of Charset.
* This file is part of MinetestBridge.
*
* Charset is free software: you can redistribute it and/or modify
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/util/LuaField.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import java.lang.annotation.Retention;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/util/LuaMethod.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import java.lang.annotation.Retention;

+ 19
- 0
src/main/java/pl/asie/minetestbridge/util/LuaProxy.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import jdk.nashorn.internal.lookup.MethodHandleFactory;

+ 61
- 0
src/main/java/pl/asie/minetestbridge/util/MathUtils.java View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;

public final class MathUtils {
private MathUtils() {

}

public static Matrix4f newJavaxIdentityMat() {
Matrix4f ret = new Matrix4f();
ret.setIdentity();
return ret;
}

public static float interpolate(float a, float b, float amount) {
return (a * (1.0f - amount) + b * amount);
}

public static float linePointDistance(Vec3d lineStart, Vec3d lineEnd, Vec3d point) {
Vec3d first = lineStart.subtract(point);
Vec3d second = lineEnd.subtract(point);

return MathHelper.sqrt(first.crossProduct(second).lengthSquared() / second.lengthSquared());
}

public static Vec3d interpolate(Vec3d one, Vec3d two, float amount) {
return new Vec3d(
one.x + (two.x - one.x) * amount,
one.y + (two.y - one.y) * amount,
one.z + (two.z - one.z) * amount
);
}
}

+ 19
- 0
src/main/java/pl/asie/minetestbridge/util/MethodHandleHelper.java View File

@@ -1,3 +1,22 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import net.minecraft.launchwrapper.Launch;

+ 341
- 0
src/main/java/pl/asie/minetestbridge/util/Orientation.java View File

@@ -0,0 +1,341 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.model.IModelPart;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.ITransformation;
import net.minecraftforge.common.model.TRSRTransformation;

import javax.annotation.Nonnull;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import java.util.Optional;

public enum Orientation implements IModelState, IStringSerializable, ITransformation {
FACE_DOWN_POINT_SOUTH(EnumFacing.DOWN, EnumFacing.SOUTH),
FACE_DOWN_POINT_NORTH(EnumFacing.DOWN, EnumFacing.NORTH),
FACE_DOWN_POINT_EAST(EnumFacing.DOWN, EnumFacing.EAST),
FACE_DOWN_POINT_WEST(EnumFacing.DOWN, EnumFacing.WEST),

FACE_UP_POINT_SOUTH(EnumFacing.UP, EnumFacing.SOUTH),
FACE_UP_POINT_NORTH(EnumFacing.UP, EnumFacing.NORTH),
FACE_UP_POINT_EAST(EnumFacing.UP, EnumFacing.EAST),
FACE_UP_POINT_WEST(EnumFacing.UP, EnumFacing.WEST),

FACE_NORTH_POINT_UP(EnumFacing.NORTH, EnumFacing.UP),
FACE_NORTH_POINT_DOWN(EnumFacing.NORTH, EnumFacing.DOWN),
FACE_NORTH_POINT_EAST(EnumFacing.NORTH, EnumFacing.EAST),
FACE_NORTH_POINT_WEST(EnumFacing.NORTH, EnumFacing.WEST),

FACE_SOUTH_POINT_UP(EnumFacing.SOUTH, EnumFacing.UP),
FACE_SOUTH_POINT_DOWN(EnumFacing.SOUTH, EnumFacing.DOWN),
FACE_SOUTH_POINT_EAST(EnumFacing.SOUTH, EnumFacing.EAST),
FACE_SOUTH_POINT_WEST(EnumFacing.SOUTH, EnumFacing.WEST),

FACE_WEST_POINT_UP(EnumFacing.WEST, EnumFacing.UP),
FACE_WEST_POINT_DOWN(EnumFacing.WEST, EnumFacing.DOWN),
FACE_WEST_POINT_SOUTH(EnumFacing.WEST, EnumFacing.SOUTH),
FACE_WEST_POINT_NORTH(EnumFacing.WEST, EnumFacing.NORTH),

FACE_EAST_POINT_UP(EnumFacing.EAST, EnumFacing.UP),
FACE_EAST_POINT_DOWN(EnumFacing.EAST, EnumFacing.DOWN),
FACE_EAST_POINT_SOUTH(EnumFacing.EAST, EnumFacing.SOUTH),
FACE_EAST_POINT_NORTH(EnumFacing.EAST, EnumFacing.NORTH);

/**
* This value is what a Dispenser has. It can point in any of the 6 directions.
*/
public final EnumFacing facing;
/**
* This is what various RedPower-style machines add. It can only point in 4 directions. It can not point in the facing direction, nor in the opposite direction.
*/
public final EnumFacing top;
private final Orientation[] rotations = new Orientation[EnumFacing.VALUES.length];
private final Orientation[] mirrors = new Orientation[2];
private int rotation;
private Orientation swapped;
private final EnumFacing[] dirRotations = new EnumFacing[EnumFacing.VALUES.length]; // Admitedly we could just use values() here. But that's ugly.
private static final Orientation[] valuesCache = values();

Orientation(EnumFacing facing, EnumFacing top) {
this.facing = facing;
this.top = top;
}

static {
for (Orientation o : values()) {
for (Orientation t : values()) {
if (o.facing == t.top && o.top == t.facing) {
o.swapped = t;
break;
}
}
}

for (Orientation o : values()) {
o.setupRotationFacing();
}
for (Orientation o : values()) {
o.setupRotationTop();
}
for (Orientation o : values()) {
o.setupRotationAll();
}
for (Orientation o : values()) {
o.setupDirectionRotation();
}
for (Orientation o : values()) {
o.mirrors[0] = o.setupRotationMirror(EnumFacing.Axis.X); /* FRONT_BACK */
o.mirrors[1] = o.setupRotationMirror(EnumFacing.Axis.Z); /* LEFT_RIGHT */
}

if (valuesCache.length == 0) {
throw new RuntimeException("this is weird");
}
}

private Orientation setupRotationMirror(EnumFacing.Axis axis) {
if (facing.getAxis() == axis) {
return find(facing.getOpposite(), top);
} else if (top.getAxis() == axis) {
return find(facing, top.getOpposite());
} else {
return this;
}
}

private void setupRotationFacing() {
rotations[facing.getOpposite().ordinal()] = find(facing, SpaceUtils.rotateCounterclockwise(top, facing));
rotations[facing.ordinal()] = find(facing, SpaceUtils.rotateClockwise(top, facing));
}

private void setupRotationTop() {
rotations[top.getOpposite().ordinal()] = getSwapped().getNextRotationOnFace().getSwapped();
rotations[top.ordinal()] = getSwapped().getPrevRotationOnFace().getSwapped();
}

private void setupRotationAll() {
for (EnumFacing dir : EnumFacing.VALUES) {
if (dir.getAxis() != facing.getAxis() && dir.getAxis() != top.getAxis()) {
if (dir.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE) {
rotations[dir.ordinal()] = find(facing.rotateAround(dir.getAxis()), top.rotateAround(dir.getAxis()));
} else {
rotations[dir.ordinal()] = find(facing.rotateAround(dir.getAxis()).rotateAround(dir.getAxis()).rotateAround(dir.getAxis()), top.rotateAround(dir.getAxis()).rotateAround(dir.getAxis()).rotateAround(dir.getAxis()));
}
}
}

int rcount = 0;
Orientation head = fromDirection(facing);
for (int i = 0; i < 5; i++) {
if (head == this) {
rotation = rcount;
}
rcount++;
head = head.getNextRotationOnFace();
}
}

private void setupDirectionRotation() {
for (EnumFacing dir : EnumFacing.values()) {
Vec3d v = SpaceUtils.fromDirection(dir);
Quaternion.fromOrientation(this).applyRotation(v);
dirRotations[dir.ordinal()] = SpaceUtils.getClosestDirection(v, null);
}
}
private static Orientation find(EnumFacing f, EnumFacing t) {
for (int i = f.ordinal() * 4; i < f.ordinal() * 4 + 4; i++) {
Orientation o = valuesCache[i];
if (o.top == t) {
return o;
}
}
return null;
}

@Override
public String getName() {
return name().toLowerCase();
}
public Orientation rotateOnFace(int count) {
count = count % 4;
if (count > 0) {
Orientation here = this;
while (count > 0) {
count--;
here = here.getNextRotationOnFace();
}
return here;
} else if (count < 0) {
Orientation here = this;
while (count < 0) {
count++;
here = here.getPrevRotationOnFace();
}
return here;
} else {
return this;
}
}
public Orientation getNextRotationOnFace() {
return rotations[facing.getOpposite().ordinal()];
}
public Orientation getPrevRotationOnFace() {
return rotations[facing.ordinal()];
}
public Orientation getNextRotationOnTop() {
return rotations[top.getOpposite().ordinal()];
}
public Orientation getPrevRotationOnTop() {
return rotations[top.ordinal()];
}
public Orientation rotateOnTop(int count) {
return getSwapped().rotateOnFace(count).getSwapped();
}
public static Orientation getOrientation(int index) {
if (index >= 0 && index < valuesCache.length) {
return valuesCache[index];
}
return null;
}
public static Orientation fromDirection(EnumFacing dir) {
if (dir == null) {
return null;
}
return valuesCache[dir.ordinal()*4];
}

@Deprecated
public TRSRTransformation toTransformation() {
return new TRSRTransformation(getMatrix());
}

private Matrix4f _matrix_cache;

@Override
public Matrix4f getMatrix() {
if (_matrix_cache == null) {
Quaternion quat = Quaternion.fromOrientation(this.getSwapped());
Matrix4f trans = MathUtils.newJavaxIdentityMat();
Matrix4f rot = MathUtils.newJavaxIdentityMat();
Matrix4f r90 = MathUtils.newJavaxIdentityMat();

r90.setRotation(new AxisAngle4f(0, 1, 0, (float) Math.PI / 2));

trans.setTranslation(new Vector3f(0.5F, 0.5F, 0.5F));
Matrix4f iTrans = new Matrix4f(trans);
iTrans.invert();
rot.setRotation(quat.toJavax());
rot.mul(r90);

trans.mul(rot);
trans.mul(iTrans);
_matrix_cache = trans;
}

return (Matrix4f) _matrix_cache.clone();
}

@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part) {
return part.isPresent() ? Optional.empty() : Optional.of(new TRSRTransformation(getMatrix()));
}

@Override
public EnumFacing rotate(EnumFacing facing) {
return TRSRTransformation.rotate(getMatrix(), facing);
}

@Override
public int rotate(EnumFacing facing, int vertexIndex) {
// FIXME see TRSRTransformation
return toTransformation().rotate(facing, vertexIndex);
}

/**
* @param newTop
* @return {@link Orientation} with the same direction, but facing newTop. If the top can't be change to that direction because it is already facing that direction, it returns UNKNOWN.
*/
public Orientation pointTopTo(EnumFacing newTop) {
Orientation fzo = this;
for (int i = 0; i < 4; i++) {
if (fzo.top == newTop) {
return fzo;
}
fzo = fzo.getNextRotationOnFace();
}
return null;
}

public Orientation mirror(@Nonnull Mirror mirror) {
switch (mirror) {
case NONE:
return this;
case FRONT_BACK:
return mirrors[0];
case LEFT_RIGHT:
return mirrors[1];
default:
throw new RuntimeException("Unknown Mirror type " + mirror.name());
}
}
public Orientation rotateAround(@Nonnull EnumFacing axis) {
return rotations[axis.ordinal()];
}
public int getRotation() {
return rotation;
}
public Vec3d getDiagonalVector() {
return new Vec3d(
facing.getDirectionVec().getX() + top.getDirectionVec().getX(),
facing.getDirectionVec().getY() + top.getDirectionVec().getY(),
facing.getDirectionVec().getZ() + top.getDirectionVec().getZ()
);
}

public Orientation getSwapped() {
return swapped;
}

public EnumFacing applyRotation(EnumFacing dir) {
return dirRotations[dir.ordinal()];
}
}

+ 480
- 0
src/main/java/pl/asie/minetestbridge/util/Quaternion.java View File

@@ -0,0 +1,480 @@
/*
* Copyright (c) 2015, 2016, 2017, 2018 Adrian Siekierka
*
* This file is part of MinetestBridge.
*
* MinetestBridge is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MinetestBridge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MinetestBridge. If not, see <http://www.gnu.org/licenses/>.
*/

package pl.asie.minetestbridge.util;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.vecmath.Quat4d;
import javax.vecmath.Quat4f;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;

public class Quaternion {
public static final Quaternion ORIGIN = new Quaternion();
public final double w, x, y, z;

//Data functions
public Quaternion() {
this(1, 0, 0, 0);
}
public Quaternion(double w, double x, double y, double z) {
this.w = w;
this.x = x;
this.y = y;
this.z = z;
}
public Quaternion(Quaternion orig) {
this(orig.w, orig.x, orig.y, orig.z);
}
public Quaternion(double[] init) {
this(init[0], init[1], init[2], init[3]);
assert init.length == 4;
}

public static Quaternion fromDirection(double w, EnumFacing dir) {
return new Quaternion(w, dir.getDirectionVec().getX(), dir.getDirectionVec().getY(), dir.getDirectionVec().getZ());
}

public Quaternion(Vec3d v) {
this(0, v.x, v.y, v.z);
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj instanceof Quaternion) {
Quaternion other = (Quaternion) obj;
return w == other.w && x == other.x && y == other.y && z == other.z;
}
return false;
}
@Override
public String toString() {
String m = "";
double mag = this.magnitude();
if (mag != 1.0) {
m = " MAG=" + mag;
}
return "Q<w=" + w + ", " + x + ", " + y + ", " + z + ">" + m;
}
public void writeToTag(NBTTagCompound tag, String prefix) {
tag.setDouble(prefix+"w", w);
tag.setDouble(prefix+"x", x);
tag.setDouble(prefix+"y", y);
tag.setDouble(prefix+"z", z);
}
public static Quaternion loadFromTag(NBTTagCompound tag, String prefix) {
return new Quaternion(tag.getDouble(prefix+"w"), tag.getDouble(prefix+"x"), tag.getDouble(prefix+"y"), tag.getDouble(prefix+"z"));
}
public void write(DataOutput out) throws IOException {
double[] d = toStaticArray();
for (int i = 0; i < d.length; i++) {
out.writeDouble(d[i]);
}
}
public void write(ByteBuf out) {
double[] d = toStaticArray();
for (int i = 0; i < d.length; i++) {
out.writeDouble(d[i]);
}
}
public void write(DataOutputStream out) throws IOException {
double[] d = toStaticArray();
for (int i = 0; i < d.length; i++) {
out.writeDouble(d[i]);
}
}
public static Quaternion read(DataInput in) throws IOException {
double[] d = localStaticArray.get();
for (int i = 0; i < d.length; i++) {
d[i] = in.readDouble();
}
return new Quaternion(d);
}
public static Quaternion read(ByteBuf in) throws IOException {
double[] d = localStaticArray.get();
for (int i = 0; i < d.length; i++) {
d[i] = in.readDouble();
}
return new Quaternion(d);
}

public double[] fillArray(double[] out) {
out[0] = w;
out[1] = x;
out[2] = y;
out[3] = z;
return out;
}
public double[] toArray() {
return fillArray(new double[4]);
}

private static ThreadLocal<double[]> localStaticArray = ThreadLocal.withInitial(() -> new double[4]);

public double[] toStaticArray() {
return fillArray(localStaticArray.get());
}
public boolean isZero() {