Forge Logic double check

This commit is contained in:
kitsushadow
2015-07-03 05:54:36 -04:00
parent c12d4574a2
commit 54aee93dc9
10 changed files with 90 additions and 41 deletions

View File

@@ -42,8 +42,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class Forge extends BlockContainer implements TileForgePlaceables{ public class Forge extends BlockContainer implements TileForgePlaceables{
private final Random random = new Random(); private final Random random = new Random();
private int sideMeta; public static int sideMeta;
public static int c; private int c;
public Forge(String unlocalizedName, Material material) { public Forge(String unlocalizedName, Material material) {
super(material.rock); super(material.rock);
@@ -74,12 +74,33 @@ public class Forge extends BlockContainer implements TileForgePlaceables{
super.randomDisplayTick(world, x, y, z, random); super.randomDisplayTick(world, x, y, z, random);
} }
public static int determineOrientation(World p_150071_0_, int p_150071_1_, int p_150071_2_, int p_150071_3_, EntityLivingBase p_150071_4_)
{
if (MathHelper.abs((float)p_150071_4_.posX - (float)p_150071_1_) < 2.0F && MathHelper.abs((float)p_150071_4_.posZ - (float)p_150071_3_) < 2.0F)
{
double d0 = p_150071_4_.posY + 1.82D - (double)p_150071_4_.yOffset;
if (d0 - (double)p_150071_2_ > 2.0D)
{
return 1;
}
if ((double)p_150071_2_ - d0 > 0.0D)
{
return 0;
}
}
int l = MathHelper.floor_double((double)(p_150071_4_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
}
@Override @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack p_149689_6_) { public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack p_149689_6_) {
if(!world.isRemote){ int l = determineOrientation(world, x, y, z, player);
world.setBlockMetadataWithNotify(x, y, z, (MathHelper.floor_double((player.rotationYaw * 4F) / 360F + 0.5D) & 3), 2); world.setBlockMetadataWithNotify(x, y, z, l, 2);
System.out.println(world.getBlockMetadata(x, y, z)); System.out.println(world.getBlockMetadata(x, y, z));
}
world.markBlockForUpdate(x, y, z); world.markBlockForUpdate(x, y, z);
} }
@@ -98,35 +119,22 @@ public class Forge extends BlockContainer implements TileForgePlaceables{
if(world.isRemote){ if(world.isRemote){
MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(5, 1.0F); MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(5, 1.0F);
c = (int)mop.sideHit; c = (int)mop.sideHit;
Main.sNet.sendToServer(new MsgPacketForge((int) c)); Main.sNet.sendToServer(new MsgPacketForge((int) c));
System.out.println("Client");
System.out.println(c);
System.out.println(world.getBlockMetadata(x, y, z));
} }
if(!world.isRemote){ if(!world.isRemote){
System.out.println("Server");
System.out.println(c);
System.out.println(world.getBlockMetadata(x, y, z));
if(player.inventory.getCurrentItem()!=null){ if(player.inventory.getCurrentItem()!=null){
if((player.inventory.getCurrentItem().getItem()==Item.getItemFromBlock(Blocks.torch))|| if((player.inventory.getCurrentItem().getItem()==Item.getItemFromBlock(Blocks.torch))||
(player.inventory.getCurrentItem().getItem()==Items.flint_and_steel)|| (player.inventory.getCurrentItem().getItem()==Items.flint_and_steel)||
(player.inventory.getCurrentItem().getItem()==ModItems.fireBow) (player.inventory.getCurrentItem().getItem()==ModItems.fireBow)
){ ){
tileEnt.isOn=true; tileEnt.isOn=true;
System.out.println(tileEnt.isOn);
} }
} }
if(c==1){ if(sideMeta==1){
if(player.inventory.getCurrentItem()!=null){ if(player.inventory.getCurrentItem()!=null){
if(player.inventory.getCurrentItem().getItem()==Items.coal){ if(player.inventory.getCurrentItem().getItem()==Items.coal){
if(tileEnt.getStackInSlot(1)==null){
if(player.inventory.getCurrentItem()!=null){
tileEnt.setInventorySlotContents(1, player.inventory.getCurrentItem());
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
if(tileEnt.getStackInSlot(1)!=null){ if(tileEnt.getStackInSlot(1)!=null){
ItemStack pStack = player.inventory.getCurrentItem().copy(); ItemStack pStack = player.inventory.getCurrentItem().copy();
ItemStack sStack = tileEnt.getStackInSlot(1).copy(); ItemStack sStack = tileEnt.getStackInSlot(1).copy();
@@ -139,6 +147,10 @@ public class Forge extends BlockContainer implements TileForgePlaceables{
} }
} }
} }
if(tileEnt.getStackInSlot(1)==null){
tileEnt.setInventorySlotContents(1, player.inventory.getCurrentItem());
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
} }
return true; return true;
} }
@@ -161,7 +173,7 @@ public class Forge extends BlockContainer implements TileForgePlaceables{
return true; return true;
} }
} }
if(c!=0 && c!=1){ if(sideMeta == world.getBlockMetadata(x, y, z)){
if(player.inventory.getCurrentItem()!=null){ if(player.inventory.getCurrentItem()!=null){
if(tileEnt.getStackInSlot(0)==null){ if(tileEnt.getStackInSlot(0)==null){
System.out.println(); System.out.println();

View File

@@ -12,7 +12,7 @@ public class MsgHandleForge implements IMessageHandler<MsgPacketForge, IMessage>
@Override @Override
public IMessage onMessage(MsgPacketForge message, MessageContext ctx) { public IMessage onMessage(MsgPacketForge message, MessageContext ctx) {
Forge.c = message.caseType; Forge.sideMeta = message.caseType;
return null; return null;
} }
} }

View File

@@ -26,10 +26,8 @@ import cpw.mods.fml.client.FMLClientHandler;
public class ForgeRenderer extends TileEntitySpecialRenderer { public class ForgeRenderer extends TileEntitySpecialRenderer {
private final Random rand = new Random();
private double r = rand.nextDouble();
EntityItem entItem = null; EntityItem entItem = null;
EntityItem entCoal = null; EntityItem entItem1 = null;
public static final ResourceLocation MODEL = new ResourceLocation("kitsumedievalcraft:models/SingleForge.obj"); public static final ResourceLocation MODEL = new ResourceLocation("kitsumedievalcraft:models/SingleForge.obj");
public static final ResourceLocation TEXTURE = new ResourceLocation("kitsumedievalcraft:models/SingleForge.png"); public static final ResourceLocation TEXTURE = new ResourceLocation("kitsumedievalcraft:models/SingleForge.png");
@@ -44,6 +42,31 @@ public class ForgeRenderer extends TileEntitySpecialRenderer {
renderBlock(tileEntity, tile.getWorldObj(), tile.xCoord,tile.yCoord, tile.zCoord, ModBlocks.forge); renderBlock(tileEntity, tile.getWorldObj(), tile.xCoord,tile.yCoord, tile.zCoord, ModBlocks.forge);
if(tileEntity.getStackInSlot(1) != null){
entItem1 = new EntityItem(tileEntity.getWorldObj(), x, y, z, tileEntity.getStackInSlot(1));
GL11.glPushMatrix();
this.entItem1.hoverStart = 0.0F;
RenderItem.renderInFrame = true;
GL11.glScalef(0.5f, 0.1f, 0.5f);
GL11.glRotatef(90, 1, 0, 0);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 1.0D, 0.8D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 1.25D, 1.0D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 1.25D, 0.5D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 0.7D, 0.6D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 0.7D, 1.0D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 1.5D, 0.75D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 1.0D, 1.2D, -10.0D, 0.0F, 0.0F);
RenderManager.instance.renderEntityWithPosYaw(entItem1, 0.98D, 0.35D, -10.0D, 0.0F, 0.0F);
//RenderManager.instance.renderEntityWithPosYaw(entItem1, 0.5D, 0.7D, -10.0D, 0.0F, 0.0F);
RenderItem.renderInFrame = false;
GL11.glPopMatrix();
tileEntity.markForUpdate();
tileEntity.markDirty();
}
if(tileEntity.getStackInSlot(0) != null){ if(tileEntity.getStackInSlot(0) != null){
entItem = new EntityItem(tileEntity.getWorldObj(), x, y, z, tileEntity.getStackInSlot(0)); entItem = new EntityItem(tileEntity.getWorldObj(), x, y, z, tileEntity.getStackInSlot(0));
GL11.glPushMatrix(); GL11.glPushMatrix();
@@ -54,10 +77,13 @@ public class ForgeRenderer extends TileEntitySpecialRenderer {
RenderManager.instance.renderEntityWithPosYaw(entItem, 0.55D, 0.25D, 0.5D, 0.0F, 0.0F); RenderManager.instance.renderEntityWithPosYaw(entItem, 0.55D, 0.25D, 0.5D, 0.0F, 0.0F);
RenderItem.renderInFrame = false; RenderItem.renderInFrame = false;
GL11.glPopMatrix(); GL11.glPopMatrix();
tileEntity.markForUpdate();
tileEntity.markDirty();
} }
tileEntity.markForUpdate();
tileEntity.markDirty(); //tileEntity.markForUpdate();
//tileEntity.markDirty();
GL11.glPopMatrix(); GL11.glPopMatrix();
@@ -69,16 +95,17 @@ public class ForgeRenderer extends TileEntitySpecialRenderer {
GL11.glScalef(scale, scale, scale); GL11.glScalef(scale, scale, scale);
GL11.glTranslatef(1.0F, 1.0F, 1.0F); GL11.glTranslatef(1.0F, 1.0F, 1.0F);
int dir = world.getBlockMetadata(i, j, k); int dir = world.getBlockMetadata(i, j, k);
if(dir == 0){ //System.out.println(dir);
GL11.glRotated(90F, 0.0, 1.0F, 0.0F); if(dir == 4){
GL11.glRotated(-180F, 0.0, 1.0F, 0.0F);
} }
if(dir == 1){ if(dir == 5){
} }
if(dir == 2){ if(dir == 2){
GL11.glRotated(-90F, 0.0, 1.0F, 0.0F); GL11.glRotated(90F, 0.0, 1.0F, 0.0F);
} }
if(dir == 3){ if(dir == 3){
GL11.glRotated(180F, 0.0, 1.0F, 0.0F); GL11.glRotated(-90F, 0.0, 1.0F, 0.0F);
} }
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE); FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);

View File

@@ -49,7 +49,7 @@ public class TileIngotBase extends TileEntity {
private void coolDown(World world, int x, int y, int z){ private void coolDown(World world, int x, int y, int z){
if(!world.isRemote){ if(!world.isRemote){
if((world.getBlock(x, y-1, z)!=ModBlocks.firebox)&&(this.hot==true)){ if((world.getBlock(x, y-1, z)!=ModBlocks.forge)&&(this.hot==true)){
coolTicks--; coolTicks--;
if(coolTicks <= 0){ if(coolTicks <= 0){
this.hot=false; this.hot=false;

View File

@@ -1,7 +1,6 @@
package com.kitsu.medievalcraft.tileents.machine; package com.kitsu.medievalcraft.tileents.machine;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -12,7 +11,8 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.kitsu.medievalcraft.block.ModBlocks; import com.kitsu.medievalcraft.block.ingots.IngotBase;
import com.kitsu.medievalcraft.tileents.ingots.TileIngotBase;
public class TileForge extends TileEntity implements IInventory{ public class TileForge extends TileEntity implements IInventory{
private String tileForgeName; private String tileForgeName;
@@ -193,10 +193,7 @@ public class TileForge extends TileEntity implements IInventory{
int x = this.xCoord; int x = this.xCoord;
int y = this.yCoord; int y = this.yCoord;
int z = this.zCoord; int z = this.zCoord;
if(!world.isRemote){ heatIngot(world, x, y, z);
if(!world.isRemote){
}
/*if(world.getBlock(x, y+1, z).equals(Blocks.air)||this.getStackInSlot(0)==null){ /*if(world.getBlock(x, y+1, z).equals(Blocks.air)||this.getStackInSlot(0)==null){
this.isOn = false; this.isOn = false;
} }
@@ -215,9 +212,22 @@ public class TileForge extends TileEntity implements IInventory{
//isFurnace(world, x, y, z); //isFurnace(world, x, y, z);
//isCrucible(world, x, y, z); //isCrucible(world, x, y, z);
//isIngot(world, x, y, z); //isIngot(world, x, y, z);
}
if (worldObj.isRemote) return; if (worldObj.isRemote) return;
} }
private void heatIngot(World world, int x, int y, int z){
if(!world.isRemote){
if(world.getBlock(x, y+1, z) instanceof IngotBase){
TileIngotBase tile = (TileIngotBase) world.getTileEntity(x, y+1, z);
if(tile.hot==false){
tile.heatTicks--;
System.out.println(tile.hot);
System.out.println(tile.heatTicks);
}
}
}
}
} }