2016-08-03 04:01:47 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks.render;
|
|
|
|
|
2020-09-07 20:33:27 +02:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2016-12-09 21:36:43 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-08-03 04:01:47 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2020-09-07 20:33:27 +02:00
|
|
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
|
|
import net.minecraft.client.renderer.Quaternion;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
|
|
|
import net.minecraft.item.BlockItem;
|
2016-08-03 04:01:47 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-09-07 20:33:27 +02:00
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.Util;
|
2016-12-09 21:36:43 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-08-03 04:01:47 +02:00
|
|
|
|
2020-09-07 20:33:27 +02:00
|
|
|
// todo: migrate to client package
|
|
|
|
public class RenderEmpowerer extends TileEntityRenderer<TileEntityEmpowerer> {
|
|
|
|
public RenderEmpowerer(TileEntityRendererDispatcher rendererDispatcherIn) {
|
|
|
|
super(rendererDispatcherIn);
|
|
|
|
}
|
2016-08-03 04:01:47 +02:00
|
|
|
|
|
|
|
@Override
|
2020-09-07 20:33:27 +02:00
|
|
|
public void render(TileEntityEmpowerer tile, float partialTicks, MatrixStack matrices, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
|
|
|
|
// BlockPos pos = tile.getPos();
|
2019-02-27 19:53:05 +01:00
|
|
|
ItemStack stack = tile.inv.getStackInSlot(0);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
2020-09-07 20:33:27 +02:00
|
|
|
matrices.push();
|
|
|
|
// matrices.translate((float) pos.getX() + 0.5F, (float) pos.getY() + 1F, (float) pos.getZ() + 0.5F);
|
2016-08-03 04:01:47 +02:00
|
|
|
|
2020-09-07 20:33:27 +02:00
|
|
|
double boop = Util.nanoTime() / 800D;
|
|
|
|
matrices.translate(0D, Math.sin(boop % (2 * Math.PI)) * 0.065, 0D);
|
|
|
|
matrices.rotate(new Quaternion((float) (boop * 40D % 360), 0, 1, 0));
|
2016-08-03 04:01:47 +02:00
|
|
|
|
2020-09-07 20:33:27 +02:00
|
|
|
float scale = stack.getItem() instanceof BlockItem ? 0.85F : 0.65F;
|
|
|
|
matrices.scale(scale, scale, scale);
|
2019-05-02 09:10:29 +02:00
|
|
|
try {
|
2016-08-03 04:01:47 +02:00
|
|
|
AssetUtil.renderItemInWorld(stack);
|
2019-05-02 09:10:29 +02:00
|
|
|
} catch (Exception e) {
|
2020-09-07 20:33:27 +02:00
|
|
|
ActuallyAdditions.LOGGER.error("Something went wrong trying to render an item in an empowerer! The item is {}!", stack.getItem().getRegistryName(), e);
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 20:33:27 +02:00
|
|
|
matrices.pop();
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
2016-12-09 21:36:43 +01:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
int index = tile.recipeForRenderIndex;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (index >= 0 && ActuallyAdditionsAPI.EMPOWERER_RECIPES.size() > index) {
|
2016-12-09 21:36:43 +01:00
|
|
|
EmpowererRecipe recipe = ActuallyAdditionsAPI.EMPOWERER_RECIPES.get(index);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (recipe != null) {
|
2020-09-07 20:33:27 +02:00
|
|
|
Direction.Plane.HORIZONTAL.iterator().forEachRemaining(e -> {
|
|
|
|
BlockPos offset = tile.getPos().offset(e, 3);
|
2016-12-09 21:36:43 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
AssetUtil.renderLaser(tile.getPos().getX() + 0.5, tile.getPos().getY() + 0.5, tile.getPos().getZ() + 0.5, offset.getX() + 0.5, offset.getY() + 0.95, offset.getZ() + 0.5, 80, 1F, 0.1F, recipe.getParticleColors());
|
2020-09-07 20:33:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// original code of the above if it doesn't work
|
|
|
|
// @since 1.15-port
|
|
|
|
// for (int i = 0; i < Direction.Plane.HORIZONTAL; i++) {
|
|
|
|
// EnumFacing facing = EnumFacing.HORIZONTALS[i];
|
|
|
|
// BlockPos offset = tile.getPos().offset(facing, 3);
|
|
|
|
//
|
|
|
|
// AssetUtil.renderLaser(tile.getPos().getX() + 0.5, tile.getPos().getY() + 0.5, tile.getPos().getZ() + 0.5, offset.getX() + 0.5, offset.getY() + 0.95, offset.getZ() + 0.5, 80, 1F, 0.1F, recipe.getParticleColors());
|
|
|
|
// }
|
2016-12-09 21:36:43 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-03 04:01:47 +02:00
|
|
|
}
|
|
|
|
}
|