Skip to content

Commit

Permalink
Implement BW Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Feb 12, 2017
1 parent aaccb91 commit 96b81ae
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) {
.map(cuboid -> cuboid.subtract(pos))
.collect(Collectors.toSet());
});
components.add(new StaticRenderer())
.onRender(model -> model.addChild(new CustomModel(self -> RenderBlocks.getInstance().renderStandardBlock(mcBlock, x(), y(), z()))));
//TODO: Set selection bounds
components.add(new StaticRenderer()).onRender(model ->
model.addChild(new CustomModel(self -> RenderBlocks.getInstance().renderBlockByRenderType(mcBlock, x(), y(), z()))));
WrapperEvent.BWBlockCreate event = new WrapperEvent.BWBlockCreate(world, pos, this, mcBlock);
Game.events().publish(event);
//TODO: Set selection bounds
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import net.minecraft.util.DamageSource;
import nova.core.component.inventory.InventoryPlayer;
import nova.core.component.misc.Damageable;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.entity.Entity;
import nova.core.entity.component.Living;
import nova.core.entity.component.Player;
import nova.core.render.model.CustomModel;
import nova.core.wrapper.mc.forge.v17.util.WrapperEvent;
import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.MCEntityTransform;
import nova.core.wrapper.mc.forge.v17.wrapper.inventory.BWInventory;
Expand Down Expand Up @@ -61,6 +63,12 @@ public void damage(double amount, DamageType type) {
}
});

components.add(new DynamicRenderer()).onRender(model -> {
model.addChild(new CustomModel(self -> {
net.minecraft.client.renderer.entity.RenderManager.instance.renderEntityWithPosYaw(entity, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, 1);
}));
});

if (entity instanceof EntityLivingBase) {
if (entity instanceof EntityPlayer) {
MCPlayer player = components.add(new MCPlayer(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,21 @@ public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {

components.add(new StaticRenderer())
.onRender(model -> {
model.addChild(new CustomModel(self -> {
Tessellator.instance.draw();
GL11.glPushMatrix();
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(4 * 4);
double[] flatArray = Arrays.stream(self.matrix.getMatrix().getData())
.flatMapToDouble(Arrays::stream)
.toArray();
buffer.put(flatArray);
buffer.position(0);
GL11.glMultMatrix(buffer);
BWClientRenderManager.renderItem.doRender(fakeEntity, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
Tessellator.instance.startDrawingQuads();
}));
}
);
model.addChild(new CustomModel(self -> {
Tessellator.instance.draw();
GL11.glPushMatrix();
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(4 * 4);
double[] flatArray = Arrays.stream(self.matrix.getMatrix().getData())
.flatMapToDouble(Arrays::stream)
.toArray();
buffer.put(flatArray);
buffer.position(0);
GL11.glMultMatrix(buffer);
BWClientRenderManager.renderItem.doRender(fakeEntity, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
Tessellator.instance.startDrawingQuads();
}));
});
}

public net.minecraft.item.Item getItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import net.minecraft.block.BlockSnow;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -34,8 +36,10 @@
import nova.core.block.component.BlockProperty;
import nova.core.block.component.LightEmitter;
import nova.core.component.misc.Collider;
import nova.core.component.renderer.StaticRenderer;
import nova.core.component.transform.BlockTransform;
import nova.core.item.ItemFactory;
import nova.core.render.model.CustomModel;
import nova.core.retention.Data;
import nova.core.retention.Storable;
import nova.core.retention.Store;
Expand Down Expand Up @@ -95,9 +99,12 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) {
.map(cuboid -> cuboid.subtract(pos))
.collect(Collectors.toSet());
});
//TODO: Set selection bounds
components.add(new StaticRenderer()).onRender(model ->
model.addChild(new CustomModel(self -> Minecraft.getMinecraft().getBlockRendererDispatcher()
.renderBlock(blockState(), new BlockPos(x(), y(), z()), getMcBlockAccess(), Tessellator.getInstance().getWorldRenderer()))));
WrapperEvent.BWBlockCreate event = new WrapperEvent.BWBlockCreate(world, pos, this, mcBlock);
Game.events().publish(event);
//TODO: Set selection bounds
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@

package nova.core.wrapper.mc.forge.v18.wrapper.entity.backward;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import nova.core.component.inventory.InventoryPlayer;
import nova.core.component.misc.Damageable;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.entity.Entity;
import nova.core.entity.component.Living;
import nova.core.entity.component.Player;
import nova.core.render.model.CustomModel;
import nova.core.wrapper.mc.forge.v18.util.WrapperEvent;
import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.MCEntityTransform;
import nova.core.wrapper.mc.forge.v18.wrapper.inventory.BWInventory;
Expand Down Expand Up @@ -61,6 +64,12 @@ public void damage(double amount, DamageType type) {
}
});

components.add(new DynamicRenderer()).onRender(model -> {
model.addChild(new CustomModel(self -> {
Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entity, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, 1);
}));
});

if (entity instanceof EntityLivingBase) {
if (entity instanceof EntityPlayer) {
MCPlayer player = components.add(new MCPlayer(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import nova.core.component.renderer.StaticRenderer;
import nova.core.item.Item;
import nova.core.render.model.CustomModel;
import nova.core.retention.Storable;
import nova.core.wrapper.mc.forge.v18.wrapper.render.BWClientRenderManager;

/**
* @author Stan
Expand All @@ -42,6 +45,9 @@ public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {
this.item = item;
this.meta = meta;
this.tag = tag;

components.add(new StaticRenderer()).onRender(model ->
model.addChild(new CustomModel(self -> BWClientRenderManager.renderItem().renderItemModel(makeItemStack(count())))));
}

public net.minecraft.item.Item getItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package nova.core.wrapper.mc.forge.v18.wrapper.render;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -36,8 +37,13 @@
/**
* @author Calclavia
*/
@SideOnly(Side.CLIENT)
public class BWClientRenderManager extends BWRenderManager {
@SideOnly(Side.CLIENT)

public static RenderItem renderItem() {
return Minecraft.getMinecraft().getRenderItem();
}

@Override
public Vector2D getDimension(Texture texture) {
ResourceLocation loc = toResourceLocation(texture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.ResourceLocation;
import nova.core.render.model.CustomModel;
import nova.core.render.model.MeshModel;
import nova.core.render.texture.EntityTexture;
import nova.core.render.texture.Texture;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void render(Optional<RenderManager> entityRenderManager) {
worldRenderer.setBrightness(15 << 20 | 11 << 4);
}

worldRenderer.setNormal((int) face.normal.getX(), (int) face.normal.getY(), (int) face.normal.getZ());
worldRenderer.setNormal((float) face.normal.getX(), (float) face.normal.getY(), (float) face.normal.getZ());

if (face.texture.isPresent()) {
if (entityRenderManager.isPresent() && face.texture.get() instanceof EntityTexture) {
Expand Down Expand Up @@ -100,8 +101,10 @@ public void render(Optional<RenderManager> entityRenderManager) {
);
}
});
} else if (model instanceof CustomModel) {
CustomModel customModel = (CustomModel) model;
customModel.render.accept(customModel);
}
//TODO: Handle BW Rendering
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.util.ResourceLocation;
import nova.core.render.RenderManager;
import nova.core.render.texture.Texture;
import nova.internal.core.Game;
import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;

public class BWRenderManager extends RenderManager {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/nova/core/render/model/MeshModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void drawFace(Face Face) {
faces.add(Face);
}

@Override
public Set<Model> flatten(MatrixStack matrixStack) {
Set<Model> models = new HashSet<>();

Expand Down Expand Up @@ -110,7 +111,7 @@ public Set<Model> flatten(MatrixStack matrixStack) {
}

@Override
protected Model newModel(String name) {
protected MeshModel newModel(String name) {
return new MeshModel(name);
}

Expand Down

0 comments on commit 96b81ae

Please sign in to comment.