Grinder now works with mechanical network

This commit is contained in:
Calclavia 2014-01-19 13:49:42 +08:00
parent b4606b23da
commit e7e19b6afd
7 changed files with 5893 additions and 47 deletions

View file

@ -1,8 +1,13 @@
package resonantinduction.core;
import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import resonantinduction.core.render.RIBlockRenderingHandler;
import universalelectricity.api.vector.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
@ -51,4 +56,12 @@ public class ClientProxy extends CommonProxy
{
return FMLClientHandler.instance().getClient().gameSettings.fancyGraphics;
}
@Override
public void renderBlockParticle(World world, Vector3 position, Vector3 velocity, int blockID, float scale)
{
EntityFX fx = new EntityDiggingFX(world, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z, Block.blocksList[blockID], 0, 0);
fx.multipleParticleScaleBy(scale);
FMLClientHandler.instance().getClient().effectRenderer.addEffect(fx);
}
}

View file

@ -3,7 +3,9 @@
*/
package resonantinduction.core;
import net.minecraft.world.World;
import resonantinduction.core.prefab.ProxyBase;
import universalelectricity.api.vector.Vector3;
/**
* @author Calclavia
@ -21,4 +23,9 @@ public class CommonProxy extends ProxyBase
return false;
}
public void renderBlockParticle(World world, Vector3 position, Vector3 velocity, int blockID, float scale)
{
}
}

View file

@ -105,11 +105,15 @@ public class BlockGrinderWheel extends BlockRIRotatable implements ITileEntityPr
entity.attackEntityFrom(DamageSource.cactus, 2);
}
}
if (tile.getNetwork().getAngularVelocity() > 0)
{
// Move entity based on the direction of the block.
ForgeDirection dir = this.getDirection(world, x, y, z);
entity.motionX += dir.offsetX * 0.1;
entity.motionZ += dir.offsetZ * 0.1;
entity.motionY += 0.1;
entity.motionX += dir.offsetX * tile.getNetwork().getAngularVelocity() / 20;
entity.motionZ += dir.offsetZ * tile.getNetwork().getAngularVelocity() / 20;
entity.motionY += Math.random() * tile.getNetwork().getAngularVelocity() / 20;
entity.isAirBorne = true;
}
}

View file

@ -2,6 +2,7 @@ package resonantinduction.mechanical.process;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@ -9,9 +10,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.obj.WavefrontObject;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
@ -30,12 +28,16 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
glPushMatrix();
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
glTranslatef(0, 0, 0.5f);
glScalef(0.5f, 0.5f, 0.5f);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
MODEL.renderOnly("Default");
glPopMatrix();
if (t instanceof TileGrinderWheel)
{
TileGrinderWheel tile = (TileGrinderWheel) t;
glPushMatrix();
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
glScalef(0.5f, 0.5f, 0.52f);
glRotatef((float) Math.toDegrees(tile.getNetwork().getRotation()), 0, 0, 1);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
MODEL.renderAll();
glPopMatrix();
}
}
}

View file

@ -3,14 +3,15 @@ package resonantinduction.mechanical.process;
import java.util.HashMap;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.ItemStackResource;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.network.TileMechanical;
import universalelectricity.api.energy.EnergyStorageHandler;
import universalelectricity.api.vector.Vector3;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
@ -29,6 +30,9 @@ public class TileGrinderWheel extends TileMechanical
public EntityItem grindingItem = null;
private final long requiredTorque = 10000;
private long counter = 0;
@Override
public void updateEntity()
{
@ -43,58 +47,71 @@ public class TileGrinderWheel extends TileMechanical
*/
public boolean canWork()
{
return true;
return (counter = Math.max(counter + getNetwork().getTorque(), 0)) > requiredTorque;
}
public void doWork()
{
boolean didWork = false;
if (grindingItem != null)
if (canWork())
{
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(grindingItem) < 1)
{
int timeLeft = getTimer().get(grindingItem) - 1;
getTimer().put(grindingItem, timeLeft);
boolean didWork = false;
if (timeLeft <= 0)
if (grindingItem != null)
{
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(grindingItem) < 1)
{
if (this.doGrind(grindingItem))
int timeLeft = getTimer().get(grindingItem) - 1;
getTimer().put(grindingItem, timeLeft);
if (timeLeft <= 0)
{
if (--grindingItem.getEntityItem().stackSize <= 0)
if (this.doGrind(grindingItem))
{
grindingItem.setDead();
getTimer().remove(grindingItem);
grindingItem = null;
if (--grindingItem.getEntityItem().stackSize <= 0)
{
grindingItem.setDead();
getTimer().remove(grindingItem);
grindingItem = null;
}
else
{
grindingItem.setEntityItemStack(grindingItem.getEntityItem());
// Reset timer
getTimer().put(grindingItem, DEFAULT_TIME);
}
}
}
else
{
grindingItem.delayBeforeCanPickup = 20;
if (grindingItem.getEntityItem().getItem() instanceof ItemBlock)
{
ResonantInduction.proxy.renderBlockParticle(worldObj, new Vector3(grindingItem), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), ((ItemBlock) grindingItem.getEntityItem().getItem()).getBlockID(), 1);
}
else
{
grindingItem.setEntityItemStack(grindingItem.getEntityItem());
// Reset timer
getTimer().put(grindingItem, DEFAULT_TIME);
this.worldObj.spawnParticle("crit", grindingItem.posX, grindingItem.posY, grindingItem.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3);
}
}
didWork = true;
}
else
{
grindingItem.delayBeforeCanPickup = 20;
this.worldObj.spawnParticle("crit", grindingItem.posX, grindingItem.posY, grindingItem.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3);
getTimer().remove(grindingItem);
grindingItem = null;
}
}
if (didWork)
{
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "grinder", 0.5f, 1);
}
didWork = true;
}
else
{
getTimer().remove(grindingItem);
grindingItem = null;
}
}
if (didWork)
{
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "grinder", 0.5f, 1);
counter -= requiredTorque;
}
}
}

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 752 B