@@ -7,6 +7,7 @@
import com.teamwizardry.librarianlib.features.particle.ParticleSpawner;
import com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV;
import com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut;
import com.teamwizardry.librarianlib.features.tesr.TileRenderHandler;
import com.teamwizardry.wizardry.Wizardry;
import com.teamwizardry.wizardry.api.Constants;
import com.teamwizardry.wizardry.api.block.CachedStructure;
@@ -21,40 +22,44 @@
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.opengl.GL11;

import java.awt.*;

/**
* Created by LordSaad.
*/
public class TileManaBatteryRenderer extends TileEntitySpecialRenderer<TileManaBattery> {
@Mod.EventBusSubscriber(modid = Wizardry.MODID)
public class TileManaBatteryRenderer extends TileRenderHandler<TileManaBattery> {

private IBakedModel modelRing, modelCrystal, modelRingOuter;
private static IBakedModel modelRing, modelCrystal, modelRingOuter;
private CachedStructure cachedStructure;

public TileManaBatteryRenderer() {
MinecraftForge.EVENT_BUS.register(this);
public TileManaBatteryRenderer(@NotNull TileManaBattery manaBattery) {
super(manaBattery);
cachedStructure = new CachedStructure(((IStructure) tile.getBlockType()).getStructure().loc, tile.getWorld());
}

@SubscribeEvent
public void reload(ClientProxy.ResourceReloadEvent event) {
public static void reload(ClientProxy.ResourceReloadEvent event) {
modelRing = null;
modelCrystal = null;
modelRingOuter = null;
}

private void getBakedModels() {
private static void getBakedModels() {
IModel model;
if (modelRing == null) {
try {
@@ -88,63 +93,63 @@ private void getBakedModels() {
}

@Override
public void render(TileManaBattery te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
World world = te.getWorld();
public void render(float partialTicks, int destroyStage, float alpha) {
super.render(partialTicks, destroyStage, alpha);

World world = tile.getWorld();

GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
getBakedModels();

bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureManager texturemanager = Minecraft.getMinecraft().renderEngine;

if (texturemanager != null) {
texturemanager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}

if (Minecraft.isAmbientOcclusionEnabled())
GlStateManager.shadeModel(GL11.GL_SMOOTH);
else GlStateManager.shadeModel(GL11.GL_FLAT);

GlStateManager.translate(x, y + 0.5, z);
GlStateManager.translate(0, 0.5, 0);
GlStateManager.disableRescaleNormal();

GlStateManager.translate(0, Math.sin((te.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks()) / 40) / 8, 0);
GlStateManager.translate(0, Math.sin((tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks()) / 40) / 8, 0);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelCrystal, 1.0F, 1, 1, 1);

GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(te.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, 1, 0);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, 1, 0);
GlStateManager.translate(-0.5, 0, -0.5);

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelRing, 1.0F, 1, 1, 1);

GlStateManager.translate(0.5, 0, 0.5);
GlStateManager.rotate(te.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.rotate(te.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.rotate(tile.getWorld().getTotalWorldTime() + ClientTickHandler.getPartialTicks(), 0, -1, 0);
GlStateManager.translate(-0.5, 0, -0.5);

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(modelRingOuter, 1.0F, 1, 1, 1);

GlStateManager.disableBlend();
GlStateManager.popMatrix();

if (te.revealStructure && te.getBlockType() instanceof IStructure && !((IStructure) te.getBlockType()).isStructureComplete(te.getWorld(), te.getPos())) {
if (tile.revealStructure && tile.getBlockType() instanceof IStructure && !((IStructure) tile.getBlockType()).isStructureComplete(tile.getWorld(), tile.getPos())) {

IStructure structure = ((IStructure) te.getBlockType());
IStructure structure = ((IStructure) tile.getBlockType());

GlStateManager.pushMatrix();
GlStateManager.enableAlpha();
GlStateManager.enableLighting();
GlStateManager.enableBlend();
GlStateManager.enableCull();
GlStateManager.disableDepth();
GlStateManager.enableRescaleNormal();
GlStateManager.color(1, 1, 1);
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(1f, -0.05f);

GlStateManager.translate(x, y, z);
GlStateManager.translate(-structure.offsetToCenter().getX(), -structure.offsetToCenter().getY(), -structure.offsetToCenter().getZ());
Minecraft mc = Minecraft.getMinecraft();
Tessellator tes = Tessellator.getInstance();
BufferBuilder buffer = tes.getBuffer();

CachedStructure cachedStructure = ((IStructure) te.getBlockType()).getStructure();

mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

for (BlockRenderLayer layer : cachedStructure.blocks.keySet()) {
@@ -153,25 +158,25 @@ public void render(TileManaBattery te, double x, double y, double z, float parti

for (int i = 0; i < buffer.getVertexCount(); i++) {
int idx = buffer.getColorIndex(i + 1);
buffer.putColorRGBA(idx, 255, 255, 255, 150);
buffer.putColorRGBA(idx, 255, 255, 255, 200);
}
tes.draw();
}

GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.disableCull();
GlStateManager.disablePolygonOffset();
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.enableDepth();
GlStateManager.popMatrix();
return;
}

if (te.getBlockType() == ModBlocks.MANA_BATTERY) {

if (tile.getBlockType() == ModBlocks.MANA_BATTERY) {
if (RandUtil.nextInt(10) == 0) {
ParticleBuilder glitter = new ParticleBuilder(3);
glitter.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
glitter.setColorFunction(new InterpColorHSV(ColorUtils.changeColorAlpha(Color.CYAN, RandUtil.nextInt(50, 150)), ColorUtils.changeColorAlpha(Color.BLUE, RandUtil.nextInt(50, 150))));
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(te.getPos()).addVector(0.5, 0.5, 0.5)), RandUtil.nextInt(1, 3), 0, (aFloat, particleBuilder) -> {
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(tile.getPos()).addVector(0.5, 0.5, 0.5)), RandUtil.nextInt(1, 3), 0, (aFloat, particleBuilder) -> {
glitter.setAlphaFunction(new InterpFadeInOut(1f, 1f));
glitter.setMotion(new Vec3d(
RandUtil.nextDouble(-0.05, 0.05),
@@ -182,8 +187,8 @@ public void render(TileManaBattery te, double x, double y, double z, float parti
glitter.setScale((float) RandUtil.nextDouble(3));
});
}
} else if (te.getBlockType() == ModBlocks.CREATIVE_MANA_BATTERY) {
double angle = te.getWorld().getTotalWorldTime() / 10.0;
} else if (tile.getBlockType() == ModBlocks.CREATIVE_MANA_BATTERY) {
double angle = tile.getWorld().getTotalWorldTime() / 10.0;
double x1 = Math.cos((float) angle);
double y1 = Math.sin((float) angle);

@@ -193,17 +198,12 @@ public void render(TileManaBattery te, double x, double y, double z, float parti
builder.disableRandom();
builder.disableMotionCalculation();

ParticleSpawner.spawn(builder, getWorld(), new InterpCircle(new Vec3d(te.getPos()).addVector(0.5, 0.5, 0.5), new Vec3d(x1, x1, y1), 1.5f), 20, 0, (aFloat, particleBuilder) -> {
ParticleSpawner.spawn(builder, tile.getWorld(), new InterpCircle(new Vec3d(tile.getPos()).addVector(0.5, 0.5, 0.5), new Vec3d(x1, x1, y1), 1.5f), 20, 0, (aFloat, particleBuilder) -> {
particleBuilder.setScale(0.5f);
particleBuilder.setColor(new Color(0xd600d2));
particleBuilder.setAlphaFunction(new InterpFadeInOut(1, 1));
particleBuilder.setLifetime(RandUtil.nextInt(5, 10));
});
}
}

@Override
public boolean isGlobalRenderer(TileManaBattery te) {
return true;
}
}
@@ -3,7 +3,6 @@
import com.teamwizardry.librarianlib.features.base.block.tile.BlockModContainer;
import com.teamwizardry.wizardry.api.block.CachedStructure;
import com.teamwizardry.wizardry.api.block.IStructure;
import com.teamwizardry.wizardry.client.render.block.TileManaBatteryRenderer;
import com.teamwizardry.wizardry.common.tile.TileManaBattery;
import com.teamwizardry.wizardry.init.ModStructures;
import net.minecraft.block.SoundType;
@@ -18,9 +17,6 @@
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -32,11 +28,6 @@ public BlockCreativeManaBattery() {
setSoundType(SoundType.GLASS);
}

@SideOnly(Side.CLIENT)
public void initModel() {
ClientRegistry.bindTileEntitySpecialRenderer(TileManaBattery.class, new TileManaBatteryRenderer());
}

@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState iBlockState) {
@@ -3,7 +3,6 @@
import com.teamwizardry.librarianlib.features.base.block.tile.BlockModContainer;
import com.teamwizardry.wizardry.api.block.CachedStructure;
import com.teamwizardry.wizardry.api.block.IStructure;
import com.teamwizardry.wizardry.client.render.block.TileManaBatteryRenderer;
import com.teamwizardry.wizardry.common.tile.TileManaBattery;
import com.teamwizardry.wizardry.init.ModStructures;
import net.minecraft.block.SoundType;
@@ -18,9 +17,6 @@
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -32,11 +28,6 @@ public BlockManaBattery() {
setSoundType(SoundType.GLASS);
}

@SideOnly(Side.CLIENT)
public void initModel() {
ClientRegistry.bindTileEntitySpecialRenderer(TileManaBattery.class, new TileManaBatteryRenderer());
}

@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState iBlockState) {
@@ -45,13 +36,12 @@ public TileEntity createTileEntity(World world, IBlockState iBlockState) {

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile == null || !(tile instanceof TileManaBattery)) return false;
else {
((TileManaBattery) tile).revealStructure = !((TileManaBattery) tile).revealStructure;
tile.markDirty();
return true;
}
TileManaBattery tile = (TileManaBattery) worldIn.getTileEntity(pos);
if (tile == null) return false;

tile.revealStructure = !tile.revealStructure;
tile.markDirty();
return true;
}

@Override
@@ -38,7 +38,7 @@ public ItemNacrePearl() {
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
return new WizardryCapabilityProvider(new CustomWizardryCapability(1000, 1000, 0, 0));
return new WizardryCapabilityProvider(new CustomWizardryCapability(300, 300, 0, 0));
}

@Override
@@ -61,6 +61,7 @@ public class TileCraftingPlate extends TileManaInteracter {
@Save
public boolean revealStructure = false;
public ClusterObject[] renders;
public Vec3d[] positions;
public Random random = new Random(getPos().toLong());

public static final HashSet<BlockPos> poses = new HashSet<>();
@@ -76,25 +77,11 @@ public TileCraftingPlate() {
super(500, 500);
realInventory.setSides(EnumFacing.values());
renders = new ClusterObject[realInventory.getHandler().getSlots()];
positions = new Vec3d[realInventory.getHandler().getSlots()];
}

@Override
public void readCustomNBT(NBTTagCompound compound) {
TileCraftingPlate plate = this;
ClientRunnable.run(new ClientRunnable() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
for (int i = 0; i < renders.length; i++) {
renders[i] = null;
}
for (int i = 0; i < realInventory.getHandler().getSlots(); i++) {
ItemStack stack = realInventory.getHandler().getStackInSlot(i);
if (stack.isEmpty()) continue;
renders[i] = new ClusterObject(plate, stack, getWorld(), null);
}
}
});
}

@Override
@@ -143,13 +130,12 @@ public void update() {
realInventory.getHandler().setStackInSlot(i, stack);

int finalI = i;
TileCraftingPlate plate = this;
ClientRunnable.run(new ClientRunnable() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
// if(renderHandler != null)
// ((TileCraftingPlateRenderer)renderHandler).spawnItem(finalI);
if (renderHandler != null)
((TileCraftingPlateRenderer) renderHandler).addAnimation(finalI, true);
}
});
break;
@@ -193,8 +179,8 @@ public void runIfClient() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
for (int i = 0; i < renders.length; i++) {
renders[i] = null;
for (int i = 0; i < positions.length; i++) {
positions[i] = Vec3d.ZERO;
}
}
});
@@ -2,8 +2,10 @@

import com.teamwizardry.librarianlib.features.autoregister.TileRegister;
import com.teamwizardry.librarianlib.features.saving.Save;
import com.teamwizardry.librarianlib.features.tesr.TileRenderer;
import com.teamwizardry.wizardry.api.block.TileManaInteracter;
import com.teamwizardry.wizardry.api.capability.CapManager;
import com.teamwizardry.wizardry.client.render.block.TileManaBatteryRenderer;
import com.teamwizardry.wizardry.common.block.BlockManaBattery;
import com.teamwizardry.wizardry.init.ModBlocks;
import net.minecraft.tileentity.TileEntity;
@@ -16,6 +18,7 @@
import java.util.HashSet;

@TileRegister("mana_battery")
@TileRenderer(TileManaBatteryRenderer.class)
public class TileManaBattery extends TileManaInteracter {

public static final HashSet<BlockPos> poses = new HashSet<>();
@@ -107,8 +107,6 @@ public static void init() {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void registerModels(ModelRegistryEvent event) {
MANA_BATTERY.initModel();
//CREATIVE_MANA_BATTERY.initModel();
PEARL_HOLDER.initModel();
JAR.initModel();
MANA_MAGNET.initModel();