mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 09:37:29 +00:00
==STILL SLIGHTLY BUGGED==
Scripted blocks now render exactly like regular blocks in the world.
This commit is contained in:
1 parent
b9170d77f5
commit
5a84ed47d9
3 files changed
+58
-12
No files matched your search
@@ -25,6 +25,8 @@ import noppes.npcs.constants.EnumGuiType;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockScripted extends BlockContainer {
|
||||
|
||||
public int renderId = -1;
|
||||
public static final AxisAlignedBB AABB = AxisAlignedBB.getBoundingBox(0.001f, 0.001f, 0.001f, 0.998f, 0.998f, 0.998f);
|
||||
public static final AxisAlignedBB AABB_EMPTY = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
|
||||
|
||||
@@ -109,12 +111,12 @@ public class BlockScripted extends BlockContainer {
|
||||
|
||||
@Override
|
||||
public boolean canRenderInPass(int pass) {
|
||||
return false;
|
||||
return super.canRenderInPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 0;
|
||||
return renderId;
|
||||
}
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import noppes.npcs.*;
|
||||
import noppes.npcs.api.IBlock;
|
||||
import noppes.npcs.api.block.ITextPlane;
|
||||
@@ -48,6 +49,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
|
||||
public ItemStack itemModel = new ItemStack(CustomItems.scripted);
|
||||
public Block blockModel = null;
|
||||
private int metadata;
|
||||
|
||||
public boolean needsClientUpdate = false;
|
||||
|
||||
@@ -68,6 +70,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
|
||||
public TileEntity renderTile;
|
||||
public boolean renderTileErrored = true;
|
||||
public boolean renderFullBlock = true;
|
||||
public ITickable renderTileUpdate = null;
|
||||
|
||||
public TextPlane text1 = new TextPlane();
|
||||
@@ -219,9 +222,14 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
EventHooks.onScriptBlockUpdate(this);
|
||||
ticksExisted = 0;
|
||||
if(needsClientUpdate){
|
||||
markDirty();
|
||||
worldObj.func_147451_t(xCoord, yCoord, zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord,yCoord,zCoord,getBlockType(),3);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, CustomItems.scripted);
|
||||
|
||||
Chunk chunk = worldObj.getChunkFromChunkCoords(xCoord >> 4, zCoord >> 4);
|
||||
chunk.setBlockMetadata(xCoord & 15, yCoord, zCoord & 15, metadata);
|
||||
blockMetadata = metadata;
|
||||
|
||||
needsClientUpdate = false;
|
||||
}
|
||||
}
|
||||
@@ -273,6 +281,11 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
if(NoppesUtilPlayer.compareItems(item, itemModel, false, false) && b != blockModel)
|
||||
return;
|
||||
|
||||
boolean blockChanged = b != blockModel;
|
||||
int meta = item.getItemDamage();
|
||||
metadata = (meta == 0 || meta == metadata) && blockChanged ? metadata + 1 : meta;
|
||||
this.blockMetadata = metadata;
|
||||
|
||||
itemModel = item;
|
||||
blockModel = b;
|
||||
needsClientUpdate = true;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package noppes.npcs.client.renderer.blocks;
|
||||
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.src.FMLRenderAccessLibrary;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.blocks.BlockScripted;
|
||||
@@ -28,6 +28,38 @@ public class BlockScriptedRenderer extends BlockRendererInterface{
|
||||
private static final RenderBlocks renderBlocks = new RenderBlocks();
|
||||
private static final Random random = new Random();
|
||||
|
||||
public BlockScriptedRenderer() {
|
||||
((BlockScripted) CustomItems.scripted).renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
TileScripted tile = (TileScripted) world.getTileEntity(x, y, z);
|
||||
Block blockModel = tile.blockModel;
|
||||
|
||||
if (!overrideModel() && blockModel != null) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glRotatef(tile.rotationY, 0, 1, 0);
|
||||
GL11.glRotatef(tile.rotationX, 1, 0, 0);
|
||||
GL11.glRotatef(tile.rotationZ, 0, 0, 1);
|
||||
GL11.glScalef(tile.scaleX, tile.scaleY, tile.scaleZ);
|
||||
if (blockModel != CustomItems.scripted) {
|
||||
tile.renderFullBlock = renderer.renderBlockByRenderType(blockModel, x, y, z);
|
||||
} else {
|
||||
renderer.renderStandardBlock(blockModel, x, y, z);
|
||||
tile.renderFullBlock = true;
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getRenderId() {
|
||||
return CustomItems.scripted.getRenderType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks) {
|
||||
TileScripted tile = (TileScripted) te;
|
||||
@@ -38,8 +70,7 @@ public class BlockScriptedRenderer extends BlockRendererInterface{
|
||||
GL11.glTranslatef((float) (x + 0.5), (float) y, (float) (z + 0.5));
|
||||
if (overrideModel()) {
|
||||
GL11.glTranslatef(0, 0.5F, 0);
|
||||
renderItem(te, new ItemStack(CustomItems.scripted));
|
||||
} else {
|
||||
} else if (!tile.renderFullBlock) {
|
||||
GL11.glRotatef(tile.rotationY, 0, 1, 0);
|
||||
GL11.glRotatef(tile.rotationX, 1, 0, 0);
|
||||
GL11.glRotatef(tile.rotationZ, 0, 0, 1);
|
||||
@@ -166,7 +197,7 @@ public class BlockScriptedRenderer extends BlockRendererInterface{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return 0;
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user