Added border and camouflage to ship scanner
Refactored camouflage handling
This commit is contained in:
parent
e8e89c0bd5
commit
2ce52712f7
7 changed files with 463 additions and 125 deletions
|
@ -133,6 +133,7 @@ import cr0s.warpdrive.item.ItemUpgrade;
|
|||
import cr0s.warpdrive.item.ItemWarpArmor;
|
||||
import cr0s.warpdrive.network.PacketHandler;
|
||||
import cr0s.warpdrive.render.ClientCameraHandler;
|
||||
import cr0s.warpdrive.render.RenderBlockShipScanner;
|
||||
import cr0s.warpdrive.render.RenderBlockForceField;
|
||||
import cr0s.warpdrive.render.RenderBlockOmnipanel;
|
||||
import cr0s.warpdrive.render.RenderBlockStandard;
|
||||
|
@ -321,6 +322,9 @@ public class WarpDrive implements LoadingCallback {
|
|||
|
||||
RenderBlockOmnipanel.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(RenderBlockOmnipanel.instance);
|
||||
|
||||
RenderBlockShipScanner.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(RenderBlockShipScanner.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,18 @@ package cr0s.warpdrive.block.building;
|
|||
import java.util.Random;
|
||||
|
||||
import cr0s.warpdrive.Commons;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import cr0s.warpdrive.block.BlockAbstractContainer;
|
||||
import cr0s.warpdrive.render.RenderBlockShipScanner;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -22,6 +26,9 @@ public class BlockShipScanner extends BlockAbstractContainer {
|
|||
private static final int ICON_BOTTOM = 0;
|
||||
private static final int ICON_TOP = 1;
|
||||
private static final int ICON_SIDE = 2;
|
||||
private static final int ICON_BORDER = 3;
|
||||
|
||||
public static int passCurrent;
|
||||
|
||||
public BlockShipScanner() {
|
||||
super(Material.iron);
|
||||
|
@ -32,9 +39,10 @@ public class BlockShipScanner extends BlockAbstractContainer {
|
|||
@Override
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
iconBuffer = new IIcon[16];
|
||||
iconBuffer[ICON_BOTTOM] = iconRegister.registerIcon("warpdrive:building/shipScannerBottom");
|
||||
iconBuffer[ICON_TOP ] = iconRegister.registerIcon("warpdrive:building/shipScannerTop");
|
||||
iconBuffer[ICON_SIDE ] = iconRegister.registerIcon("warpdrive:building/shipScannerSide");
|
||||
iconBuffer[ICON_BOTTOM ] = iconRegister.registerIcon("warpdrive:building/shipScannerBottom");
|
||||
iconBuffer[ICON_TOP ] = iconRegister.registerIcon("warpdrive:building/shipScannerTop");
|
||||
iconBuffer[ICON_SIDE ] = iconRegister.registerIcon("warpdrive:building/shipScannerSide");
|
||||
iconBuffer[ICON_BORDER ] = iconRegister.registerIcon("warpdrive:building/shipScanner-border");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -50,6 +58,57 @@ public class BlockShipScanner extends BlockAbstractContainer {
|
|||
return iconBuffer[ICON_SIDE];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBorderIcon() {
|
||||
return iconBuffer[ICON_BORDER];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return RenderBlockShipScanner.renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderBlockPass() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInPass(final int pass) {
|
||||
passCurrent = pass;
|
||||
return pass == 0 || pass == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int colorMultiplier(IBlockAccess blockAccess, int x, int y, int z) {
|
||||
final TileEntity tileEntity = blockAccess.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileEntityShipScanner && ((TileEntityShipScanner) tileEntity).blockCamouflage != null) {
|
||||
return ((TileEntityShipScanner) tileEntity).colorMultiplierCamouflage;
|
||||
}
|
||||
|
||||
return super.colorMultiplier(blockAccess, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(IBlockAccess blockAccess, int x, int y, int z) {
|
||||
final TileEntity tileEntity = blockAccess.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileEntityShipScanner) {
|
||||
return ((TileEntityShipScanner) tileEntity).lightCamouflage;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1, int i) {
|
||||
return new TileEntityShipScanner();
|
||||
|
@ -74,8 +133,26 @@ public class BlockShipScanner extends BlockAbstractContainer {
|
|||
if (entityPlayer.getHeldItem() == null) {
|
||||
final TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileEntityShipScanner) {
|
||||
Commons.addChatMessage(entityPlayer, ((TileEntityShipScanner) tileEntity).getStatus());
|
||||
return true;
|
||||
final Block blockAbove = world.getBlock(x, y + 2, z);
|
||||
if ( blockAbove.isAir(world, x, y + 2, z)
|
||||
|| !entityPlayer.isSneaking() ) {
|
||||
Commons.addChatMessage(entityPlayer, ((TileEntityShipScanner) tileEntity).getStatus());
|
||||
return true;
|
||||
} else if (blockAbove != this) {
|
||||
((TileEntityShipScanner) tileEntity).blockCamouflage = blockAbove;
|
||||
((TileEntityShipScanner) tileEntity).metadataCamouflage = world.getBlockMetadata(x, y + 2, z);
|
||||
((TileEntityShipScanner) tileEntity).colorMultiplierCamouflage = 0x808080; // blockAbove.colorMultiplier(world, x, y + 2, z);
|
||||
((TileEntityShipScanner) tileEntity).lightCamouflage = blockAbove.getLightValue(world, x, y + 2, z);
|
||||
tileEntity.markDirty();
|
||||
world.setBlockMetadataWithNotify(x, y, z, ((TileEntityShipScanner) tileEntity).metadataCamouflage, 2);
|
||||
} else {
|
||||
((TileEntityShipScanner) tileEntity).blockCamouflage = null;
|
||||
((TileEntityShipScanner) tileEntity).metadataCamouflage = 0;
|
||||
((TileEntityShipScanner) tileEntity).colorMultiplierCamouflage = 0;
|
||||
((TileEntityShipScanner) tileEntity).lightCamouflage = 0;
|
||||
tileEntity.markDirty();
|
||||
world.setBlockMetadataWithNotify(x, y, z, ((TileEntityShipScanner) tileEntity).metadataCamouflage, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
@ -46,6 +49,16 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
|
||||
private static final int SHIP_TOKEN_MAX_RETRY_COUNT = 5;
|
||||
|
||||
// persistent properties
|
||||
private String schematicFileName = "";
|
||||
private int targetX, targetY, targetZ;
|
||||
private byte rotationSteps;
|
||||
public Block blockCamouflage;
|
||||
public int metadataCamouflage;
|
||||
protected int colorMultiplierCamouflage;
|
||||
protected int lightCamouflage;
|
||||
|
||||
// computed properties
|
||||
private boolean isActive = false;
|
||||
private TileEntityShipCore shipCore = null;
|
||||
|
||||
|
@ -56,7 +69,6 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
|
||||
private int searchTicks = 0;
|
||||
|
||||
private String schematicFileName = "";
|
||||
private String playerName = "";
|
||||
|
||||
private JumpShip jumpShip;
|
||||
|
@ -64,9 +76,6 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
private int blocksToDeployCount;
|
||||
private boolean isDeploying = false;
|
||||
|
||||
private int targetX, targetY, targetZ;
|
||||
private byte rotationSteps;
|
||||
|
||||
public TileEntityShipScanner() {
|
||||
super();
|
||||
|
||||
|
@ -93,8 +102,9 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
shipCore = searchShipCore();
|
||||
}
|
||||
|
||||
// Trigger deployment by player
|
||||
if (!isActive) {
|
||||
// Trigger deployment by player, provided setup is done
|
||||
final boolean isSetupDone = targetX != 0 || targetY != 0 || targetZ != 0;
|
||||
if (!isActive && isSetupDone) {
|
||||
checkPlayerForShipToken();
|
||||
}
|
||||
|
||||
|
@ -279,10 +289,16 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
}
|
||||
}
|
||||
|
||||
private void setActive(boolean newState) {
|
||||
isActive = newState;
|
||||
if ((getBlockMetadata() == 1) == newState) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActive ? 1 : 0, 2);
|
||||
private void setActive(final boolean newState) {
|
||||
if (blockCamouflage == null) {
|
||||
isActive = newState;
|
||||
if ((getBlockMetadata() == 1) == newState) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActive ? 1 : 0, 2);
|
||||
}
|
||||
} else {
|
||||
if (getBlockMetadata() != metadataCamouflage) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadataCamouflage, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,23 +589,64 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
schematicFileName = tag.getString("schematic");
|
||||
targetX = tag.getInteger("targetX");
|
||||
targetY = tag.getInteger("targetY");
|
||||
targetZ = tag.getInteger("targetZ");
|
||||
rotationSteps = tag.getByte("rotationSteps");
|
||||
public void readFromNBT(NBTTagCompound tatagCompound) {
|
||||
super.readFromNBT(tatagCompound);
|
||||
schematicFileName = tatagCompound.getString("schematic");
|
||||
targetX = tatagCompound.getInteger("targetX");
|
||||
targetY = tatagCompound.getInteger("targetY");
|
||||
targetZ = tatagCompound.getInteger("targetZ");
|
||||
rotationSteps = tatagCompound.getByte("rotationSteps");
|
||||
if (tatagCompound.hasKey("camouflageBlock")) {
|
||||
try {
|
||||
blockCamouflage = Block.getBlockFromName(tatagCompound.getString("camouflageBlock"));
|
||||
metadataCamouflage = tatagCompound.getByte("camouflageMeta");
|
||||
colorMultiplierCamouflage = tatagCompound.getInteger("camouflageColorMultiplier");
|
||||
lightCamouflage = tatagCompound.getByte("camouflageLight");
|
||||
if (Dictionary.BLOCKS_NOCAMOUFLAGE.contains(blockCamouflage)) {
|
||||
blockCamouflage = null;
|
||||
metadataCamouflage = 0;
|
||||
colorMultiplierCamouflage = 0;
|
||||
lightCamouflage = 0;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
blockCamouflage = null;
|
||||
metadataCamouflage = 0;
|
||||
colorMultiplierCamouflage = 0;
|
||||
lightCamouflage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setString("schematic", schematicFileName);
|
||||
tag.setInteger("targetX", targetX);
|
||||
tag.setInteger("targetY", targetY);
|
||||
tag.setInteger("targetZ", targetZ);
|
||||
tag.setByte("rotationSteps", rotationSteps);
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setString("schematic", schematicFileName);
|
||||
tagCompound.setInteger("targetX", targetX);
|
||||
tagCompound.setInteger("targetY", targetY);
|
||||
tagCompound.setInteger("targetZ", targetZ);
|
||||
tagCompound.setByte("rotationSteps", rotationSteps);
|
||||
if (blockCamouflage != null) {
|
||||
tagCompound.setString("camouflageBlock", Block.blockRegistry.getNameForObject( blockCamouflage));
|
||||
tagCompound.setByte("camouflageMeta", (byte) metadataCamouflage);
|
||||
tagCompound.setInteger("camouflageColorMultiplier", colorMultiplierCamouflage);
|
||||
tagCompound.setByte("camouflageLight", (byte) lightCamouflage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
writeToNBT(tagCompound);
|
||||
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -1, tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
|
@ -718,11 +775,6 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
|
|||
}
|
||||
shipToken_nextUpdate_ticks = SHIP_TOKEN_UPDATE_PERIOD_TICKS;
|
||||
|
||||
// skip unless setup is done
|
||||
if (targetX == 0 && targetY == 0 && targetZ == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find a unique player in range
|
||||
final AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(xCoord - 1.0D, yCoord + 1.0D, zCoord - 1.0D,
|
||||
xCoord + 1.99D, yCoord + 5.0D, zCoord + 1.99D);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class TileEntityForceField extends TileEntityAbstractBase {
|
|||
if (tag.hasKey("projector")) {
|
||||
vProjector = VectorI.createFromNBT(tag.getCompoundTag("projector"));
|
||||
cache_beamFrequency = tag.getInteger(IBeamFrequency.BEAM_FREQUENCY_TAG);
|
||||
if (tag.hasKey("projector")) {
|
||||
if (tag.hasKey("camouflageBlock")) {
|
||||
try {
|
||||
cache_blockCamouflage = Block.getBlockFromName(tag.getString("camouflageBlock"));
|
||||
cache_metadataCamouflage = tag.getByte("camouflageMeta");
|
||||
|
@ -78,9 +78,9 @@ public class TileEntityForceField extends TileEntityAbstractBase {
|
|||
tagCompound.setInteger(IBeamFrequency.BEAM_FREQUENCY_TAG, cache_beamFrequency);
|
||||
if (cache_blockCamouflage != null) {
|
||||
tagCompound.setString("camouflageBlock", Block.blockRegistry.getNameForObject(cache_blockCamouflage));
|
||||
tagCompound.setByte("camouflageMeta", (byte)cache_metadataCamouflage);
|
||||
tagCompound.setByte("camouflageMeta", (byte) cache_metadataCamouflage);
|
||||
tagCompound.setInteger("camouflageColorMultiplier", cache_colorMultiplierCamouflage);
|
||||
tagCompound.setByte("camouflageLight", (byte)cache_lightCamouflage);
|
||||
tagCompound.setByte("camouflageLight", (byte) cache_lightCamouflage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,9 @@
|
|||
package cr0s.warpdrive.render;
|
||||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.block.forcefield.TileEntityForceField;
|
||||
import cr0s.warpdrive.config.Dictionary;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAnvil;
|
||||
import net.minecraft.block.BlockBeacon;
|
||||
import net.minecraft.block.BlockBrewingStand;
|
||||
import net.minecraft.block.BlockCauldron;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.BlockDragonEgg;
|
||||
import net.minecraft.block.BlockEndPortalFrame;
|
||||
import net.minecraft.block.BlockFence;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.BlockFlowerPot;
|
||||
import net.minecraft.block.BlockHopper;
|
||||
import net.minecraft.block.BlockPane;
|
||||
import net.minecraft.block.BlockRailBase;
|
||||
import net.minecraft.block.BlockRedstoneComparator;
|
||||
import net.minecraft.block.BlockRedstoneDiode;
|
||||
import net.minecraft.block.BlockRedstoneRepeater;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.BlockWall;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -56,74 +36,7 @@ public class RenderBlockForceField implements ISimpleBlockRenderingHandler {
|
|||
renderType = blockCamouflage.getRenderType();
|
||||
}
|
||||
|
||||
if (renderType >= 0) {
|
||||
try {
|
||||
blockCamouflage.setBlockBoundsBasedOnState(renderer.blockAccess, x, y, z);
|
||||
renderer.setRenderBoundsFromBlock(blockCamouflage);
|
||||
|
||||
switch (renderType) {
|
||||
case 0 : renderer.renderStandardBlock(blockCamouflage, x, y, z); break;
|
||||
case 1 : renderer.renderCrossedSquares(blockCamouflage, x, y, z); break;
|
||||
case 2 : renderer.renderBlockTorch(blockCamouflage, x, y, z); break;
|
||||
case 3 : renderer.renderBlockFire((BlockFire)blockCamouflage, x, y, z); break;
|
||||
// case 4 : renderer.renderBlockLiquid(blockCamouflage, x, y, z); break; // not working due to material check of neighbours during computation
|
||||
case 5 : renderer.renderBlockRedstoneWire(blockCamouflage, x, y, z); break;
|
||||
case 6 : renderer.renderBlockCrops(blockCamouflage, x, y, z); break;
|
||||
// case 7 : renderer.renderBlockDoor(blockCamouflage, x, y, z); break; // not working and doesn't make sense
|
||||
case 9 : renderer.renderBlockMinecartTrack((BlockRailBase)blockCamouflage, x, y, z); break;
|
||||
case 10 : renderer.renderBlockStairs((BlockStairs)blockCamouflage, x, y, z); break;
|
||||
case 11 : renderer.renderBlockFence((BlockFence)blockCamouflage, x, y, z); break;
|
||||
case 12 : renderer.renderBlockLever(blockCamouflage, x, y, z); break;
|
||||
case 13 : renderer.renderBlockCactus(blockCamouflage, x, y, z); break;
|
||||
case 14 : renderer.renderBlockBed(blockCamouflage, x, y, z); break;
|
||||
case 15 : renderer.renderBlockRepeater((BlockRedstoneRepeater)blockCamouflage, x, y, z); break;
|
||||
case 16 : renderer.renderPistonBase(blockCamouflage, x, y, z, false); break;
|
||||
case 17 : renderer.renderPistonExtension(blockCamouflage, x, y, z, true); break;
|
||||
case 18 : renderer.renderBlockPane((BlockPane)blockCamouflage, x, y, z); break;
|
||||
// 19 is stem
|
||||
case 20 : renderer.renderBlockVine(blockCamouflage, x, y, z); break;
|
||||
case 21 : renderer.renderBlockFenceGate((BlockFenceGate)blockCamouflage, x, y, z); break;
|
||||
// 22 is chest
|
||||
case 23 : renderer.renderBlockLilyPad(blockCamouflage, x, y, z); break;
|
||||
case 24 : renderer.renderBlockCauldron((BlockCauldron)blockCamouflage, x, y, z); break;
|
||||
case 25 : renderer.renderBlockBrewingStand((BlockBrewingStand)blockCamouflage, x, y, z); break;
|
||||
case 26 : renderer.renderBlockEndPortalFrame((BlockEndPortalFrame)blockCamouflage, x, y, z); break;
|
||||
case 27 : renderer.renderBlockDragonEgg((BlockDragonEgg)blockCamouflage, x, y, z); break;
|
||||
case 28 : renderer.renderBlockCocoa((BlockCocoa)blockCamouflage, x, y, z); break;
|
||||
case 29 : renderer.renderBlockTripWireSource(blockCamouflage, x, y, z); break;
|
||||
case 30 : renderer.renderBlockTripWire(blockCamouflage, x, y, z); break;
|
||||
case 31 : renderer.renderBlockLog(blockCamouflage, x, y, z); break;
|
||||
case 32 : renderer.renderBlockWall((BlockWall)blockCamouflage, x, y, z); break;
|
||||
case 33 : renderer.renderBlockFlowerpot((BlockFlowerPot)blockCamouflage, x, y, z); break; // won't render content due to tileEntity access
|
||||
case 34 : renderer.renderBlockBeacon((BlockBeacon)blockCamouflage, x, y, z); break;
|
||||
case 35 : renderer.renderBlockAnvil((BlockAnvil)blockCamouflage, x, y, z); break;
|
||||
case 36 : renderer.renderBlockRedstoneDiode((BlockRedstoneDiode)blockCamouflage, x, y, z); break;
|
||||
case 37 : renderer.renderBlockRedstoneComparator((BlockRedstoneComparator)blockCamouflage, x, y, z); break;
|
||||
case 38 : renderer.renderBlockHopper((BlockHopper)blockCamouflage, x, y, z); break;
|
||||
case 39 : renderer.renderBlockQuartz(blockCamouflage, x, y, z); break;
|
||||
// 40 is double plant
|
||||
case 41 : renderer.renderBlockStainedGlassPane(blockCamouflage, x, y, z); break;
|
||||
default:
|
||||
// blacklist the faulty block
|
||||
WarpDrive.logger.error("Disabling camouflage with block " + Block.blockRegistry.getNameForObject(blockCamouflage) + " due to invalid renderType " + renderType);
|
||||
Dictionary.BLOCKS_NOCAMOUFLAGE.add(blockCamouflage);
|
||||
return false;
|
||||
}
|
||||
} catch(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
// blacklist the faulty block
|
||||
WarpDrive.logger.error("Disabling camouflage block " + Block.blockRegistry.getNameForObject(blockCamouflage) + " due to previous exception");
|
||||
Dictionary.BLOCKS_NOCAMOUFLAGE.add(blockCamouflage);
|
||||
|
||||
// render normal force field
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
// renderer.renderBlockAsItem(blockCamouflage, metaCamouflage, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return renderer.renderStandardBlock(block, x, y, z);
|
||||
return RenderCommons.renderWorldBlockCamouflaged(x, y, z, block, renderer, renderType, blockCamouflage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
198
src/main/java/cr0s/warpdrive/render/RenderBlockShipScanner.java
Normal file
198
src/main/java/cr0s/warpdrive/render/RenderBlockShipScanner.java
Normal file
|
@ -0,0 +1,198 @@
|
|||
package cr0s.warpdrive.render;
|
||||
|
||||
import cr0s.warpdrive.block.building.BlockShipScanner;
|
||||
import cr0s.warpdrive.block.building.TileEntityShipScanner;
|
||||
import cr0s.warpdrive.config.Dictionary;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
|
||||
public class RenderBlockShipScanner implements ISimpleBlockRenderingHandler {
|
||||
|
||||
public static int renderId = 0;
|
||||
public static RenderBlockShipScanner instance = new RenderBlockShipScanner();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
final float intensity = 1.0F;
|
||||
|
||||
// simplified copy from RenderBlocks.renderBlockAsItem()
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
if (renderer.useInventoryTint) {
|
||||
final int color = block.getRenderColor(metadata);
|
||||
final float red = (float)(color >> 16 & 255) / 255.0F;
|
||||
final float green = (float)(color >> 8 & 255) / 255.0F;
|
||||
final float blue = (float)(color & 255) / 255.0F;
|
||||
GL11.glColor4f(red * intensity, green * intensity, blue * intensity, 1.0F);
|
||||
}
|
||||
|
||||
renderer.setRenderBoundsFromBlock(block);
|
||||
|
||||
block.setBlockBoundsForItemRender();
|
||||
renderer.setRenderBoundsFromBlock(block);
|
||||
GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, -1.0F, 0.0F);
|
||||
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
||||
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, -1.0F);
|
||||
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
||||
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess blockAccess, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
if (!(block instanceof BlockShipScanner)) {
|
||||
return false;
|
||||
}
|
||||
final TileEntity tileEntity = blockAccess.getTileEntity(x, y, z);
|
||||
if (!(tileEntity instanceof TileEntityShipScanner)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BlockShipScanner.passCurrent == 0) {
|
||||
// render the controlling block
|
||||
int renderType = -1;
|
||||
final Block blockCamouflage = ((TileEntityShipScanner) tileEntity).blockCamouflage;
|
||||
if (blockCamouflage != null && !Dictionary.BLOCKS_NOCAMOUFLAGE.contains(blockCamouflage)) {
|
||||
renderType = blockCamouflage.getRenderType();
|
||||
}
|
||||
|
||||
return RenderCommons.renderWorldBlockCamouflaged(x, y, z, block, renderer, renderType, blockCamouflage);
|
||||
}
|
||||
|
||||
|
||||
// check vertical offset
|
||||
final Block blockAbove = blockAccess.getBlock(x, y + 1, z);
|
||||
final boolean isHidden = !blockAbove.isAir(blockAccess, x, y + 1, z)
|
||||
&& blockAbove.isBlockSolid(blockAccess, x, y + 1, z, blockAccess.getBlockMetadata(x, y + 1, z));
|
||||
|
||||
// render borders
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.setBrightness(200); // block.getMixedBrightnessForBlock(blockAccess, x, y, z));
|
||||
|
||||
// apply coloring
|
||||
final int colorMultiplier = 0xFFFFFF; // block.colorMultiplier(blockAccess, x, y, z);
|
||||
final float fRed = (float) (colorMultiplier >> 16 & 255) / 255.0F;
|
||||
final float fGreen = (float) (colorMultiplier >> 8 & 255) / 255.0F;
|
||||
final float fBlue = (float) (colorMultiplier & 255) / 255.0F;
|
||||
tessellator.setColorOpaque_F(fRed, fGreen, fBlue);
|
||||
|
||||
// get icons
|
||||
final IIcon iconBorder = ((BlockShipScanner) block).getBorderIcon();
|
||||
|
||||
// pre-compute dimensions
|
||||
final int intRadius = 1;
|
||||
final double radius = intRadius + 0.0D;
|
||||
final int size = 1 + 2 * intRadius;
|
||||
|
||||
// pre-compute coordinates
|
||||
final double dX_min = x + 0.0D - radius;
|
||||
final double dX_max = x + 1.0D + radius;
|
||||
final double dY_min = y + (isHidden ? 1.999D : 0.999D);
|
||||
final double dY_max = dY_min + 1.0D;
|
||||
final double dZ_min = z + 0.0D - radius;
|
||||
final double dZ_max = z + 1.0D + radius;
|
||||
|
||||
final double dU_min = iconBorder.getMinU();
|
||||
final double dU_max = iconBorder.getMaxU();
|
||||
|
||||
final double dV_min = iconBorder.getMinV();
|
||||
final double dV_max = iconBorder.getMaxV();
|
||||
|
||||
// start drawing
|
||||
for (int index = 0; index < size; index++) {
|
||||
final double offsetMin = index == 0 ? 0.0D : 0.001D;
|
||||
final double offsetMax = index == size - 1 ? 0.0D : 0.001D;
|
||||
|
||||
// draw exterior faces
|
||||
tessellator.addVertexWithUV(dX_min + index + 1, dY_max, dZ_min - offsetMax, dU_max, dV_min);
|
||||
tessellator.addVertexWithUV(dX_min + index + 1, dY_min, dZ_min - offsetMax, dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + index , dY_min, dZ_min - offsetMin, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + index , dY_max, dZ_min - offsetMin, dU_min, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_max - index - 1, dY_max, dZ_max + offsetMax, dU_max, dV_min);
|
||||
tessellator.addVertexWithUV(dX_max - index - 1, dY_min, dZ_max + offsetMax, dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - index , dY_min, dZ_max + offsetMin, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - index , dY_max, dZ_max + offsetMin, dU_min, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_min - offsetMin, dY_max, dZ_min + index , dU_max, dV_min);
|
||||
tessellator.addVertexWithUV(dX_min - offsetMin, dY_min, dZ_min + index , dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min - offsetMax, dY_min, dZ_min + index + 1, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min - offsetMax, dY_max, dZ_min + index + 1, dU_min, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_max + offsetMin, dY_max, dZ_max - index , dU_max, dV_min);
|
||||
tessellator.addVertexWithUV(dX_max + offsetMin, dY_min, dZ_max - index , dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max + offsetMax, dY_min, dZ_max - index - 1, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max + offsetMax, dY_max, dZ_max - index - 1, dU_min, dV_min);
|
||||
|
||||
// draw interior faces
|
||||
tessellator.addVertexWithUV(dX_min + index , dY_max, dZ_min + offsetMin, dU_min, dV_min);
|
||||
tessellator.addVertexWithUV(dX_min + index , dY_min, dZ_min + offsetMin, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + index + 1, dY_min, dZ_min + offsetMax, dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + index + 1, dY_max, dZ_min + offsetMax, dU_max, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_max - index , dY_max, dZ_max - offsetMin, dU_min, dV_min);
|
||||
tessellator.addVertexWithUV(dX_max - index , dY_min, dZ_max - offsetMin, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - index - 1, dY_min, dZ_max - offsetMax, dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - index - 1, dY_max, dZ_max - offsetMax, dU_max, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_min + offsetMax, dY_max, dZ_min + index + 1, dU_min, dV_min);
|
||||
tessellator.addVertexWithUV(dX_min + offsetMax, dY_min, dZ_min + index + 1, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + offsetMin, dY_min, dZ_min + index , dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_min + offsetMin, dY_max, dZ_min + index , dU_max, dV_min);
|
||||
|
||||
tessellator.addVertexWithUV(dX_max - offsetMax, dY_max, dZ_max - index - 1, dU_min, dV_min);
|
||||
tessellator.addVertexWithUV(dX_max - offsetMax, dY_min, dZ_max - index - 1, dU_min, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - offsetMin, dY_min, dZ_max - index , dU_max, dV_max);
|
||||
tessellator.addVertexWithUV(dX_max - offsetMin, dY_max, dZ_max - index , dU_max, dV_min);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return renderId;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,34 @@
|
|||
package cr0s.warpdrive.render;
|
||||
|
||||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.Dictionary;
|
||||
import cr0s.warpdrive.data.EnumDisplayAlignment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAnvil;
|
||||
import net.minecraft.block.BlockBeacon;
|
||||
import net.minecraft.block.BlockBrewingStand;
|
||||
import net.minecraft.block.BlockCauldron;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.BlockDragonEgg;
|
||||
import net.minecraft.block.BlockEndPortalFrame;
|
||||
import net.minecraft.block.BlockFence;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.BlockFlowerPot;
|
||||
import net.minecraft.block.BlockHopper;
|
||||
import net.minecraft.block.BlockPane;
|
||||
import net.minecraft.block.BlockRailBase;
|
||||
import net.minecraft.block.BlockRedstoneComparator;
|
||||
import net.minecraft.block.BlockRedstoneDiode;
|
||||
import net.minecraft.block.BlockRedstoneRepeater;
|
||||
import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.BlockWall;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
|
@ -189,4 +212,75 @@ public class RenderCommons {
|
|||
// close rendering
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlockCamouflaged(final int x, final int y, final int z, final Block blockDefault, final RenderBlocks renderer, final int renderType, final Block blockCamouflage) {
|
||||
if (renderType >= 0) {
|
||||
try {
|
||||
blockCamouflage.setBlockBoundsBasedOnState(renderer.blockAccess, x, y, z);
|
||||
renderer.setRenderBoundsFromBlock(blockCamouflage);
|
||||
|
||||
switch (renderType) {
|
||||
case 0 : renderer.renderStandardBlock(blockCamouflage, x, y, z); break;
|
||||
case 1 : renderer.renderCrossedSquares(blockCamouflage, x, y, z); break;
|
||||
case 2 : renderer.renderBlockTorch(blockCamouflage, x, y, z); break;
|
||||
case 3 : renderer.renderBlockFire((BlockFire)blockCamouflage, x, y, z); break;
|
||||
// case 4 : renderer.renderBlockLiquid(blockCamouflage, x, y, z); break; // not working due to material check of neighbours during computation
|
||||
case 5 : renderer.renderBlockRedstoneWire(blockCamouflage, x, y, z); break;
|
||||
case 6 : renderer.renderBlockCrops(blockCamouflage, x, y, z); break;
|
||||
// case 7 : renderer.renderBlockDoor(blockCamouflage, x, y, z); break; // not working and doesn't make sense
|
||||
case 9 : renderer.renderBlockMinecartTrack((BlockRailBase)blockCamouflage, x, y, z); break;
|
||||
case 10 : renderer.renderBlockStairs((BlockStairs)blockCamouflage, x, y, z); break;
|
||||
case 11 : renderer.renderBlockFence((BlockFence)blockCamouflage, x, y, z); break;
|
||||
case 12 : renderer.renderBlockLever(blockCamouflage, x, y, z); break;
|
||||
case 13 : renderer.renderBlockCactus(blockCamouflage, x, y, z); break;
|
||||
case 14 : renderer.renderBlockBed(blockCamouflage, x, y, z); break;
|
||||
case 15 : renderer.renderBlockRepeater((BlockRedstoneRepeater)blockCamouflage, x, y, z); break;
|
||||
case 16 : renderer.renderPistonBase(blockCamouflage, x, y, z, false); break;
|
||||
case 17 : renderer.renderPistonExtension(blockCamouflage, x, y, z, true); break;
|
||||
case 18 : renderer.renderBlockPane((BlockPane)blockCamouflage, x, y, z); break;
|
||||
// 19 is stem
|
||||
case 20 : renderer.renderBlockVine(blockCamouflage, x, y, z); break;
|
||||
case 21 : renderer.renderBlockFenceGate((BlockFenceGate)blockCamouflage, x, y, z); break;
|
||||
// 22 is chest
|
||||
case 23 : renderer.renderBlockLilyPad(blockCamouflage, x, y, z); break;
|
||||
case 24 : renderer.renderBlockCauldron((BlockCauldron)blockCamouflage, x, y, z); break;
|
||||
case 25 : renderer.renderBlockBrewingStand((BlockBrewingStand)blockCamouflage, x, y, z); break;
|
||||
case 26 : renderer.renderBlockEndPortalFrame((BlockEndPortalFrame)blockCamouflage, x, y, z); break;
|
||||
case 27 : renderer.renderBlockDragonEgg((BlockDragonEgg)blockCamouflage, x, y, z); break;
|
||||
case 28 : renderer.renderBlockCocoa((BlockCocoa)blockCamouflage, x, y, z); break;
|
||||
case 29 : renderer.renderBlockTripWireSource(blockCamouflage, x, y, z); break;
|
||||
case 30 : renderer.renderBlockTripWire(blockCamouflage, x, y, z); break;
|
||||
case 31 : renderer.renderBlockLog(blockCamouflage, x, y, z); break;
|
||||
case 32 : renderer.renderBlockWall((BlockWall)blockCamouflage, x, y, z); break;
|
||||
case 33 : renderer.renderBlockFlowerpot((BlockFlowerPot)blockCamouflage, x, y, z); break; // won't render content due to tileEntity access
|
||||
case 34 : renderer.renderBlockBeacon((BlockBeacon)blockCamouflage, x, y, z); break;
|
||||
case 35 : renderer.renderBlockAnvil((BlockAnvil)blockCamouflage, x, y, z); break;
|
||||
case 36 : renderer.renderBlockRedstoneDiode((BlockRedstoneDiode)blockCamouflage, x, y, z); break;
|
||||
case 37 : renderer.renderBlockRedstoneComparator((BlockRedstoneComparator)blockCamouflage, x, y, z); break;
|
||||
case 38 : renderer.renderBlockHopper((BlockHopper)blockCamouflage, x, y, z); break;
|
||||
case 39 : renderer.renderBlockQuartz(blockCamouflage, x, y, z); break;
|
||||
// 40 is double plant
|
||||
case 41 : renderer.renderBlockStainedGlassPane(blockCamouflage, x, y, z); break;
|
||||
default:
|
||||
// blacklist the faulty block
|
||||
WarpDrive.logger.error("Disabling camouflage with block " + Block.blockRegistry.getNameForObject(blockCamouflage) + " due to invalid renderType " + renderType);
|
||||
Dictionary.BLOCKS_NOCAMOUFLAGE.add(blockCamouflage);
|
||||
return false;
|
||||
}
|
||||
} catch(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
// blacklist the faulty block
|
||||
WarpDrive.logger.error("Disabling camouflage block " + Block.blockRegistry.getNameForObject(blockCamouflage) + " due to previous exception");
|
||||
Dictionary.BLOCKS_NOCAMOUFLAGE.add(blockCamouflage);
|
||||
|
||||
// render normal default block
|
||||
renderer.renderStandardBlock(blockDefault, x, y, z);
|
||||
// renderer.renderBlockAsItem(blockCamouflage, metaCamouflage, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return renderer.renderStandardBlock(blockDefault, x, y, z);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue