Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into mc1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Jan 17, 2017
2 parents 3212641 + 15b0f49 commit 1adb7d6
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
import nova.core.block.component.LightEmitter;
import nova.core.component.Updater;
import nova.core.component.misc.Collider;
import nova.core.component.renderer.ItemRenderer;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.component.renderer.Renderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.retention.Storable;
import nova.core.util.Direction;
Expand Down Expand Up @@ -376,14 +377,21 @@ public int getRenderBlockPass() {
@SideOnly(Side.CLIENT)
@Override
public void renderInventoryBlock(net.minecraft.block.Block block, int metadata, int modelId, RenderBlocks renderer) {
Optional<ItemRenderer> opRenderer = this.dummy.components.getOp(ItemRenderer.class);
if (opRenderer.isPresent()) {
if (this.dummy.components.has(Renderer.class)) {
GL11.glPushAttrib(GL_TEXTURE_BIT);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glPushMatrix();
Tessellator.instance.startDrawingQuads();
BWModel model = new BWModel();
opRenderer.get().onRender.accept(model);

if (this.dummy.components.has(StaticRenderer.class)) {
StaticRenderer staticRenderer = this.dummy.components.get(StaticRenderer.class);
staticRenderer.onRender.accept(model);
} else if (this.dummy.components.has(DynamicRenderer.class)) {
DynamicRenderer dynamicRenderer = this.dummy.components.get(DynamicRenderer.class);
dynamicRenderer.onRender.accept(model);
}

model.render();
Tessellator.instance.draw();
GL11.glPopMatrix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import nova.core.component.renderer.ItemRenderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.item.Item;
import nova.core.render.model.CustomModel;
import nova.core.retention.Storable;
Expand Down Expand Up @@ -55,7 +55,7 @@ public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {
this.meta = meta;
this.tag = tag;

components.add(new ItemRenderer())
components.add(new StaticRenderer())
.onRender(model -> {
model.addChild(new CustomModel(self -> {
Tessellator.instance.draw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import nova.core.component.renderer.ItemRenderer;
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;
Expand Down Expand Up @@ -67,37 +69,39 @@ default ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlaye
}

default IIcon getIconFromDamage(int p_77617_1_) {
//TODO: Can we prevent building new items?
Item item = getItemFactory().build();
if (item.components.has(ItemRenderer.class) && item.components.get(ItemRenderer.class).texture.isPresent()) {
return RenderUtility.instance.getIcon(item.components.get(ItemRenderer.class).texture.get());
}
return null;
}

default IIcon getIcon(ItemStack itemStack, int pass) {
Item item = Game.natives().toNova(itemStack);
if (item.components.has(ItemRenderer.class) && item.components.get(ItemRenderer.class).texture.isPresent()) {
return RenderUtility.instance.getIcon(item.components.get(ItemRenderer.class).texture.get());
}
return null;
}

@Override
default boolean handleRenderType(ItemStack item, IItemRenderer.ItemRenderType type) {
return item.getItem() == this && getIcon(item, 0) == null;
}

@Override
default boolean shouldUseRenderHelper(IItemRenderer.ItemRenderType type, ItemStack item, IItemRenderer.ItemRendererHelper helper) {
return true;
}

@Override
default void renderItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data) {
Item item = Game.natives().toNova(itemStack);
if (item.components.has(ItemRenderer.class)) {
BWModel model = new BWModel();
item.components.get(ItemRenderer.class).onRender.accept(model);
model.render();
BWModel model = new BWModel();

if (item.components.has(StaticRenderer.class)) {
StaticRenderer staticRenderer = item.components.get(StaticRenderer.class);
staticRenderer.onRender.accept(model);
} else if (item.components.has(DynamicRenderer.class)) {
DynamicRenderer dynamicRenderer = item.components.get(DynamicRenderer.class);
dynamicRenderer.onRender.accept(model);
}

// For some reason calling model.faces.size() returns 0.
// Yet staticRenderer.onRender.accept(model) still gets executed.
model.render();
}

default int getColorFromItemStack(ItemStack itemStack, int p_82790_2_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,28 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockPart;
import net.minecraft.client.renderer.block.model.BlockPartFace;
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.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.client.resources.model.SimpleBakedModel;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.TRSRTransformation;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import nova.core.component.renderer.ItemRenderer;
import nova.core.component.renderer.Renderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.render.texture.BlockTexture;
import nova.core.render.texture.ItemTexture;
import nova.core.render.texture.Texture;
import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock;
import nova.core.wrapper.mc.forge.v18.wrapper.item.FWItem;
import nova.core.wrapper.mc.forge.v18.wrapper.item.FWItemBlock;
import nova.core.wrapper.mc.forge.v18.wrapper.render.FWEmptyModel;
import nova.core.wrapper.mc.forge.v18.wrapper.render.FWSmartBlockModel;
import nova.core.wrapper.mc.forge.v18.wrapper.render.FWSmartItemModel;
Expand All @@ -60,7 +53,6 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Optional;

import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_FLAT;
Expand Down Expand Up @@ -214,35 +206,8 @@ public void onModelBakeEvent(ModelBakeEvent event) {

nova.core.item.Item dummy = item.getItemFactory().build();

if (dummy.components.has(ItemRenderer.class)) {
Optional<Texture> texture = dummy.components.get(ItemRenderer.class).texture;

if (texture.isPresent()) {
MODEL_GENERATED.textures.put("layer0", texture.get().getResource());
MODEL_GENERATED.name = itemLocation.toString();

// This is the key part, it takes the texture and makes the "3d" one wide voxel model
ModelBlock itemModel = ITEM_MODEL_GENERATOR.makeItemModel(new FakeTextureMap(dummy), MODEL_GENERATED);

// This was taken from ModelBakery and simplified for the generation of our Items
SimpleBakedModel.Builder builder = new SimpleBakedModel.Builder(itemModel).setTexture(getTexture(texture.get()));
for (BlockPart blockpart : (Iterable<BlockPart>) itemModel.getElements()) {
for (EnumFacing enumfacing : (Iterable<EnumFacing>) blockpart.mapFaces.keySet()) {
BlockPartFace blockpartface = (BlockPartFace) blockpart.mapFaces.get(enumfacing);
BakedQuad bakedQuad = FACE_BAKERY.makeBakedQuad(blockpart.positionFrom, blockpart.positionTo, blockpartface, getTexture(texture.get()), enumfacing, ModelRotation.X0_Y0, blockpart.partRotation, false, blockpart.shade);

if (blockpartface.cullFace == null || !TRSRTransformation.isInteger(ModelRotation.X0_Y0.getMatrix())) {
builder.addGeneralQuad(bakedQuad);
} else {

builder.addFaceQuad(ModelRotation.X0_Y0.rotate(blockpartface.cullFace), bakedQuad);
}
}
}
event.modelRegistry.putObject(itemLocation, builder.makeBakedModel());
} else {
event.modelRegistry.putObject(itemLocation, new FWSmartItemModel(dummy));
}
if (dummy.components.has(Renderer.class)) {
event.modelRegistry.putObject(itemLocation, new FWSmartItemModel(dummy));
}
}
}
Expand All @@ -261,24 +226,4 @@ public void preInit() {
}
});
}

private class FakeTextureMap extends TextureMap {
private final nova.core.item.Item item;

public FakeTextureMap(nova.core.item.Item item) {
super("");
this.item = item;
}

@Override
public TextureAtlasSprite getAtlasSprite(String iconName) {
if (item.components.has(ItemRenderer.class)) {
ItemRenderer itemRenderer = item.components.get(ItemRenderer.class);
if (itemRenderer.texture.isPresent()) {
return RenderUtility.instance.getTexture(itemRenderer.texture.get());
}
}
return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.client.model.ISmartItemModel;
import nova.core.block.Block;
import nova.core.component.renderer.ItemRenderer;
import nova.core.component.renderer.DynamicRenderer;
import nova.core.component.renderer.Renderer;
import nova.core.component.renderer.StaticRenderer;
import nova.core.item.ItemBlock;
import nova.core.wrapper.mc.forge.v18.render.RenderUtility;
import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock;
import nova.internal.core.Game;

import javax.vecmath.Vector3f;

import java.util.List;

/**
Expand All @@ -50,10 +50,10 @@ public class FWSmartBlockModel extends FWSmartModel implements ISmartBlockModel,
private final Block block;
private final boolean isItem;

public FWSmartBlockModel(Block block, boolean isDummy) {
public FWSmartBlockModel(Block block, boolean isItem) {
super();
this.block = block;
this.isItem = isDummy;
this.isItem = isItem;
// Change the default transforms to the default full Block transforms
this.itemCameraTransforms = new ItemCameraTransforms(
new ItemTransformVec3f(new Vector3f(10, -45, 170), new Vector3f(0, 0.09375f, -0.171875f), new Vector3f(0.375f, 0.375f, 0.375f)), // Third Person
Expand All @@ -78,10 +78,8 @@ public IBakedModel handleBlockState(IBlockState state) {
@Override
public IBakedModel handleItemState(ItemStack stack) {
ItemBlock item = Game.natives().toNova(stack);
ItemRenderer renderer =
item.components.has(ItemRenderer.class) ? item.components.get(ItemRenderer.class) : block.components.has(ItemRenderer.class) ? block.components.get(ItemRenderer.class) : null;

if (renderer != null) {
if (item.components.has(Renderer.class) || block.components.has(Renderer.class)) {
return new FWSmartBlockModel(block, true);
}

Expand All @@ -90,37 +88,22 @@ public IBakedModel handleItemState(ItemStack stack) {

@Override
public List<BakedQuad> getGeneralQuads() {
BWModel blockModel = new BWModel();
blockModel.matrix.translate(0.5, 0.5, 0.5);
BWModel model = new BWModel();
model.matrix.translate(0.5, 0.5, 0.5);

if (isItem) {
ItemRenderer renderer = block.components.get(ItemRenderer.class);
renderer.onRender.accept(blockModel);
} else {
StaticRenderer renderer = block.components.get(StaticRenderer.class);
renderer.onRender.accept(blockModel);
}

return modelToQuads(blockModel);
}

@Override
public TextureAtlasSprite getTexture() {
/*
if (block.components.has(StaticRenderer.class)) {
Optional<Texture> apply = block.components.get(StaticRenderer.class).texture.apply(Direction.UNKNOWN);
if (apply.isPresent()) {
return RenderUtility.instance.getTexture(apply.components.get());
}
}*/

if (block.components.has(ItemRenderer.class)) {
ItemRenderer itemRenderer = block.components.get(ItemRenderer.class);
if (itemRenderer.texture.isPresent()) {
return RenderUtility.instance.getTexture(itemRenderer.texture.get());
if (block.components.has(StaticRenderer.class)) {
StaticRenderer staticRenderer = block.components.get(StaticRenderer.class);
staticRenderer.onRender.accept(model);
} else if (block.components.has(DynamicRenderer.class)) {
DynamicRenderer dynamicRenderer = block.components.get(DynamicRenderer.class);
dynamicRenderer.onRender.accept(model);
}
} else {
StaticRenderer staticRenderer = block.components.get(StaticRenderer.class);
staticRenderer.onRender.accept(model);
}

return null;
return modelToQuads(model);
}
}
Loading

0 comments on commit 1adb7d6

Please sign in to comment.