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 Jan 17, 2017
1 parent 15b0f49 commit 2076f20
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ 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()))));
components.add(new StaticRenderer()).onRender(model ->
model.addChild(new CustomModel(self -> RenderBlocks.getInstance().renderBlockByRenderType(mcBlock, x(), y(), z()))));
//TODO: Set selection bounds
}

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 @@ -93,6 +97,9 @@ 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 -> Minecraft.getMinecraft().getBlockRendererDispatcher()
.renderBlock(blockState(), new BlockPos(x(), y(), z()), getMcBlockAccess(), Tessellator.getInstance().getWorldRenderer()))));
//TODO: Set selection bounds
}

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 @@ -37,6 +38,13 @@
* @author Calclavia
*/
public class BWClientRenderManager extends BWRenderManager {

//TODO: Would this break server?
@SideOnly(Side.CLIENT)
public static RenderItem renderItem() {
return Minecraft.getMinecraft().getRenderItem();
}

@SideOnly(Side.CLIENT)
@Override
public Vector2D getDimension(Texture 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 @@ -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 2076f20

Please sign in to comment.