Skip to content

Commit

Permalink
Tweak lantern stuff, updating chain API
Browse files Browse the repository at this point in the history
  • Loading branch information
jaquadro committed Mar 7, 2015
1 parent db69e06 commit e1078ef
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 13 deletions.
Binary file modified resources/assets/gardenstuff/textures/blocks/lantern_glass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,11 @@ public TileEntityLargePot createNewTileEntity (World world, int data) {
};

@Override
public Vec3[] getChainAttachPoints () {
return chainAttachPoints;
public Vec3[] getChainAttachPoints (int side) {
if (side == 1)
return chainAttachPoints;

return null;
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ public TileEntityMediumPot getTileEntity (IBlockAccess world, int x, int y, int
};

@Override
public Vec3[] getChainAttachPoints () {
return chainAttachPoints;
public Vec3[] getChainAttachPoints (int side) {
if (side == 1)
return chainAttachPoints;

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface IChainAttachable
{
public Vec3[] getChainAttachPoints ();
public Vec3[] getChainAttachPoints (int side);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jaquadro.minecraft.gardencore.api.block;

import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;

public interface IChainSingleAttachable
{
Vec3 getChainAttachPoint (IBlockAccess blockAccess, int x, int y, int z, int side);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jaquadro.minecraft.gardencore.core.ModCreativeTabs;
import com.jaquadro.minecraft.gardenstuff.GardenStuff;
import com.jaquadro.minecraft.gardenstuff.core.ClientProxy;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -48,7 +49,7 @@ public boolean renderAsNormalBlock () {

@Override
public int getRenderType () {
return 1; // Crossed Squares
return ClientProxy.heavyChainRenderID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public BlockLantern (String blockName) {
setBlockBoundsForItemRender();
}

@Override
public String getItemIconName () {
return GardenStuff.MOD_ID + ":lantern";
}

@Override
public boolean isOpaqueCube () {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Vec3[] getAttachPoints (IBlockAccess world, int x, int y, int z) {

Vec3[] attachPoints = singleAttachPoint;
if (bottomBlock instanceof IChainAttachable)
attachPoints = ((IChainAttachable) bottomBlock).getChainAttachPoints();
attachPoints = ((IChainAttachable) bottomBlock).getChainAttachPoints(1);
else if (bottomBlock.isSideSolid(world, x, y, z, ForgeDirection.UP))
attachPoints = defaultAttachPoints;

Expand Down
4 changes: 4 additions & 0 deletions src/com/jaquadro/minecraft/gardenstuff/core/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.jaquadro.minecraft.gardenstuff.core;

import com.jaquadro.minecraft.gardenstuff.renderer.HeavyChainRenderer;
import com.jaquadro.minecraft.gardenstuff.renderer.LanternRenderer;
import com.jaquadro.minecraft.gardenstuff.renderer.LatticeRenderer;
import com.jaquadro.minecraft.gardenstuff.renderer.LightChainRenderer;
import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends CommonProxy
{
public static int heavyChainRenderID;
public static int lightChainRenderID;
public static int latticeRenderID;
public static int lanternRenderID;
Expand All @@ -15,12 +17,14 @@ public class ClientProxy extends CommonProxy

@Override
public void registerRenderers () {
heavyChainRenderID = RenderingRegistry.getNextAvailableRenderId();
lightChainRenderID = RenderingRegistry.getNextAvailableRenderId();
latticeRenderID = RenderingRegistry.getNextAvailableRenderId();
lanternRenderID = RenderingRegistry.getNextAvailableRenderId();

lanternRenderer = new LanternRenderer();

RenderingRegistry.registerBlockHandler(heavyChainRenderID, new HeavyChainRenderer());
RenderingRegistry.registerBlockHandler(lightChainRenderID, new LightChainRenderer());
RenderingRegistry.registerBlockHandler(latticeRenderID, new LatticeRenderer());
RenderingRegistry.registerBlockHandler(lanternRenderID, lanternRenderer);
Expand Down
7 changes: 2 additions & 5 deletions src/com/jaquadro/minecraft/gardenstuff/core/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.jaquadro.minecraft.gardenstuff.block.*;
import com.jaquadro.minecraft.gardenstuff.block.tile.TileEntityLatticeMetal;
import com.jaquadro.minecraft.gardenstuff.block.tile.TileEntityLatticeWood;
import com.jaquadro.minecraft.gardenstuff.item.ItemHeavyChain;
import com.jaquadro.minecraft.gardenstuff.item.ItemLatticeMetal;
import com.jaquadro.minecraft.gardenstuff.item.ItemLatticeWood;
import com.jaquadro.minecraft.gardenstuff.item.ItemLightChain;
import com.jaquadro.minecraft.gardenstuff.item.*;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -36,7 +33,7 @@ public void init () {
GameRegistry.registerBlock(latticeMetal, ItemLatticeMetal.class, "lattice");
GameRegistry.registerBlock(latticeWood, ItemLatticeWood.class, "lattice_wood");
GameRegistry.registerBlock(rootCover, "root_cover");
GameRegistry.registerBlock(lantern, "lantern");
GameRegistry.registerBlock(lantern, ItemLantern.class, "lantern");
//GameRegistry.registerBlock(largeMountingPlate, "large_mounting_plate");

GameRegistry.registerTileEntity(TileEntityLatticeMetal.class, ModBlocks.getQualifiedName(latticeMetal));
Expand Down
14 changes: 14 additions & 0 deletions src/com/jaquadro/minecraft/gardenstuff/item/ItemLantern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jaquadro.minecraft.gardenstuff.item;

import com.jaquadro.minecraft.gardenstuff.GardenStuff;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.IIcon;

public class ItemLantern extends ItemBlock
{
public ItemLantern (Block block) {
super(block);
setTextureName(GardenStuff.MOD_ID + ":lantern");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.jaquadro.minecraft.gardenstuff.renderer;

import com.jaquadro.minecraft.gardencore.api.block.IChainAttachable;
import com.jaquadro.minecraft.gardencore.api.block.IChainSingleAttachable;
import com.jaquadro.minecraft.gardencore.util.RenderUtil;
import com.jaquadro.minecraft.gardenstuff.block.BlockHeavyChain;
import com.jaquadro.minecraft.gardenstuff.core.ClientProxy;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;

/**
* Created by Justin on 3/6/2015.
*/
public class HeavyChainRenderer implements ISimpleBlockRenderingHandler
{
private static final Vec3[] defaultAttachPoint = new Vec3[] {
Vec3.createVectorHelper(.5, 0, .5),
Vec3.createVectorHelper(.5, 1, .5),
Vec3.createVectorHelper(.5, .5, 0),
Vec3.createVectorHelper(.5, .5, 1),
Vec3.createVectorHelper(0, .5, .5),
Vec3.createVectorHelper(1, .5, .5),
};
@Override
public void renderInventoryBlock (Block block, int metadata, int modelId, RenderBlocks renderer) {

}

@Override
public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if (block instanceof BlockHeavyChain)
return renderWorldBlock(world, x, y, z, (BlockHeavyChain)block, modelId, renderer);

return false;
}

private boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, BlockHeavyChain block, int modelId, RenderBlocks renderer) {
renderer.setRenderBounds(0, 0, 0, 1, 1, 1);
renderCrossedSquares(renderer, block, x, y, z);

Block upperBlock = world.getBlock(x, y + 1, z);
if (upperBlock instanceof IChainSingleAttachable) {
Vec3 attach = ((IChainSingleAttachable) upperBlock).getChainAttachPoint(world, x, y + 1, z, 0);
if (attach != null && attach != defaultAttachPoint[0]) {
renderer.setRenderBounds(0, 0, 0, 1, attach.yCoord, 1);
renderer.setOverrideBlockTexture(block.getIcon(world, x, y, z, 0));
renderCrossedSquares(renderer, block, x, y + 1, z);
renderer.setOverrideBlockTexture(null);
}
}

Block lowerBlock = world.getBlock(x, y - 1, z);
if (lowerBlock instanceof IChainSingleAttachable) {
Vec3 attach = ((IChainSingleAttachable) lowerBlock).getChainAttachPoint(world, x, y - 1, z, 0);
if (attach != null && attach != defaultAttachPoint[1]) {
renderer.setRenderBounds(0, attach.yCoord, 0, 1, 1, 1);
renderer.setOverrideBlockTexture(block.getIcon(world, x, y, z, 0));
renderCrossedSquares(renderer, block, x, y - 1, z);
renderer.setOverrideBlockTexture(null);
}
}

return true;
}

@Override
public boolean shouldRender3DInInventory (int modelId) {
return false;
}

@Override
public int getRenderId () {
return ClientProxy.heavyChainRenderID;
}

private void renderCrossedSquares (RenderBlocks renderer, Block block, int x, int y, int z)
{
Tessellator tessellator = Tessellator.instance;
tessellator.setBrightness(block.getMixedBrightnessForBlock(renderer.blockAccess, x, y, z));
int l = block.colorMultiplier(renderer.blockAccess, x, y, z);
float f = (float)(l >> 16 & 255) / 255.0F;
float f1 = (float)(l >> 8 & 255) / 255.0F;
float f2 = (float)(l & 255) / 255.0F;

if (EntityRenderer.anaglyphEnable)
{
float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F;
float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F;
float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F;
f = f3;
f1 = f4;
f2 = f5;
}

tessellator.setColorOpaque_F(f, f1, f2);

IIcon iicon = renderer.getBlockIconFromSideAndMetadata(block, 0, renderer.blockAccess.getBlockMetadata(x, y, z));
drawCrossedSquares(renderer, iicon, x, y, z, 1.0F);
}

private void drawCrossedSquares(RenderBlocks renderer, IIcon icon, double x, double y, double z, float scale)
{
Tessellator tessellator = Tessellator.instance;
if (renderer.hasOverrideBlockTexture())
icon = renderer.overrideBlockTexture;

double uMin = icon.getInterpolatedU(renderer.renderMinX * 16.0D);
double uMax = icon.getInterpolatedU(renderer.renderMaxX * 16.0D);
double vMin = icon.getInterpolatedV(16 - renderer.renderMaxY * 16.0D);
double vMax = icon.getInterpolatedV(16 - renderer.renderMinY * 16.0D);

double d7 = 0.45D * (double)scale;
double xMin = x + 0.5D - d7;
double xMax = x + 0.5D + d7;
double yMin = y + renderer.renderMinY * scale;
double yMax = y + renderer.renderMaxY * scale;
double zMin = z + 0.5D - d7;
double zMax = z + 0.5D + d7;

tessellator.addVertexWithUV(xMin, yMax, zMin, uMin, vMin);
tessellator.addVertexWithUV(xMin, yMin, zMin, uMin, vMax);
tessellator.addVertexWithUV(xMax, yMin, zMax, uMax, vMax);
tessellator.addVertexWithUV(xMax, yMax, zMax, uMax, vMin);
tessellator.addVertexWithUV(xMax, yMax, zMax, uMin, vMin);
tessellator.addVertexWithUV(xMax, yMin, zMax, uMin, vMax);
tessellator.addVertexWithUV(xMin, yMin, zMin, uMax, vMax);
tessellator.addVertexWithUV(xMin, yMax, zMin, uMax, vMin);

tessellator.addVertexWithUV(xMin, yMax, zMax, uMin, vMin);
tessellator.addVertexWithUV(xMin, yMin, zMax, uMin, vMax);
tessellator.addVertexWithUV(xMax, yMin, zMin, uMax, vMax);
tessellator.addVertexWithUV(xMax, yMax, zMin, uMax, vMin);
tessellator.addVertexWithUV(xMax, yMax, zMin, uMin, vMin);
tessellator.addVertexWithUV(xMax, yMin, zMin, uMin, vMax);
tessellator.addVertexWithUV(xMin, yMin, zMax, uMax, vMax);
tessellator.addVertexWithUV(xMin, yMax, zMax, uMax, vMin);
}
}
29 changes: 28 additions & 1 deletion src/com/jaquadro/minecraft/gardentrees/block/BlockThinLog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jaquadro.minecraft.gardentrees.block;

import com.jaquadro.minecraft.gardencore.api.WoodRegistry;
import com.jaquadro.minecraft.gardencore.api.block.IChainSingleAttachable;
import com.jaquadro.minecraft.gardencore.util.UniqueMetaIdentifier;
import com.jaquadro.minecraft.gardentrees.block.tile.TileEntityWoodProxy;
import com.jaquadro.minecraft.gardentrees.core.ClientProxy;
Expand All @@ -24,6 +25,7 @@
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
Expand All @@ -32,7 +34,7 @@
import java.util.Map.Entry;
import java.util.Random;

public class BlockThinLog extends BlockContainer
public class BlockThinLog extends BlockContainer implements IChainSingleAttachable
{
public static final String[] subNames = new String[] { "oak", "spruce", "birch", "jungle", "acacia", "big_oak" };

Expand Down Expand Up @@ -429,4 +431,29 @@ public boolean canSustainLeaves (IBlockAccess world, int x, int y, int z) {
public TileEntity createNewTileEntity (World world, int meta) {
return new TileEntityWoodProxy();
}

private final Vec3[] attachPoints = new Vec3[] {
Vec3.createVectorHelper(.5, getMargin(), .5),
Vec3.createVectorHelper(.5, 1 - getMargin(), .5),
Vec3.createVectorHelper(.5, .5, getMargin()),
Vec3.createVectorHelper(.5, .5, 1 - getMargin()),
Vec3.createVectorHelper(getMargin(), .5, .5),
Vec3.createVectorHelper(1 - getMargin(), .5, .5),
};

@Override
public Vec3 getChainAttachPoint (IBlockAccess blockAccess, int x, int y, int z, int side) {
int connectFlags = calcConnectionFlags(blockAccess, x, y, z);

switch (side) {
case 0: return (connectFlags & 1) == 0 ? attachPoints[0] : null;
case 1: return (connectFlags & 2) == 0 ? attachPoints[1] : null;
case 2: return (connectFlags & 4) == 0 ? attachPoints[2] : null;
case 3: return (connectFlags & 8) == 0 ? attachPoints[3] : null;
case 4: return (connectFlags & 16) == 0 ? attachPoints[4] : null;
case 5: return (connectFlags & 32) == 0 ? attachPoints[5] : null;
}

return null;
}
}

0 comments on commit e1078ef

Please sign in to comment.