Power Variable
This commit is contained in:
@@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import nmd.primal.energy.block.lathe.LatheBase;
|
||||
import nmd.primal.energy.common.ModInfo;
|
||||
@@ -15,6 +16,7 @@ import nmd.primal.energy.render.RenderID;
|
||||
import nmd.primal.energy.tileents.TileEntCrank;
|
||||
import nmd.primal.energy.tileents.TileEntLatheBase;
|
||||
import nmd.primal.energy.util.CustomTab;
|
||||
import nmd.primal.energy.util.EnergyUtil;
|
||||
|
||||
public class CrankBlock extends Block implements ITileEntityProvider{
|
||||
|
||||
@@ -26,8 +28,6 @@ public class CrankBlock extends Block implements ITileEntityProvider{
|
||||
this.setHardness(1.0F);
|
||||
this.setResistance(6.0F);
|
||||
this.setStepSound(soundTypeStone);
|
||||
this.setBlockBounds(0.1F, 0.0F, 0.1F,
|
||||
0.9F, 0.75F, 0.9F);
|
||||
}
|
||||
|
||||
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) {
|
||||
@@ -42,6 +42,7 @@ public class CrankBlock extends Block implements ITileEntityProvider{
|
||||
if(world.getBlock(x, y, z+1) instanceof LatheBase){
|
||||
TileEntLatheBase tileLathe = (TileEntLatheBase) world.getTileEntity(x, y, z+1);
|
||||
tileLathe.isPowered=true;
|
||||
tileLathe.power+=100;
|
||||
tileLathe.markDirty();
|
||||
tileLathe.markForUpdate();
|
||||
}
|
||||
@@ -61,32 +62,35 @@ public class CrankBlock extends Block implements ITileEntityProvider{
|
||||
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack)
|
||||
{
|
||||
int l = determineOrientation(world, x, y, z, player);
|
||||
//if(!world.isRemote){
|
||||
int l = EnergyUtil.determineOrientationComplex(world, x, y, z, player);
|
||||
System.out.println(l);
|
||||
world.setBlockMetadataWithNotify(x, y, z, l, 2);
|
||||
//}
|
||||
}
|
||||
|
||||
public static int determineOrientation(World world, int x, int y, int z, EntityLivingBase player) {
|
||||
if (MathHelper.abs((float)player.posX - (float)x) < 2.0F && MathHelper.abs((float)player.posZ - (float)z) < 2.0F)
|
||||
{
|
||||
double d0 = player.posY + 1.82D - (double)player.yOffset;
|
||||
|
||||
if (d0 - (double)y > 2.0D)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((double)y - d0 > 0.0D)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z){
|
||||
int p = access.getBlockMetadata(x, y, z);
|
||||
if(p==0){
|
||||
this.setBlockBounds(0.2F, 0.5F, 0.2F, 0.8F, 1.0F, 0.8F);
|
||||
}
|
||||
|
||||
int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
|
||||
if(p==1){
|
||||
this.setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 0.5F, 0.8F);
|
||||
}
|
||||
if(p==2){
|
||||
this.setBlockBounds(0.2F, 0.2F, 0.5F, 0.8F, 0.8F, 1.0F);
|
||||
}
|
||||
if(p==3){
|
||||
this.setBlockBounds(0.2F, 0.2F, 0.0F, 0.8F, 0.8F, 0.5F);
|
||||
}
|
||||
if(p==4){
|
||||
this.setBlockBounds(0.5F, 0.2F, 0.2F, 1.0F, 0.8F, 0.8F);
|
||||
}
|
||||
if(p==5){
|
||||
this.setBlockBounds(0.0F, 0.2F, 0.2F, 0.5F, 0.8F, 0.8F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return RenderID.crankID;
|
||||
|
||||
@@ -6,18 +6,22 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import nmd.primal.energy.common.ModInfo;
|
||||
import nmd.primal.energy.item.ModItems;
|
||||
import nmd.primal.energy.render.RenderID;
|
||||
import nmd.primal.energy.tileents.TileEntLatheBase;
|
||||
import nmd.primal.energy.util.CustomTab;
|
||||
import nmd.primal.energy.util.EnergyUtil;
|
||||
import nmd.primal.energy.util.LatheRecipes;
|
||||
|
||||
public abstract class LatheBase extends BlockContainer implements ITileEntityProvider{
|
||||
@@ -32,8 +36,8 @@ public abstract class LatheBase extends BlockContainer implements ITileEntityPro
|
||||
this.setHardness(1.0F);
|
||||
this.setResistance(6.0F);
|
||||
this.setStepSound(soundTypeStone);
|
||||
this.setBlockBounds(0.1F, 0.0F, 0.1F,
|
||||
0.9F, 0.75F, 0.9F);
|
||||
//this.setBlockBounds(0.1F, 0.0F, 0.1F,
|
||||
// 0.9F, 0.75F, 0.9F);
|
||||
}
|
||||
|
||||
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) {
|
||||
@@ -156,6 +160,25 @@ public abstract class LatheBase extends BlockContainer implements ITileEntityPro
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack p_149689_6_) {
|
||||
int l = EnergyUtil.determineOrientationSimple(player);
|
||||
world.setBlockMetadataWithNotify(x, y, z, l, 2);
|
||||
System.out.println(l);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z)
|
||||
{
|
||||
int orient = access.getBlockMetadata(x, y, z);
|
||||
if(orient==1 || orient == 3){
|
||||
this.setBlockBounds(0.2F, 0F, 0F, 0.8F, 0.61F, 1.0F);
|
||||
}
|
||||
if(orient==0 || orient == 2){
|
||||
this.setBlockBounds(0.0F, 0F, 0.2F, 1.0F, 0.61F, 0.8F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return RenderID.latheID;
|
||||
|
||||
@@ -21,8 +21,6 @@ import nmd.primal.energy.tileents.TileEntLatheBase;
|
||||
|
||||
public class RenderLathe extends TileEntitySpecialRenderer {
|
||||
|
||||
public int i = 0;
|
||||
public int a = 0;
|
||||
public static final ResourceLocation MODEL = new ResourceLocation("energy:models/Lathe.obj");
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation("energy:models/FlintLathe.png");
|
||||
private IModelCustom model = AdvancedModelLoader.loadModel(MODEL);
|
||||
@@ -51,7 +49,9 @@ public class RenderLathe extends TileEntitySpecialRenderer {
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
|
||||
if(tile.getBlockMetadata()==0||tile.getBlockMetadata()==2){
|
||||
GL11.glRotatef(90, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
if(tile.getStackInSlot(0) != null){
|
||||
entItem = new EntityItem(tile.getWorldObj(), x, y, z, tile.getStackInSlot(0));
|
||||
@@ -68,23 +68,16 @@ public class RenderLathe extends TileEntitySpecialRenderer {
|
||||
if(tile.isPowered == true){
|
||||
if(tile.getStackInSlot(0).getItem().equals(Item.getItemFromBlock(Blocks.wooden_slab))
|
||||
||tile.getStackInSlot(0).getItem().equals(ModItems.saxleItem)){
|
||||
GL11.glRotatef(i, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(tile.rot, 0.0F, 1.0F, 0.0F);
|
||||
}else{
|
||||
GL11.glRotatef(i, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glRotatef(tile.rot, 0.0F, 0.0F, 1.0F);
|
||||
}
|
||||
|
||||
RenderManager.instance.renderEntityWithPosYaw(entItem, 0.0D, -0.223D, 0.0D, 0.0F, 0.0F);
|
||||
a++;
|
||||
if(a==1){
|
||||
i=i-14;
|
||||
a=0;
|
||||
}
|
||||
if(i>=360||i<=-360){
|
||||
i=0;
|
||||
}
|
||||
|
||||
}
|
||||
if(tile.isPowered==false){
|
||||
RenderManager.instance.renderEntityWithPosYaw(entItem, 0.0D, -0.15D, 0.0D, 0.0F, 0.0F);
|
||||
RenderManager.instance.renderEntityWithPosYaw(entItem, 0.0D, -0.223D, 0.0D, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
RenderItem.renderInFrame = false;
|
||||
|
||||
@@ -22,8 +22,9 @@ public class TileEntLatheBase extends TileEntity implements IInventory {
|
||||
private ItemStack[] inv;
|
||||
private int i;
|
||||
public boolean isPowered = true;
|
||||
public int workCount;
|
||||
public int power, workCount;
|
||||
protected String specName = "TileEntLatheBase";
|
||||
public float rot = 0;
|
||||
|
||||
public TileEntLatheBase() {
|
||||
this.inv = new ItemStack[1];
|
||||
@@ -62,14 +63,21 @@ public class TileEntLatheBase extends TileEntity implements IInventory {
|
||||
int x = this.xCoord;
|
||||
int y = this.yCoord;
|
||||
int z = this.zCoord;
|
||||
if(this.isPowered==true){
|
||||
i++;
|
||||
if(i>16){
|
||||
//this.isPowered=false;
|
||||
i=0;
|
||||
//latheWork();
|
||||
if(!world.isRemote){
|
||||
if(this.isPowered==true){
|
||||
this.power--;
|
||||
rot-=45;
|
||||
System.out.println(rot);
|
||||
if(rot>=360||rot<=-360){
|
||||
rot=0;
|
||||
}
|
||||
if(power<=0){
|
||||
this.isPowered=false;
|
||||
this.power=0;
|
||||
}
|
||||
this.markForUpdate();
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
}
|
||||
if (worldObj.isRemote) return;
|
||||
}
|
||||
@@ -165,7 +173,6 @@ public class TileEntLatheBase extends TileEntity implements IInventory {
|
||||
* */
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -186,7 +193,9 @@ public class TileEntLatheBase extends TileEntity implements IInventory {
|
||||
this.specName = tagCompound.getString("CustomName");
|
||||
}
|
||||
this.isPowered = tagCompound.getBoolean("ISPOWERED");
|
||||
this.power = tagCompound.getInteger("POWER");
|
||||
this.workCount = tagCompound.getInteger("WORKCOUNT");
|
||||
this.rot = tagCompound.getFloat("ROT");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +213,9 @@ public class TileEntLatheBase extends TileEntity implements IInventory {
|
||||
}
|
||||
tagCompound.setTag("Inventory", itemList);
|
||||
tagCompound.setBoolean("ISPOWERED", this.isPowered);
|
||||
tagCompound.setInteger("POWER", this.power);
|
||||
tagCompound.setInteger("WORKCOUNT", this.workCount);
|
||||
tagCompound.setFloat("ROT", this.rot);
|
||||
}
|
||||
|
||||
|
||||
|
||||
26
src/main/java/nmd/primal/energy/util/EnergyUtil.java
Normal file
26
src/main/java/nmd/primal/energy/util/EnergyUtil.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package nmd.primal.energy.util;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EnergyUtil {
|
||||
|
||||
public static int determineOrientationComplex(World world, int x, int y, int z, EntityLivingBase player)
|
||||
{
|
||||
if (MathHelper.abs((float)player.posX - (float)x) < 2.0F && MathHelper.abs((float)player.posZ - (float)z) < 2.0F)
|
||||
{
|
||||
double d0 = player.posY + 1.82D - (double)player.yOffset;
|
||||
if (d0 - (double)y > 2.0D){return 1;}
|
||||
if ((double)y - d0 > 0.0D) {return 0;}
|
||||
}
|
||||
|
||||
int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
|
||||
}
|
||||
|
||||
public static int determineOrientationSimple(EntityLivingBase player){
|
||||
int l = (MathHelper.floor_double((player.rotationYaw * 4F) / 360F + 0.5D) & 3);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user