From ba4c2d6b207d6e0572e48a75ad610f3b6220f31a Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 21 Apr 2017 13:56:42 +0200 Subject: [PATCH 1/4] Fix NPE when teleporting inside block --- .../v17/wrapper/block/forward/FWBlock.java | 24 +++---------------- .../v17/wrapper/item/ItemWrapperMethods.java | 8 +++---- .../mc/forge/v17/wrapper/render/BWModel.java | 6 +++-- .../mc/forge/v18/wrapper/render/BWModel.java | 6 +++-- .../v18/wrapper/render/FWEmptyModel.java | 5 ---- 5 files changed, 14 insertions(+), 35 deletions(-) diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java index 391cfd7a6..aced065ed 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java @@ -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; @@ -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 opRenderer = blockInstance.components.getOp(StaticBlockRenderer.class); - if (opRenderer.isPresent()) { - Optional 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 opRenderer = block.components.getOp(StaticBlockRenderer.class); - if (opRenderer.isPresent()) { - Optional 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 diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java index 9b9d80f55..03f6569f3 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java @@ -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; @@ -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 diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/render/BWModel.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/render/BWModel.java index a8cd9c070..73271d8e0 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/render/BWModel.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/render/BWModel.java @@ -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() { diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/BWModel.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/BWModel.java index d8abf65f4..84c7fe8fc 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/BWModel.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/BWModel.java @@ -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() { diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/FWEmptyModel.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/FWEmptyModel.java index 2ba60ef6e..7676d7719 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/FWEmptyModel.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/FWEmptyModel.java @@ -53,9 +53,4 @@ public ISmartItemModel handleItemState(ItemStack stack) { public List getGeneralQuads() { return Collections.emptyList(); } - - @Override - public TextureAtlasSprite getTexture() { - return null; - } } From 70f0dab8f06587358d93af159ac800bef114a1ad Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 21 Apr 2017 21:18:06 +0200 Subject: [PATCH 2/4] Don't crash on missing model, display broken texture cube instead --- .../mc/forge/v17/render/RenderUtility.java | 3 +- .../mc/forge/v18/render/RenderUtility.java | 6 +--- .../nova/core/render/model/MeshModel.java | 9 +++-- .../render/model/TechneModelProvider.java | 6 +++- .../model/WavefrontObjectModelProvider.java | 5 ++- src/main/java/nova/core/util/ModelUtil.java | 34 +++++++++++++++++++ 6 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/main/java/nova/core/util/ModelUtil.java diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/render/RenderUtility.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/render/RenderUtility.java index 26085bc67..4cb873212 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/render/RenderUtility.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/render/RenderUtility.java @@ -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; @@ -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); } }); } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java index a878336c3..f96caac91 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java @@ -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; @@ -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; @@ -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); } }); } diff --git a/src/main/java/nova/core/render/model/MeshModel.java b/src/main/java/nova/core/render/model/MeshModel.java index 88613a39d..f7a816f35 100644 --- a/src/main/java/nova/core/render/model/MeshModel.java +++ b/src/main/java/nova/core/render/model/MeshModel.java @@ -56,8 +56,9 @@ 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; } /** @@ -65,12 +66,13 @@ public void bind(Texture texture) { * * @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; } /** @@ -78,8 +80,9 @@ public void bindAll(Texture texture) { * * @param Face - The finished masterpiece. */ - public void drawFace(Face Face) { + public MeshModel drawFace(Face Face) { faces.add(Face); + return this; } @Override diff --git a/src/main/java/nova/core/render/model/TechneModelProvider.java b/src/main/java/nova/core/render/model/TechneModelProvider.java index 053335cbb..93d586534 100755 --- a/src/main/java/nova/core/render/model/TechneModelProvider.java +++ b/src/main/java/nova/core/render/model/TechneModelProvider.java @@ -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; @@ -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; @@ -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 @@ -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 diff --git a/src/main/java/nova/core/render/model/WavefrontObjectModelProvider.java b/src/main/java/nova/core/render/model/WavefrontObjectModelProvider.java index 899486d27..e3feed715 100755 --- a/src/main/java/nova/core/render/model/WavefrontObjectModelProvider.java +++ b/src/main/java/nova/core/render/model/WavefrontObjectModelProvider.java @@ -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; @@ -58,6 +59,7 @@ public class WavefrontObjectModelProvider extends ModelProvider { private ArrayList vertices = new ArrayList<>(); private ArrayList textureCoordinates = new ArrayList<>(); private ArrayList vertexNormals = new ArrayList<>(); + private boolean loaded = false; /** * Creates new ModelProvider @@ -122,6 +124,7 @@ public void load(InputStream stream) { } finally { this.cleanUp(); } + this.loaded = true; } private void cleanUp() { @@ -132,7 +135,7 @@ private void cleanUp() { @Override public MeshModel getModel() { - return model.clone(); + return this.loaded ? model.clone() : ModelUtil.getMissingModel(); } @Override diff --git a/src/main/java/nova/core/util/ModelUtil.java b/src/main/java/nova/core/util/ModelUtil.java new file mode 100644 index 000000000..ba33f4e20 --- /dev/null +++ b/src/main/java/nova/core/util/ModelUtil.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NOVA. If not, see . + */ +package nova.core.util; + +import nova.core.render.model.MeshModel; +import nova.core.render.pipeline.BlockRenderPipeline; +import nova.core.render.texture.Texture; + +/** + * @author ExE Boss + */ +public class ModelUtil { + + public static MeshModel getMissingModel() { + return BlockRenderPipeline.drawCube(new MeshModel()).bind(new Texture("nova", "null")); + } +} From 18bdb5081407affc720cc850224492aa711fda93 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 21 Apr 2017 21:24:38 +0200 Subject: [PATCH 3/4] Fix broken Direction.NORTH/SOUTH.rotation --- src/main/java/nova/core/util/Direction.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/nova/core/util/Direction.java b/src/main/java/nova/core/util/Direction.java index a8df6b1ca..0f9d70b20 100755 --- a/src/main/java/nova/core/util/Direction.java +++ b/src/main/java/nova/core/util/Direction.java @@ -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)); } } From 0bc9c6a5d1db5ff5e1a955db5c72e412cd1f84ac Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Wed, 31 May 2017 20:08:16 +0200 Subject: [PATCH 4/4] Begin 1.7 backward rendering implementation --- .../v17/wrapper/block/backward/BWBlock.java | 13 ++++++-- .../v17/wrapper/entity/backward/BWEntity.java | 6 ++++ .../mc/forge/v17/wrapper/item/BWItem.java | 33 +++++++++---------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java index c205b6ed2..56d5c9eb3 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java @@ -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; @@ -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; @@ -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); } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java index 9af246d94..47dc209d5 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java @@ -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; @@ -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)); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java index 76cc54d07..9e7b16f38 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java @@ -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() {