Started work on renderer for attractor.

This commit is contained in:
CrazyPants committed 2014-09-12 00:50:59 +08:00
1 parent 0a6fce8956
commit 597d5225f3
9 files changed
+340 -32

No files matched your search

@@ -55,6 +55,9 @@ import crazypants.enderio.item.skull.BlockEndermanSkull;
import crazypants.enderio.item.skull.EndermanSkullRenderer;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.AbstractMachineRenderer;
import crazypants.enderio.machine.attractor.AttractorRenderer;
import crazypants.enderio.machine.attractor.BlockAttractor;
import crazypants.enderio.machine.attractor.TileAttractor;
import crazypants.enderio.machine.enchanter.EnchanterModelRenderer;
import crazypants.enderio.machine.enchanter.TileEnchanter;
import crazypants.enderio.machine.farm.BlockFarmStation;
@@ -203,6 +206,11 @@ public class ClientProxy extends CommonProxy {
BlockSoulBinder.renderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new SoulBinderRenderer());
BlockAttractor.renderId = RenderingRegistry.getNextAvailableRenderId();
AttractorRenderer attRen = new AttractorRenderer();
RenderingRegistry.registerBlockHandler(attRen);
ClientRegistry.bindTileEntitySpecialRenderer(TileAttractor.class, attRen);
if(Config.useCombustionGenModel) {
@@ -58,6 +58,7 @@ public final class Config {
public static final Section sectionSpawner = new Section("PoweredSpawner Settings", "spawner");
public static final Section sectionKiller = new Section("Killer Joe Settings", "killerjoe");
public static final Section sectionSoulBinder = new Section("Soul Binder Settings", "soulBinder");
public static final Section sectionAttarctor = new Section("Mob Attractor Settings", "attractor");
public static final double DEFAULT_CONDUIT_SCALE = 0.6;
@@ -287,6 +288,13 @@ public final class Config {
public static boolean soulBinderRequiresEndermanSkull = true;
public static int attractorRangeLevelOne = 16;
public static int attractorPowerPerTickLevelOne = 20;
public static int attractorRangeLevelTwo = 32;
public static int attractorPowerPerTickLevelTwo = 80;
public static int attractorRangeLevelThree = 64;
public static int attractorPowerPerTickLevelThree = 320;
public static void load(FMLPreInitializationEvent event) {
@@ -769,6 +777,19 @@ public final class Config {
"The number of RF/t consumed by a Slice'N'Splice with a double layer capacitor upgrade.").getInt(sliceAndSpliceLevelTwoPowerPerTickRF);
sliceAndSpliceLevelThreePowerPerTickRF = config.get(sectionPower.name, "sliceAndSpliceLevelThreePowerPerTickRF", sliceAndSpliceLevelThreePowerPerTickRF,
"The number of RF/t consumed by a Slice'N'Splice with an octadic capacitor upgrade.").getInt(sliceAndSpliceLevelThreePowerPerTickRF);
attractorRangeLevelOne = config.get(sectionAttarctor.name, "attractorRangeLevelOne", attractorRangeLevelOne,
"The range of the mob attractor with no upgrades").getInt(attractorRangeLevelOne);
attractorRangeLevelTwo = config.get(sectionAttarctor.name, "attractorRangeLevelTwo", attractorRangeLevelTwo,
"The range of the mob attractor with a double layer capacitor upgrade").getInt(attractorRangeLevelTwo);
attractorRangeLevelThree = config.get(sectionAttarctor.name, "attractorRangeLevelThree", attractorRangeLevelThree,
"The range of the mob attractor with an octadic capacitor upgrade").getInt(attractorRangeLevelThree);
attractorPowerPerTickLevelOne = config.get(sectionAttarctor.name, "attractorPowerPerTickLevelOne", attractorPowerPerTickLevelOne,
"The RF/t power use of a levele 1 mob attractor").getInt(attractorPowerPerTickLevelOne);
attractorPowerPerTickLevelTwo = config.get(sectionAttarctor.name, "attractorPowerPerTickLevelTwo", attractorPowerPerTickLevelTwo,
"The RF/t power use of a levele 2 mob attractor").getInt(attractorPowerPerTickLevelTwo);
attractorPowerPerTickLevelThree = config.get(sectionAttarctor.name, "attractorPowerPerTickLevelThree", attractorPowerPerTickLevelThree,
"The RF/t power use of a levele 3 mob attractor").getInt(attractorPowerPerTickLevelThree);
}
@@ -0,0 +1,188 @@
package crazypants.enderio.machine.attractor;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import crazypants.enderio.EnderIO;
import crazypants.enderio.machine.generator.combustion.TranslatedCubeRenderer;
import crazypants.enderio.machine.killera.TileKillerJoe;
import crazypants.enderio.material.Material;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.VertexTransform;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vertex;
public class AttractorRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler {
private VertXForm xform = new VertXForm();
private VertXForm2 xform2 = new VertXForm2();
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float tick) {
World world = te.getWorldObj();
float f = world.getBlockLightValue(te.xCoord, te.yCoord, te.zCoord);
int l = world.getLightBrightnessForSkyBlocks(te.xCoord, te.yCoord, te.zCoord, 0);
int l1 = l % 65536;
int l2 = l / 65536;
Tessellator.instance.setColorOpaque_F(f, f, f);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) l1, (float) l2);
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glPopMatrix();
EntityItem ei = new EntityItem(world, x, y, z, new ItemStack(EnderIO.itemMaterial, 1, Material.ENDER_CRYSTAL.ordinal()));
ei.age = (int) world.getTotalWorldTime();
//Remove the bob
float bob = ((float) ei.age + tick) / 10.0F;
ei.hoverStart = -bob;
RenderManager.instance.getEntityRenderObject(ei).doRender(ei, x + 0.5, y + 0.55, z + 0.5, 0, tick);
}
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
GL11.glDisable(GL11.GL_LIGHTING);
Tessellator.instance.startDrawingQuads();
renderWorldBlock(null, 0, 0, 0, block, 0, renderer);
Tessellator.instance.draw();
GL11.glEnable(GL11.GL_LIGHTING);
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
BoundingBox bb = BoundingBox.UNIT_CUBE;
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, null, world != null);
Tessellator.instance.addTranslation(x, y, z);
IIcon icon = block.getIcon(ForgeDirection.EAST.ordinal(), 0);
if(world != null) {
icon = block.getIcon(world, x, y, z, 0);
}
float height = 0.475f;
float width = 0.5f;
bb = BoundingBox.UNIT_CUBE.scale(width, height, 1).translate(0, -0.5f + height / 2, 0);
xform2.isX = false;
CubeRenderer.render(bb, icon, xform2);
bb = BoundingBox.UNIT_CUBE.scale(1, height, width).translate(0, -0.5f + height / 2, 0);
xform2.isX = true;
CubeRenderer.render(bb, icon, xform2);
Tessellator.instance.addTranslation(-x, -y, -z);
//
// CubeRenderer.render(block, 0, xform);
//
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return true;
}
@Override
public int getRenderId() {
return BlockAttractor.renderId;
}
private static class VertXForm implements VertexTransform {
public VertXForm() {
}
@Override
public void apply(Vertex vertex) {
apply(vertex.xyz);
}
@Override
public void apply(Vector3d vec) {
double pinch = 0.8;
if(vec.y > 0.5) {
pinch = 0.4;
}
vec.x -= 0.5;
vec.x *= pinch;
vec.x += 0.5;
vec.z -= 0.5;
vec.z *= pinch;
vec.z += 0.5;
double scale = 0.5;
vec.y -= 0.5;
vec.y *= scale;
vec.y += (0.5 * scale);
}
@Override
public void applyToNormal(Vector3f vec) {
}
}
private static class VertXForm2 implements VertexTransform {
boolean isX = true;
public VertXForm2() {
}
@Override
public void apply(Vertex vertex) {
apply(vertex.xyz);
}
@Override
public void apply(Vector3d vec) {
double pinch = 0.9;
if(vec.y > 0.2) {
pinch = 0.5;
}
if(isX) {
vec.x -= 0.5;
vec.x *= pinch;
vec.x += 0.5;
} else {
vec.z -= 0.5;
vec.z *= pinch;
vec.z += 0.5;
}
}
@Override
public void applyToNormal(Vector3f vec) {
}
}
}
@@ -1,5 +1,11 @@
package crazypants.enderio.machine.attractor;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@@ -9,6 +15,8 @@ import crazypants.enderio.machine.AbstractMachineBlock;
public class BlockAttractor extends AbstractMachineBlock<TileAttractor> {
public static int renderId;
public static BlockAttractor create() {
BlockAttractor res = new BlockAttractor();
res.init();
@@ -44,7 +52,73 @@ public class BlockAttractor extends AbstractMachineBlock<TileAttractor> {
@Override
protected String getMachineFrontIconKey(boolean active) {
return "enderio:blankMachinePanel";
if(active) {
return "enderio:blockAttractorSideOn";
}
return "enderio:blockAttractorSide";
}
@Override
protected String getSideIconKey(boolean active) {
if(active) {
return "enderio:blockAttractorSideOn";
}
return "enderio:blockAttractorSide";
}
@Override
protected String getBackIconKey(boolean active) {
if(active) {
return "enderio:blockAttractorSideOn";
}
return "enderio:blockAttractorSide";
}
@Override
protected String getTopIconKey(boolean active) {
return "enderio:blockSoulMachineTop";
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public int getLightOpacity() {
return 0;
}
@Override
public int getRenderType() {
return renderId;
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
if(isActive(world, x, y, z) && world.getTotalWorldTime() % 5 == 0) {
float startX = x + 1.0F;
float startY = y + 0.85F;
float startZ = z + 1.0F;
for (int i = 0; i < 1; i++) {
float xOffset = -0.2F - rand.nextFloat() * 0.6F;
float yOffset = -0.1F + rand.nextFloat() * 0.2F;
float zOffset = -0.2F - rand.nextFloat() * 0.6F;
EntityFX fx = Minecraft.getMinecraft().renderGlobal.doSpawnParticle("spell", startX + xOffset, startY + yOffset, startZ + zOffset, 0.0D, 0.0D, 0.0D);
if(fx != null) {
fx.setRBGColorF(0.2f, 0.2f, 0.8f);
fx.motionY *= 0.5f;
}
}
}
}
}
@@ -19,9 +19,12 @@ import com.mojang.authlib.GameProfile;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.power.BasicCapacitor;
import crazypants.enderio.power.Capacitors;
import crazypants.enderio.power.ICapacitor;
import crazypants.render.BoundingBox;
import crazypants.util.BlockCoord;
import crazypants.vecmath.Vector3d;
@@ -36,33 +39,46 @@ public class TileAttractor extends AbstractMachineEntity {
private final Set<EntityLiving> tracking = new HashSet<EntityLiving>();
private int tickCounter = 0;
private ICapacitor capacitor;
public TileAttractor() {
super(new SlotDefinition(12, 0));
updateRange();
setUpdrade(Capacitors.BASIC_CAPACITOR);
}
private void updateRange() {
// //TODO: Config
@Override
public void setCapacitor(Capacitors capacitorType) {
setUpdrade(capacitorType);
super.setCapacitor(capacitorType);
}
@Override
public ICapacitor getCapacitor() {
return capacitor;
}
private void setUpdrade(Capacitors capacitorType) {
switch (capacitorType) {
case ACTIVATED_CAPACITOR:
range = 32;
powerPerTick = 60;
range = Config.attractorRangeLevelTwo;
powerPerTick = Config.attractorPowerPerTickLevelTwo;
break;
case ENDER_CAPACITOR:
range = 64;
powerPerTick = 180;
range = Config.attractorRangeLevelThree;
powerPerTick = Config.attractorPowerPerTickLevelThree;
break;
case BASIC_CAPACITOR:
default:
range = 16;
powerPerTick = 20;
range = Config.attractorRangeLevelOne;
powerPerTick = Config.attractorPowerPerTickLevelOne;
break;
}
rangeSqu = range * range;
BoundingBox bb = new BoundingBox(new BlockCoord(this));
bb = bb.scale(range, range, range);
attractorBounds = AxisAlignedBB.getBoundingBox(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
attractorBounds = AxisAlignedBB.getBoundingBox(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
capacitor = new BasicCapacitor(powerPerTick * 8, capacitorType.capacitor.getMaxEnergyStored(), powerPerTick);
}
@Override
@@ -135,13 +151,6 @@ public class TileAttractor extends AbstractMachineEntity {
return powerPerTick;
}
@Override
public void setCapacitor(Capacitors capacitorType) {
super.setCapacitor(capacitorType);
attractorBounds = null;
updateRange();
}
FakePlayer getTarget() {
if(target == null) {
target = new Target();
@@ -156,14 +165,13 @@ public class TileAttractor extends AbstractMachineEntity {
private boolean isMobInRange(EntityLiving mob) {
return isMobInRange(mob, rangeSqu);
}
private boolean isMobInRange(EntityLiving mob, int range) {
if(mob == null) {
return false;
}
return new Vector3d(mob.posX, mob.posY, mob.posZ).distanceSquared(new Vector3d(xCoord, yCoord, zCoord)) <= range;
}
private boolean isMobInFilter(EntityLiving ent) {
return isMobInFilter(EntityList.getEntityString(ent));
@@ -180,14 +188,14 @@ public class TileAttractor extends AbstractMachineEntity {
}
return false;
}
private void trackMob(EntityLiving ent) {
if(ent instanceof EntityEnderman) {
private void trackMob(EntityLiving ent) {
if(ent instanceof EntityEnderman) {
((EntityEnderman) ent).setTarget(getTarget());
} else {
tracking.add(ent);
ent.tasks.addTask(0, new AttractTask(ent, getTarget(), new BlockCoord(this)));
}
}
}
private class Target extends FakePlayer {
@@ -211,7 +219,7 @@ public class TileAttractor extends AbstractMachineEntity {
private String entityId;
private boolean keepGoing = true;
private AttractTask(EntityLiving mob, FakePlayer target, BlockCoord coord) {
this.mob = mob;
this.coord = coord;
@@ -230,11 +238,11 @@ public class TileAttractor extends AbstractMachineEntity {
TileEntity te = mob.worldObj.getTileEntity(coord.x, coord.y, coord.z);
if(te instanceof TileAttractor) {
TileAttractor attractor = (TileAttractor) te;
res = attractor.canAttract(entityId, mob);
if(attractor.isMobInRange(mob, 2)) {
res = attractor.canAttract(entityId, mob);
if(attractor.isMobInRange(mob, 2)) {
res = false;
}
}
}
return res;
}
@@ -247,7 +255,7 @@ public class TileAttractor extends AbstractMachineEntity {
public void updateTask() {
int speed = 1;
mob.getNavigator().setAvoidsWater(false);
mob.getNavigator().tryMoveToEntityLiving(target, speed);
mob.getNavigator().tryMoveToEntityLiving(target, speed);
}
}
@@ -19,7 +19,11 @@ import crazypants.enderio.material.Alloy;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.IconUtil;
import crazypants.render.VertexTransform;
import crazypants.util.ForgeDirectionOffsets;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vertex;
public class SoulBinderRenderer implements ISimpleBlockRenderingHandler {
@@ -117,5 +121,6 @@ public class SoulBinderRenderer implements ISimpleBlockRenderingHandler {
@Override
public int getRenderId() {
return BlockSoulBinder.renderId;
}
}
}
@@ -16,11 +16,15 @@ public final class CubeRenderer {
}
public static void render(Block block, int meta) {
render(block, meta, null);
}
public static void render(Block block, int meta, VertexTransform xForm) {
IIcon[] icons = new IIcon[6];
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
icons[dir.ordinal()] = block.getIcon(dir.ordinal(), meta);
}
render(BoundingBox.UNIT_CUBE, icons, true);
render(BoundingBox.UNIT_CUBE, icons, xForm, true);
}
public static void render(BoundingBox bb, IIcon tex) {
@@ -206,7 +210,7 @@ public final class CubeRenderer {
float maxV;
IIcon tex;
Tessellator tessellator = Tessellator.instance;
Tessellator tessellator = Tessellator.instance;
tessellator.setNormal(0, 0, -1);
if(brightnessPerSide != null) {