Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 1.7.10 BW rendering #302

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.ModelFormatException;
import nova.core.render.texture.Texture;
import nova.core.wrapper.mc.forge.v17.launcher.ForgeLoadable;
import nova.core.wrapper.mc.forge.v17.wrapper.assets.AssetConverter;
Expand Down Expand Up @@ -177,7 +176,7 @@ public void preInit(FMLPreInitializationEvent event) {
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
m.load(res.getInputStream());
} catch (IOException e) {
throw new ModelFormatException("IO Exception reading model format", e);
Game.logger().warn("IO Exception reading model format", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package nova.core.wrapper.mc.forge.v17.wrapper.block.backward;

import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -32,6 +33,7 @@
import nova.core.block.component.BlockProperty;
import nova.core.block.component.LightEmitter;
import nova.core.component.misc.Collider;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.component.transform.BlockTransform;
import nova.core.item.ItemFactory;
Expand Down Expand Up @@ -98,8 +100,15 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) {
.collect(Collectors.toSet());
});
//TODO: Set selection bounds
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 -> {
// TODO: Test and fix backward Block rendering
Tessellator.instance.draw();
RenderBlocks.getInstance().renderStandardBlock(mcBlock, x(), y(), z());
Tessellator.instance.startDrawingQuads();
})));
components.add(new DynamicRenderer()).onRender(model -> model.addChild(new CustomModel(self -> {
// TODO: Implement backward TileEntity rendering
})));
WrapperEvent.BWBlockCreate event = new WrapperEvent.BWBlockCreate(world, pos, this, mcBlock);
Game.events().publish(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.IIconRegister;
Expand Down Expand Up @@ -218,31 +219,12 @@ public TileEntity createTileEntity(World world, int metadata) {

@Override
public IIcon getIcon(IBlockAccess access, int x, int y, int z, int side) {
//TODO: Fill in something
/*
Block blockInstance = getBlockInstance(access, new Vector3D(x, y, z));
Optional<StaticBlockRenderer> opRenderer = blockInstance.components.getOp(StaticBlockRenderer.class);
if (opRenderer.isPresent()) {
Optional<Texture> texture = opRenderer.components.get().texture.apply(Direction.values()[side]);
if (texture.isPresent()) {
return RenderUtility.instance.getIcon(texture.components.get());
}
}*/
return null;
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("missingno");
}

@Override
public IIcon getIcon(int side, int meta) {
//TODO: Fill in something
/*
Optional<StaticBlockRenderer> opRenderer = block.components.getOp(StaticBlockRenderer.class);
if (opRenderer.isPresent()) {
Optional<Texture> texture = opRenderer.components.get().texture.apply(Direction.values()[side]);
if (texture.isPresent()) {
return RenderUtility.instance.getIcon(texture.components.get());
}
}*/
return null;
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("missingno");
}

@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,10 @@ public void damage(double amount, DamageType type) {
}
});

components.add(new DynamicRenderer()).onRender(model -> model.addChild(new CustomModel(self -> {
// TODO: Implement backward Entity rendering
})));

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 @@ -55,24 +55,21 @@ public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {
this.meta = meta;
this.tag = 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);
RenderItem.getInstance().doRender(fakeEntity, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
Tessellator.instance.startDrawingQuads();
}));
}
);
components.add(new StaticRenderer()).onRender(model -> model.addChild(new CustomModel(self -> {
// TODO: Test and fix backward Item rendering
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);
RenderItem.getInstance().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 @@ -20,19 +20,17 @@

package nova.core.wrapper.mc.forge.v17.wrapper.item;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.component.renderer.Renderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.item.Item;
import nova.core.item.ItemFactory;
import nova.core.util.Direction;
import nova.core.wrapper.mc.forge.v17.render.RenderUtility;
import nova.core.wrapper.mc.forge.v17.wrapper.entity.backward.BWEntity;
import nova.core.wrapper.mc.forge.v17.wrapper.render.BWModel;
import nova.internal.core.Game;
Expand Down Expand Up @@ -74,11 +72,11 @@ default ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlaye
}

default IIcon getIconFromDamage(int p_77617_1_) {
return null;
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("missingno");
}

default IIcon getIcon(ItemStack itemStack, int pass) {
return null;
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("missingno");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public class BWModel extends MeshModel {

/**
* Completes this rendering for a block.
*
* @param access The world instance.
*/
public void render(IBlockAccess blockAccess) {
render(Optional.of(blockAccess), Optional.empty());
public void render(IBlockAccess access) {
render(Optional.of(access), Optional.empty());
}

public void render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.FaceBakery;
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.model.ModelResourceLocation;
Expand All @@ -38,7 +35,6 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import nova.core.component.renderer.Renderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.item.ItemFactory;
import nova.core.render.texture.Texture;
Expand Down Expand Up @@ -229,7 +225,7 @@ public void preInit(FMLPreInitializationEvent event) {
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
m.load(res.getInputStream());
} catch (IOException e) {
throw new RuntimeException("IO Exception reading model format", e);
Game.logger().warn("IO Exception reading model format", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public class BWModel extends MeshModel {

/**
* Completes this rendering for a block.
*
* @param access The world instance.
*/
public void render(IBlockAccess blockAccess) {
render(Optional.of(blockAccess), Optional.empty());
public void render(IBlockAccess access) {
render(Optional.of(access), Optional.empty());
}

public void render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,4 @@ public ISmartItemModel handleItemState(ItemStack stack) {
public List<BakedQuad> getGeneralQuads() {
return Collections.emptyList();
}

@Override
public TextureAtlasSprite getTexture() {
return null;
}
}
9 changes: 6 additions & 3 deletions src/main/java/nova/core/render/model/MeshModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,33 @@ public MeshModel(String name) {
*
* @param texture The texture
*/
public void bind(Texture texture) {
public MeshModel bind(Texture texture) {
faces.forEach(f -> f.texture = Optional.of(texture));
return this;
}

/**
* Binds the texture to the model, and all its children.
*
* @param texture to be used to as for this model and sub-models.
*/
public void bindAll(Texture texture) {
public MeshModel bindAll(Texture texture) {
bind(texture);
stream()
.filter(m -> m instanceof MeshModel)
.map(m -> (MeshModel) m)
.forEach(m -> m.bindAll(texture));
return this;
}

/**
* Finish drawing the {@link Face} by adding it into the list of faces.
*
* @param Face - The finished masterpiece.
*/
public void drawFace(Face Face) {
public MeshModel drawFace(Face Face) {
faces.add(Face);
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import nova.core.render.RenderException;
import nova.core.render.pipeline.BlockRenderPipeline;
import nova.core.render.pipeline.CubeTextureCoordinates;
import nova.core.util.ModelUtil;
import nova.core.util.math.MatrixStack;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;
Expand All @@ -32,6 +33,7 @@

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -55,6 +57,7 @@ public class TechneModelProvider extends ModelProvider {

//A map of all models generated with their names
private final MeshModel model = new MeshModel();
private boolean loaded = false;

/**
* Creates new ModelProvider
Expand Down Expand Up @@ -249,11 +252,12 @@ public void load(InputStream stream) {
} catch (Exception e) {
e.printStackTrace();
}
this.loaded = true;
}

@Override
public MeshModel getModel() {
return model.clone();
return this.loaded ? model.clone() : ModelUtil.getMissingModel();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package nova.core.render.model;

import nova.core.render.RenderException;
import nova.core.util.ModelUtil;
import nova.core.util.math.Vector3DUtil;
import nova.internal.core.Game;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class WavefrontObjectModelProvider extends ModelProvider {
private ArrayList<Vector3D> vertices = new ArrayList<>();
private ArrayList<Vector2D> textureCoordinates = new ArrayList<>();
private ArrayList<Vector3D> vertexNormals = new ArrayList<>();
private boolean loaded = false;

/**
* Creates new ModelProvider
Expand Down Expand Up @@ -122,6 +124,7 @@ public void load(InputStream stream) {
} finally {
this.cleanUp();
}
this.loaded = true;
}

private void cleanUp() {
Expand All @@ -132,7 +135,7 @@ private void cleanUp() {

@Override
public MeshModel getModel() {
return model.clone();
return this.loaded ? model.clone() : ModelUtil.getMissingModel();
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/nova/core/util/Direction.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public enum Direction {

if (vector.equals(Vector3D.ZERO)) {
this.rotation = Rotation.IDENTITY;
} else {
} else if (z == 0) {
this.rotation = new Rotation(Vector3DUtil.FORWARD, vector);
} else {
// For some odd reason, the rotation must be reversed when dealing with NORTH/SOUTH
this.rotation = new Rotation(Vector3DUtil.FORWARD, vector.scalarMultiply(-1));
}
}

Expand Down
Loading