Shield focus rewrite.

This commit is contained in:
fewizz committed 2015-12-13 21:24:42 +03:00
1 parent a499a47d9f
commit e5d1f1637c
52 files changed
+241 -134

No files matched your search

@@ -15,35 +15,22 @@ import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class ModelCpecialArmor extends ModelBiped {
public ModelRenderer bipedHead;
public ModelRenderer bipedBody;
public ModelRenderer bipedRightArm;
public ModelRenderer bipedLeftArm;
public ModelRenderer rightWing;
public ModelRenderer leftWing;
public ModelRenderer center;
public ModelRenderer jetpack;
public boolean isJumping;
public int type = 0;// 0 - nothing, 1 - jetpack, 2 - wings
public int heldItemLeft;
public int heldItemRight;
public boolean isSneak;
public boolean aimedBow;
public ModelCpecialArmor() {
this(0.0F, 0);
this(1, 0);
}
public ModelCpecialArmor(float p_i1148_1_, int type) {
this(p_i1148_1_, 0.0F, 64, 32, type);
public ModelCpecialArmor(float scale, int type) {
this(scale, 0.0F, 64, 32, type);
}
public ModelCpecialArmor(float p_i1149_1_, float p_i1149_2_, int p_i1149_3_, int p_i1149_4_, int type) {
this.type = type;
switch (this.type) {
case 1:
@@ -13,54 +13,45 @@ public class RenderLaser extends Render {
private static final ResourceLocation laserTexture = new ResourceLocation(ModInformation.texturePath, "textures/models/lasermodel.png");
public void renderArrow(EntityLaser entityLaser, double par2, double par4, double par6, float par8, float par9) {
public void doRender(Entity entityLaser, double x, double y, double z, float par8, float par9) {
this.bindEntityTexture(entityLaser);
GL11.glPushMatrix();
GL11.glTranslatef((float) par2, (float) par4, (float) par6);
GL11.glRotatef(entityLaser.prevRotationYaw + (entityLaser.rotationYaw - entityLaser.prevRotationYaw) * par9 - 90.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(entityLaser.prevRotationPitch + (entityLaser.rotationPitch - entityLaser.prevRotationPitch) * par9, 0.0F, 0.0F, 1.0F);
GL11.glTranslated(x, y, z);
GL11.glRotatef(entityLaser.prevRotationYaw + (entityLaser.rotationYaw - entityLaser.prevRotationYaw) * par9 - 90, 0, 1, 0);
GL11.glRotatef(entityLaser.prevRotationPitch + (entityLaser.rotationPitch - entityLaser.prevRotationPitch) * par9, 0, 0, 1);
Tessellator tessellator = Tessellator.instance;
byte b0 = 0;
float f2 = 0.4F;
float f3 = 0.7F;
float f4 = (float) (0 + b0 * 10) / 32.0F;
float f5 = (float) (5 + b0 * 10) / 32.0F;
float f6 = 0.0F;
float f7 = 0.15625F;
float f8 = (float) (5 + b0 * 10) / 32.0F;
float f9 = (float) (10 + b0 * 10) / 32.0F;
float f2 = 0.4f;
float f3 = 0.7f;
float f4 = (float) (0 + b0 * 10) / 32f;
float f5 = (float) (5 + b0 * 10) / 32f;
float f10 = 0.05625F;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glRotatef(45.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45, 1, 0, 0);
GL11.glScalef(f10, f10, f10);
GL11.glTranslatef(-4.0F, 0.0F, 0.0F);
GL11.glNormal3f(f10, 0.0F, 0.0F);
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double) f6, (double) f8);
tessellator.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double) f7, (double) f8);
tessellator.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double) f7, (double) f9);
tessellator.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double) f6, (double) f9);
tessellator.draw();
GL11.glNormal3f(-f10, 0.0F, 0.0F);
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(-7.0D, 2.0D, -2.0D, (double) f6, (double) f8);
tessellator.addVertexWithUV(-7.0D, 2.0D, 2.0D, (double) f7, (double) f8);
tessellator.addVertexWithUV(-7.0D, -2.0D, 2.0D, (double) f7, (double) f9);
tessellator.addVertexWithUV(-7.0D, -2.0D, -2.0D, (double) f6, (double) f9);
tessellator.draw();
GL11.glTranslatef(-4, 0, 0);
GL11.glPushAttrib(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHTING);
for (int i = 0; i < 4; ++i) {
GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
GL11.glNormal3f(0.0F, 0.0F, f10);
GL11.glRotatef(90, 1, 0, 0);
GL11.glNormal3f(0, 0, f10);
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(-8.0D, -2.0D, 0.0D, (double) f2, (double) f4);
tessellator.addVertexWithUV(8.0D, -2.0D, 0.0D, (double) f3, (double) f4);
tessellator.addVertexWithUV(8.0D, 2.0D, 0.0D, (double) f3, (double) f5);
tessellator.addVertexWithUV(-8.0D, 2.0D, 0.0D, (double) f2, (double) f5);
tessellator.addVertexWithUV(-8, 0, 0, f2, f4);
tessellator.addVertexWithUV(8, 0, 0, f3, f4);
tessellator.addVertexWithUV(8, 4, 0, f3, f5);
tessellator.addVertexWithUV(-8, 4, 0, f2, f5);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(8, 0, 0, f2, f4);
tessellator.addVertexWithUV(-8, 0, 0, f3, f4);
tessellator.addVertexWithUV(-8, 4, 0, f3, f5);
tessellator.addVertexWithUV(8, 4, 0, f2, f5);
tessellator.draw();
}
GL11.glPopAttrib();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
@@ -73,8 +64,4 @@ public class RenderLaser extends Render {
protected ResourceLocation getEntityTexture(Entity par1Entity) {
return this.getArrowTextures((EntityLaser) par1Entity);
}
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
this.renderArrow((EntityLaser) par1Entity, par2, par4, par6, par8, par9);
}
}
@@ -0,0 +1,61 @@
package tombenpotter.emt.client.renderer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import tombenpotter.emt.ModInformation;
import tombenpotter.emt.common.entities.EntityLaser;
public class RenderShield extends Render {
private static final ResourceLocation shieldTexture = new ResourceLocation(ModInformation.texturePath, "textures/models/shield.png");
public void doRender(Entity entityLaser, double x, double y, double z, float par8, float par9) {
this.bindEntityTexture(entityLaser);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
Tessellator tessellator = Tessellator.instance;
GL11.glEnable(GL11.GL_BLEND);
GL11.glPushAttrib(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
for (float h = 0; h < 360; h += 15) {
for (float angle = 0; angle < 360; angle += 15) {
float sin1 = (float) Math.sin(Math.toRadians(angle));
float sin2 = (float) Math.sin(Math.toRadians(angle + 15));
float cos1 = (float) Math.cos(Math.toRadians(angle));
float cos2 = (float) Math.cos(Math.toRadians(angle + 15));
float hsin1 = (float) Math.sin(Math.toRadians(h));
float hsin2 = (float) Math.sin(Math.toRadians(h + 15));
float hcos1 = (float) Math.cos(Math.toRadians(h));
float hcos2 = (float) Math.cos(Math.toRadians(h + 15));
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(sin1 * 2 * hcos1, 2 * hsin1, cos1 * 2 * hcos1, 1, 1);
tessellator.addVertexWithUV(sin1 * 2 * hcos2, 2 * hsin2, cos1 * 2 * hcos2, 1, 0);
tessellator.addVertexWithUV(sin2 * 2 * hcos2, 2 * hsin2, cos2 * 2 * hcos2, 0, 0);
tessellator.addVertexWithUV(sin2 * 2 * hcos1, 2 * hsin1, cos2 * 2 * hcos1, 0, 1);
tessellator.draw();
}
}
GL11.glPopAttrib();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
@Override
protected ResourceLocation getEntityTexture(Entity texture) {
return shieldTexture;
}
}
@@ -0,0 +1,122 @@
package tombenpotter.emt.common.entities;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.core.IC2;
import net.minecraft.client.Minecraft;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class EntityShield extends Entity implements IProjectile {
EntityPlayer owner;
public EntityShield(World world) {
super(world);
this.setSize(4, 4);
this.ignoreFrustumCheck = true;
owner = Minecraft.getMinecraft().thePlayer;
this.setPosition(owner.posX, owner.posY, owner.posZ);
}
public EntityShield(World world, EntityPlayer player) {
super(world);
this.setSize(4, 4);
owner = player;
this.setPosition(player.posX, player.posY, player.posZ);
this.ignoreFrustumCheck = true;
}
@Override
protected void entityInit() {
this.dataWatcher.addObject(16, Byte.valueOf((byte) 0));
}
@SideOnly(Side.CLIENT)
public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9) {
this.setPosition(par1, par3, par5);
this.setRotation(par7, par8);
}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
}
public AxisAlignedBB getBoundingBox() {
return this.boundingBox;
}
@Override
public boolean canBePushed() {
return true;
}
public void setPosition(double x, double y, double z) {
this.posX = x;
this.posY = y + 0.5f;
this.posZ = z;
float f = this.width / 2.0F;
float f1 = this.height;
this.boundingBox.setBounds(x - (double) f, y - (double) this.yOffset - 2 + (double) this.ySize, z - (double) f, x + (double) f, y - (double) this.yOffset - 2 + (double) this.ySize + (double) f1, z + (double) f);
}
public void onUpdate() {
super.onUpdate();
if (!owner.worldObj.isRemote) {
this.setPosition(owner.posX, owner.posY, owner.posZ);
if (!owner.isUsingItem()) {
this.setDead();
}
}
}
public void applyEntityCollision(Entity entity) {
if (entity.riddenByEntity != this && entity.ridingEntity != this) {
double ePosX = entity.posX - this.posX;
double ePosZ = entity.posZ - this.posZ;
double d2 = MathHelper.abs_max(ePosX, ePosZ);
d2 = (double) MathHelper.sqrt_double(d2);
ePosX /= d2;
ePosZ /= d2;
double d3 = 1.0D / d2;
if (d3 > 1.0D) {
d3 = 1.0D;
}
ePosX *= d3;
ePosZ *= d3;
ePosX *= 0.05000000074505806D;
ePosZ *= 0.05000000074505806D;
ePosX *= (double) (1.0F - this.entityCollisionReduction);
ePosZ *= (double) (1.0F - this.entityCollisionReduction);
this.addVelocity(-ePosX * 1000, 0.0D, -ePosZ * 1000);
entity.addVelocity(ePosX * 1000, 0.0D, ePosZ * 1000);
}
}
@SideOnly(Side.CLIENT)
@Override
public boolean isInRangeToRender3d(double x, double y, double z) {
return true;
}
@Override
public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_, float p_70186_8_) {
}
}
@@ -7,6 +7,7 @@ import net.minecraft.entity.EntityLiving;
import tombenpotter.emt.ElectroMagicTools;
import tombenpotter.emt.common.entities.EntityArcher;
import tombenpotter.emt.common.entities.EntityLaser;
import tombenpotter.emt.common.entities.EntityShield;
public class EntityRegistry {
@@ -22,7 +23,6 @@ public class EntityRegistry {
return startEID;
}
@SuppressWarnings("unchecked")
public static void registerEntityEgg(Class<? extends Entity> entity, int colPrim, int colSec) {
int id = getUniqueEntityID();
EntityList.IDtoClassMapping.put(id, entity);
@@ -34,6 +34,7 @@ public class EntityRegistry {
cpw.mods.fml.common.registry.EntityRegistry.registerModEntity(EntityLaser.class, "laser", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
cpw.mods.fml.common.registry.EntityRegistry.registerModEntity(EntityArcher.class, "archer", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
cpw.mods.fml.common.registry.EntityRegistry.registerModEntity(EntityShield.class, "shield", entityIDs++, ElectroMagicTools.instance, 80, 3, true);
registerEntityEgg(EntityArcher.class, 0x99111F, 0xE5685);
}
}
@@ -130,9 +130,8 @@ public class ItemMaterials extends Item {
list.add(new ItemStack(this, 1, i));
}
}
public void onUsingTick(ItemStack stack, EntityPlayer player, int count)
{
public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
if (stack != null && stack.getItemDamage() == 6 && this.getMaxItemUseDuration(stack) - count >= 40) {
World world = player.worldObj;
player.swingItem();
@@ -171,7 +170,7 @@ public class ItemMaterials extends Item {
}
player.stopUsingItem();
}
}
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (stack.getItemDamage() == 6) {
@@ -1,8 +1,13 @@
package tombenpotter.emt.common.items.foci;
import java.util.ArrayList;
import java.util.LinkedList;
import ic2.core.IC2;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
@@ -11,13 +16,11 @@ import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.items.wands.ItemWandCasting;
import tombenpotter.emt.ElectroMagicTools;
import tombenpotter.emt.common.entities.EntityShield;
import tombenpotter.emt.common.init.BlockRegistry;
public class ItemShieldFocus extends ItemBaseFocus {
int y1 = 0;
ItemStack milk;
private static final AspectList visCost = new AspectList().add(Aspect.ORDER, 10).add(Aspect.WATER, 10).add(Aspect.AIR, 10);
private static final AspectList visCost = new AspectList().add(Aspect.ORDER, 5).add(Aspect.WATER, 5).add(Aspect.AIR, 5);
public ItemShieldFocus() {
super(".focus.shield", "focus_shield");
@@ -46,80 +49,24 @@ public class ItemShieldFocus extends ItemBaseFocus {
@Override
public void onUsingFocusTick(ItemStack itemstack, EntityPlayer player, int count) {
ItemWandCasting wand = (ItemWandCasting) itemstack.getItem();
if (player.capabilities.isCreativeMode || wand.consumeAllVis(itemstack, player, getVisCost(itemstack), true, true)) {
player.motionX = 0.0D;
if (!player.capabilities.isCreativeMode && player.motionY < 0)
player.motionY = player.motionY / 2;
player.motionZ = 0.0D;
int x = MathHelper.floor_double(player.posX);
int y = MathHelper.floor_double(player.posY);
int z = MathHelper.floor_double(player.posZ);
if (milk == null)
milk = (new ItemStack(Items.milk_bucket));
player.curePotionEffects(milk);
if (player.motionY > -5) {
// Player Level
if (player.worldObj.isAirBlock(x + 1, y, z) && player.worldObj.isAirBlock(x - 1, y, z) && player.worldObj.isAirBlock(x, y, z + 1) && player.worldObj.isAirBlock(x, y, z - 1)) {
player.worldObj.setBlock(x + 1, y, z, BlockRegistry.shield);
player.worldObj.setBlock(x - 1, y, z, BlockRegistry.shield);
player.worldObj.setBlock(x, y, z + 1, BlockRegistry.shield);
player.worldObj.setBlock(x, y, z - 1, BlockRegistry.shield);
}
// Above the player
if (player.worldObj.isAirBlock(x + 1, y + 1, z) && player.worldObj.isAirBlock(x - 1, y + 1, z) && player.worldObj.isAirBlock(x, y + 1, z + 1) && player.worldObj.isAirBlock(x, y + 1, z - 1)) {
player.worldObj.setBlock(x + 1, y + 1, z, BlockRegistry.shield);
player.worldObj.setBlock(x - 1, y + 1, z, BlockRegistry.shield);
player.worldObj.setBlock(x, y + 1, z + 1, BlockRegistry.shield);
player.worldObj.setBlock(x, y + 1, z - 1, BlockRegistry.shield);
}
if (y > y1 && (player.worldObj.isAirBlock(x + 1, y - 2, z) && player.worldObj.isAirBlock(x - 1, y - 2, z) && player.worldObj.isAirBlock(x, y - 2, z + 1) && player.worldObj.isAirBlock(x, y - 2, z - 1))
|| (player.worldObj.getBlock(x + 1, y - 2, z) == BlockRegistry.shield && player.worldObj.getBlock(x - 1, y - 2, z) == BlockRegistry.shield && player.worldObj.getBlock(x, y - 2, z + 1) == BlockRegistry.shield && player.worldObj.getBlock(x, y - 2, z - 1) == BlockRegistry.shield)) {
player.worldObj.setBlockToAir(x + 1, y - 2, z);
player.worldObj.setBlockToAir(x - 1, y - 2, z);
player.worldObj.setBlockToAir(x, y - 2, z + 1);
player.worldObj.setBlockToAir(x, y - 2, z - 1);
}
if (y < y1 && (player.worldObj.isAirBlock(x + 1, y + 2, z) && player.worldObj.isAirBlock(x - 1, y + 2, z) && player.worldObj.isAirBlock(x, y + 2, z + 1) && player.worldObj.isAirBlock(x, y + 2, z - 1))
|| (player.worldObj.getBlock(x + 1, y + 2, z) == BlockRegistry.shield && player.worldObj.getBlock(x - 1, y + 2, z) == BlockRegistry.shield && player.worldObj.getBlock(x, y + 2, z + 1) == BlockRegistry.shield && player.worldObj.getBlock(x, y + 2, z - 1) == BlockRegistry.shield)) {
player.worldObj.setBlockToAir(x + 1, y + 2, z);
player.worldObj.setBlockToAir(x - 1, y + 2, z);
player.worldObj.setBlockToAir(x, y + 2, z + 1);
player.worldObj.setBlockToAir(x, y + 2, z - 1);
}
}
y1 = y;
for (PotionEffect effect : new LinkedList<PotionEffect>(player.getActivePotionEffects())) {
IC2.platform.removePotion(player, effect.getPotionID());
}
if (player.capabilities.isCreativeMode)
return;
if (!wand.consumeAllVis(itemstack, player, getVisCost(itemstack), true, true)) {
player.stopUsingItem();
}
}
@Override
public void onPlayerStoppedUsingFocus(ItemStack itemstack, World world, EntityPlayer player, int count) {
int x = MathHelper.floor_double(player.posX);
int y = MathHelper.floor_double(player.posY);
int z = MathHelper.floor_double(player.posZ);
// Player Level
if ((player.worldObj.getBlock(x + 1, y, z) == BlockRegistry.shield) && (player.worldObj.getBlock(x - 1, y, z) == BlockRegistry.shield) && (player.worldObj.getBlock(x, y, z + 1) == BlockRegistry.shield) && (player.worldObj.getBlock(x, y, z - 1) == BlockRegistry.shield)) {
player.worldObj.setBlockToAir(x + 1, y, z);
player.worldObj.setBlockToAir(x - 1, y, z);
player.worldObj.setBlockToAir(x, y, z + 1);
player.worldObj.setBlockToAir(x, y, z - 1);
}
// Above the player
if ((player.worldObj.getBlock(x + 1, y + 1, z) == BlockRegistry.shield) && (player.worldObj.getBlock(x - 1, y + 1, z) == BlockRegistry.shield) && (player.worldObj.getBlock(x, y + 1, z + 1) == BlockRegistry.shield) && (player.worldObj.getBlock(x, y + 1, z - 1) == BlockRegistry.shield)) {
player.worldObj.setBlockToAir(x + 1, y + 1, z);
player.worldObj.setBlockToAir(x - 1, y + 1, z);
player.worldObj.setBlockToAir(x, y + 1, z + 1);
player.worldObj.setBlockToAir(x, y + 1, z - 1);
public ItemStack onFocusRightClick(ItemStack itemstack, World world, EntityPlayer player, MovingObjectPosition paramMovingObjectPosition) {
ItemWandCasting wand = (ItemWandCasting) itemstack.getItem();
player.setItemInUse(itemstack, Integer.MAX_VALUE);
if (!world.isRemote && (player.capabilities.isCreativeMode || wand.consumeAllVis(itemstack, player, getVisCost(itemstack), true, true))) {
EntityShield shield = new EntityShield(world, player);
world.spawnEntityInWorld(shield);
}
return itemstack;
}
}
@@ -8,8 +8,10 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import tombenpotter.emt.client.EMTKeys;
import tombenpotter.emt.client.renderer.RenderLaser;
import tombenpotter.emt.client.renderer.RenderShield;
import tombenpotter.emt.common.entities.EntityArcher;
import tombenpotter.emt.common.entities.EntityLaser;
import tombenpotter.emt.common.entities.EntityShield;
public class ClientProxy extends CommonProxy {
@@ -22,5 +24,6 @@ public class ClientProxy extends CommonProxy {
public void registerRenders() {
RenderingRegistry.registerEntityRenderingHandler(EntityLaser.class, new RenderLaser());
RenderingRegistry.registerEntityRenderingHandler(EntityArcher.class, new RenderSnowMan());
RenderingRegistry.registerEntityRenderingHandler(EntityShield.class, new RenderShield());
}
}