Add Force Engine prototype

This commit is contained in:
Timo Ley 2021-04-17 16:07:41 +02:00
parent ee66d45a36
commit 42def51478
36 changed files with 2725 additions and 4 deletions

View file

@ -0,0 +1,40 @@
/**
* Copyright (c) 2011-2017, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.tools;
import net.minecraft.entity.player.EntityPlayer;
/***
* Implement this interface on subclasses of Item to have that item work as a wrench for buildcraft
*/
public interface IToolWrench {
/***
* Called to ensure that the wrench can be used. To get the ItemStack that is used, check player.inventory.getCurrentItem()
*
* @param player
* - The player doing the wrenching
* @param x
* ,y,z - The coordinates for the block being wrenched
*
* @return true if wrenching is allowed, false if not
*/
boolean canWrench(EntityPlayer player, int x, int y, int z);
/***
* Callback after the wrench has been used. This can be used to decrease durability or for other purposes. To get the ItemStack that was used, check
* player.inventory.getCurrentItem()
*
* @param player
* - The player doing the wrenching
* @param x
* ,y,z - The coordinates of the block being wrenched
*/
void wrenchUsed(EntityPlayer player, int x, int y, int z);
}

View file

@ -0,0 +1,8 @@
package cofh.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
public interface IEnergyConnection {
boolean canConnectEnergy(ForgeDirection var1);
}

View file

@ -0,0 +1,12 @@
package cofh.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
public interface IEnergyProvider extends IEnergyConnection {
int extractEnergy(ForgeDirection var1, int var2, boolean var3);
int getEnergyStored(ForgeDirection var1);
int getMaxEnergyStored(ForgeDirection var1);
}

View file

@ -0,0 +1,12 @@
package cofh.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
public interface IEnergyReceiver extends IEnergyConnection {
int receiveEnergy(ForgeDirection var1, int var2, boolean var3);
int getEnergyStored(ForgeDirection var1);
int getMaxEnergyStored(ForgeDirection var1);
}

View file

@ -0,0 +1,13 @@
package cofh.api.energy;
public interface IEnergyStorage {
int receiveEnergy(int var1, boolean var2);
int extractEnergy(int var1, boolean var2);
int getEnergyStored();
int getMaxEnergyStored();
}

View file

@ -1,5 +1,11 @@
package ley.modding.dartcraft;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
public class Config {
public static boolean hardHeat;
@ -14,8 +20,70 @@ public class Config {
public static int damageLevel;
public static int sturdyLevel;
public static float gemValue;
public static float gemValue = 0.25F;
public static int powerOreRenderID;
public static File engineFile;
private static void generateDefaultEngineFile() {
try {
FileWriter e = new FileWriter(engineFile);
BufferedWriter buffer = new BufferedWriter(e);
buffer.write("#Place the Forge Liquid name (all lowercase) you wish to add as a fuel or\n");
buffer.write("#throttle under the appropriate category using the below syntax.\n");
buffer.write("#The first number is the burn value and the second is burn time.\n");
buffer.write("#Liquid Force must be added as a fuel or defaults will be asserted.\n");
Iterator i$ = getDefaultFuels().iterator();
while(i$.hasNext()) {
String name = (String)i$.next();
buffer.write(name);
buffer.write(10);
}
buffer.close();
} catch (Exception var4) {
var4.printStackTrace();
}
}
private static ArrayList getDefaultFuels() {
ArrayList<String> defaults = new ArrayList<String>();
//defaults.add("#Fuels.");
defaults.add("f:liquidforce=4.0;20000");
defaults.add("f:lava=0.5;20000");
defaults.add("f:oil=1.5;20000");
defaults.add("f:fuel=3.0;100000");
defaults.add("f:bioethanol=2.0;60000");
//defaults.add("\n#Throttles.");
defaults.add("t:water=2.0;600");
defaults.add("t:milk=2.5;3000");
defaults.add("t:ice=4.0;20000");
defaults.add("t:honey=3.0;10000");
return defaults;
}
public static ArrayList getFuels() {
/* ArrayList<String> fuels = new ArrayList<String>();
try {
BufferedReader e = new BufferedReader(new FileReader(engineFile));
String line = null;
while((line = e.readLine()) != null) {
if(!line.startsWith("#") && !line.startsWith("\n")) {
fuels.add("" + line);
}
}
} catch (Exception var3) {
var3.printStackTrace();
}
return fuels;*/
return getDefaultFuels();
}
}

View file

@ -17,6 +17,8 @@ import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.network.PacketClipButton;
import ley.modding.dartcraft.proxy.CommonProxy;
import ley.modding.dartcraft.tab.DartcraftTab;
import ley.modding.dartcraft.util.ForceEngineLiquids;
import ley.modding.dartcraft.util.FortunesUtil;
import ley.modding.tileralib.api.IRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.MinecraftForge;
@ -42,6 +44,7 @@ public class Dartcraft {
MinecraftForge.EVENT_BUS.register(new EventHandler());
channel = NetworkRegistry.INSTANCE.newSimpleChannel("Dartcraft");
channel.registerMessage(PacketClipButton.Handler.class, PacketClipButton.class, 0, Side.SERVER);
FortunesUtil.load();
}
@Mod.EventHandler
@ -62,7 +65,7 @@ public class Dartcraft {
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent e) {
ForceEngineLiquids.load();
}
}

View file

@ -0,0 +1,44 @@
package ley.modding.dartcraft.api.energy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
public class EngineLiquid {
public static final int TYPE_FUEL = 0;
public static final int TYPE_THROTTLE = 1;
protected int id;
protected int burnTime;
protected int type;
protected NBTTagCompound comp;
protected float modifier = 1.0F;
public EngineLiquid(FluidStack liquid, int type, int burnTime, float modifier) {
this.id = liquid.getFluidID();
this.comp = liquid.tag;
this.type = type;
this.burnTime = burnTime;
this.modifier = modifier;
}
public int getType() {
return this.type;
}
public int getBurnTime() {
return this.burnTime;
}
public float getModifier() {
return this.modifier;
}
public FluidStack getLiquid() {
return new FluidStack(this.id, 1000);
}
}

View file

@ -0,0 +1,134 @@
package ley.modding.dartcraft.block;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.util.DartUtils;
import ley.modding.tileralib.api.ITEProvider;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
public class BlockForceEngine extends BlockContainer implements ITEProvider {
public BlockForceEngine() {
super(Material.iron);
setHardness(3.0F);
setResistance(50.0F);
setCreativeTab(Dartcraft.tab);
setBlockName("forceengine");
}
public TileEntity createNewTileEntity(World world, int var2) {
return new TileEntityForceEngine();
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
if(!Dartcraft.proxy.isSimulating(world)) {
return true;
} else {
TileEntity tile = world.getTileEntity(x, y, z);
TileEntityForceEngine engine = null;
if(tile instanceof TileEntityForceEngine) {
engine = (TileEntityForceEngine)tile;
}
if(engine != null) {
if(DartUtils.isHoldingWrench(player)) {
engine.rotateBlock();
return true;
}
if(player.getCurrentEquippedItem() != null && FluidContainerRegistry.getFluidForFilledItem(player.getCurrentEquippedItem()) != null) {
return DartUtils.fillTankWithContainer(engine, player);
}
if(!player.isSneaking() && !DartUtils.isHoldingWrench(player)) {
player.openGui(Dartcraft.instance, 7, world, x, y, z);
}
}
return true;
}
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) {
TileEntityForceEngine tile = (TileEntityForceEngine)world.getTileEntity(x, y, z);
if(tile != null) {
tile.setFacing(ForgeDirection.UP);
tile.rotateBlock();
}
}
public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
return te instanceof TileEntityForceEngine?((TileEntityForceEngine)te).getLightValue():0;
}
public int getRenderType() {
return -1;
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
if(Dartcraft.proxy.isSimulating(world)) {
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityForceEngine) {
TileEntityForceEngine engine = (TileEntityForceEngine)tile;
for(int i = 0; i < engine.liquidInventory.getSizeInventory(); ++i) {
ItemStack tempStack = engine.liquidInventory.getStackInSlot(i);
if(tempStack != null) {
DartUtils.dropItem(tempStack, world, x, y, z);
}
}
}
super.breakBlock(world, x, y, z, par5, par6);
}
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TileEntityForceEngine ?((TileEntityForceEngine)tile).facing.getOpposite() == side:false;
}
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer renderer) {
//FXUtils.makeShiny(world, (double)x, (double)y, (double)z, 2, 16776960, 16, true);
return true;
}
@SideOnly(Side.CLIENT)
public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer renderer) {
if(world != null && target != null) { //TODO FX
//FXUtils.makeShiny(world, (double)target.blockX, (double)target.blockY, (double)target.blockZ, 2, 16776960, 3, true);
}
return true;
}
@Override
public Class<? extends TileEntity> getTEClass() {
return TileEntityForceEngine.class;
}
}

View file

@ -0,0 +1,121 @@
package ley.modding.dartcraft.block;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.entity.EntityColdChicken;
import ley.modding.dartcraft.entity.EntityColdCow;
import ley.modding.dartcraft.entity.EntityColdPig;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
public class BlockLiquidForce extends BlockFluidClassic {
public IIcon still;
public IIcon flowing;
public IIcon milk;
public BlockLiquidForce() {
super(FluidRegistry.getFluid("liquidforce"), Material.water);
Fluid liquidForce = FluidRegistry.getFluid("liquidforce");
if (liquidForce != null)
liquidForce.setBlock(DartBlocks.liquidforce);
setResistance(2000.0F);
setBlockName("liquidforce");
}
public int getLightValue(IBlockAccess world, int x, int y, int z) {
return 15;
}
public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec) {
if (entity == null)
return;
try {
double modifier = 0.85D;
entity.motionX *= modifier;
entity.motionY *= modifier;
entity.motionZ *= modifier;
} catch (Exception e) {}
}
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
try {
if (entity instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase)entity;
if (living.isEntityUndead() || living instanceof net.minecraft.entity.monster.EntityBlaze) {
living.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 1, 9, false));
/*if (Config.baneForce) {
living.attackEntityFrom((DamageSource) PunishDamage.instance, 2.0F);
} else {*/
living.attackEntityFrom(DamageSource.magic, 2.0F);
//}
} else {
if (living.getAir() < 255)
living.setAir(living.getAir() + 1);
living.heal(0.005F);
living.removePotionEffect(Potion.invisibility.getId());
living.removePotionEffect(Potion.wither.getId());
}
if (Dartcraft.proxy.isSimulating(world)) {
float chance = 0.9925F;
if (living instanceof EntityColdCow && living.getRNG().nextFloat() > chance) {
EntityColdCow cow = (EntityColdCow)living;
//cow.shouldRevert = true;
}
if (living instanceof EntityColdChicken && living.getRNG().nextFloat() > chance) {
EntityColdChicken chicken = (EntityColdChicken)living;
//chicken.shouldRevert = true;
}
if (living instanceof EntityColdPig && living.getRNG().nextFloat() > chance) {
EntityColdPig pig = (EntityColdPig)living;
//pig.shouldRevert = true;
}
if (living instanceof EntitySheep && living.getRNG().nextFloat() > chance) {
EntitySheep sheep = (EntitySheep)living;
sheep.eatGrassBonus();
}
if (living instanceof EntityAgeable && !(living instanceof net.minecraft.entity.passive.EntityHorse)) {
EntityAgeable animal = (EntityAgeable)living;
if (animal.getGrowingAge() < 0)
animal.setGrowingAge((animal.getGrowingAge() < -20) ? (animal.getGrowingAge() + 20) : 0);
}
}
}
} catch (Exception e) {}
}
public Fluid getFluid() {
return FluidRegistry.getFluid("liquidforce");
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reggie) {
still = reggie.registerIcon("dartcraft:liquidForceStill");
flowing = reggie.registerIcon("dartcraft:liquidForceMoving");
Fluid liquidForce = FluidRegistry.getFluid("liquidforce");
if (liquidForce != null)
liquidForce.setIcons(still, flowing);
blockIcon = still;
milk = reggie.registerIcon("dartcraft:milk");
Fluid fmilk = FluidRegistry.getFluid("milk");
if (fmilk != null && milk != null) {
fmilk.setIcons(milk, milk);
}
}
}

View file

@ -2,17 +2,28 @@ package ley.modding.dartcraft.block;
import ley.modding.tileralib.api.IRegistry;
import net.minecraft.block.Block;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
public class DartBlocks {
public static Block powerore;
public static Block forcesapling;
public static Block forcelog;
public static Block forceleaves;
public static Block engine;
public static Block liquidforce;
public static void register(IRegistry reg) {
FluidRegistry.registerFluid(new FluidLiquidForce());
if (!FluidRegistry.isFluidRegistered("milk")) {
Fluid milk = new Fluid("milk");
FluidRegistry.registerFluid(milk);
}
DartBlocks.liquidforce = reg.registerBlock(new BlockLiquidForce());
DartBlocks.forcesapling = reg.registerBlock(new BlockForceSapling());
DartBlocks.powerore = reg.registerBlock(new BlockPowerOre());
DartBlocks.forcelog = reg.registerBlock(new BlockForceLog());
DartBlocks.forceleaves = reg.registerBlock(new BlockForceLeaves());
DartBlocks.engine = reg.registerBlock(new BlockForceEngine());
}
}

View file

@ -0,0 +1,16 @@
package ley.modding.dartcraft.block;
import net.minecraftforge.fluids.Fluid;
public class FluidLiquidForce extends Fluid {
public FluidLiquidForce() {
super("liquidForce");
this.luminosity = 15;
this.viscosity = 6000;
this.density = 200;
}
public String getLocalizedName() {
return "Liquid Force";
}
}

View file

@ -0,0 +1,103 @@
package ley.modding.dartcraft.client.gui;
import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.util.ForceEngineLiquids;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
public class ContainerForceEngine extends Container {
public TileEntityForceEngine engine;
public IInventory playerInv;
public EntityPlayer user;
public ContainerForceEngine(EntityPlayer player, TileEntityForceEngine engine) {
this.user = player;
this.engine = engine;
this.playerInv = (IInventory)player.inventory;
addSlotToContainer(new FuelSlot((IInventory)engine.liquidInventory, 0, 38, 33));
addSlotToContainer(new ThrottleSlot((IInventory)engine.liquidInventory, 1, 122, 33));
int i;
for (i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++)
addSlotToContainer(new Slot(this.playerInv, i * 9 + j + 9, 8 + 18 * j, 79 + 18 * i));
}
for (i = 0; i < 9; i++)
addSlotToContainer(new Slot(this.playerInv, i, 8 + 18 * i, 137));
}
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++)
this.engine.sendGuiNetworkData(this, (ICrafting) crafters.get(i));
}
public void updateProgressBar(int i, int j) {
this.engine.receiveGuiNetworkData(i, j);
}
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack returnStack = null;
Slot slot = (Slot) inventorySlots.get(index);
if (slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
returnStack = stack.copy();
if (index >= 0 && index < 2)
if (!mergeItemStack(stack, 2, 38, true))
return null;
if (index >= 2)
if (ForceEngineLiquids.isFuel(FluidContainerRegistry.getFluidForFilledItem(stack)) || stack.getItem() == DartItems.forcegem) {
if (!mergeItemStack(stack, 0, 1, false))
return null;
} else if (ForceEngineLiquids.isThrottle(FluidContainerRegistry.getFluidForFilledItem(stack)) &&
!mergeItemStack(stack, 1, 2, false)) {
return null;
}
if (stack.stackSize == 0) {
slot.putStack((ItemStack)null);
} else {
slot.onSlotChanged();
}
if (stack.stackSize == returnStack.stackSize)
return null;
slot.onPickupFromSlot(player, stack);
}
return returnStack;
}
protected void retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {}
public boolean canInteractWith(EntityPlayer player) {
return true;
}
private class FuelSlot extends Slot {
public FuelSlot(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
}
public boolean isItemValid(ItemStack stack) {
if (stack.getItem() == DartItems.forcegem)
return true;
return ForceEngineLiquids.isFuel(FluidContainerRegistry.getFluidForFilledItem(stack));
}
}
private class ThrottleSlot extends Slot {
public ThrottleSlot(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
}
public boolean isItemValid(ItemStack stack) {
return ForceEngineLiquids.isThrottle(FluidContainerRegistry.getFluidForFilledItem(stack));
}
}
}

View file

@ -0,0 +1,222 @@
package ley.modding.dartcraft.client.gui;
import cpw.mods.fml.common.Loader;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.api.energy.EngineLiquid;
import ley.modding.dartcraft.client.gui.tabs.GuiTab;
import ley.modding.dartcraft.client.gui.tabs.Tab;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.util.ForceEngineLiquids;
import ley.modding.dartcraft.util.FortunesUtil;
import net.minecraft.client.gui.Gui;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class GuiEngine extends GuiTab {
private TileEntityForceEngine engine;
private ContainerForceEngine container;
private Rectangle fuelBounds;
private Rectangle throttleBounds;
private Rectangle energyBounds;
private Rectangle throttleMeterBounds;
public GuiEngine(ContainerForceEngine container) {
super(container);
this.engine = container.engine;
this.container = container;
this.xSize = 176;
this.ySize = 161;
addTab(new EnergyTab(this));
addTab(new InfoTab(this));
}
public void initGui() {
super.initGui();
this.fuelBounds = new Rectangle(this.guiLeft + 66, this.guiTop + 11, 16, 58);
this.throttleBounds = new Rectangle(this.guiLeft + 94, this.guiTop + 11, 16, 58);
}
public List<String> handleItemTooltip(ItemStack stack, int x, int y, List<String> tooltip) {
Point pointerLoc = new Point(x, y);
if (this.fuelBounds.contains(pointerLoc))
try {
tooltip.add("" + this.engine.fuelTank.getFluid().getFluid().getLocalizedName() + " (" + (this.engine.fuelTank.getFluid()).amount + ")");
} catch (Exception e) {
tooltip.add("Empty");
}
if (this.throttleBounds.contains(pointerLoc))
try {
tooltip.add("" + (this.engine.throttleTank.getInfo()).fluid.getFluid().getName() + " (" + (this.engine.throttleTank.getFluid()).amount + ")");
} catch (Exception e) {
tooltip.add("Empty");
}
return tooltip;
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Dartcraft.proxy.bindTexture("engineGui.png");
int posX = (this.width - this.xSize) / 2;
int posY = (this.height - this.ySize) / 2;
drawTexturedModalRect(posX, posY, 0, 0, this.xSize, this.ySize);
if (this.engine.fuelTank.getFluid() != null && (this.engine.fuelTank.getFluid()).amount > 0)
displayGauge(this.fuelBounds.x, this.fuelBounds.y, this.engine.fuelTank.getFluid());
if (this.engine.throttleTank.getFluid() != null && (this.engine.throttleTank.getFluid()).amount > 0)
displayGauge(this.throttleBounds.x, this.throttleBounds.y, this.engine.throttleTank.getFluid());
}
private void displayGauge(int x, int y, FluidStack liquid) {
int tempx;
if (liquid == null)
return;
int start = 0;
int squaled = (int)(58.0F * liquid.amount / 10000.0F);
Dartcraft.proxy.bindTexture("textures/atlas/blocks.png");
do {
tempx = 0;
if (squaled > 16) {
tempx = 16;
squaled -= 16;
} else {
tempx = squaled;
squaled = 0;
}
IIcon icon = liquid.getFluid().getStillIcon();
if (icon == null)
icon = FluidRegistry.LAVA.getStillIcon();
drawTexturedModelRectFromIcon(x, y + 58 - tempx - start, icon, 16, 16 - 16 - tempx);
start += 16;
} while (tempx != 0 && squaled != 0);
Dartcraft.proxy.bindTexture("engineGui.png");
drawTexturedModalRect(x, y, 176, 0, 16, 58);
}
protected void drawTooltips() {}
private class EnergyTab extends Tab {
public EnergyTab(Gui gui) {
super(gui);
this.leftSide = false;
this.overlayColor = 13914449;
this.maxHeight = 48;
this.maxWidth = 90;
}
public void draw(int x, int y) {
drawBackground(x, y);
drawIcon("items.png", 49, x + 2, y + 2);
if (!isFullyOpened())
return;
float output = GuiEngine.this.engine.getEnergyPerProcess();
float throttle = 0.0F;
if (GuiEngine.this.engine.throttleTank.getFluid() != null) {
EngineLiquid throttleLiquid = ForceEngineLiquids.getEngineLiquid(GuiEngine.this.engine.throttleTank.getFluid());
if (throttleLiquid != null)
throttle = throttleLiquid.getModifier();
}
if (!GuiEngine.this.engine.isActive)
output = throttle = 0.0F;
int subColor = 15000804;
Tab.tabFontRenderer.drawStringWithShadow("Output", x + 22, y + 6, 16777215);
Tab.tabFontRenderer.drawStringWithShadow("MJ/t:", x + 8, y + 20, 16777215);
if (output > 0.0F) {
Tab.tabFontRenderer.drawStringWithShadow("" + GuiEngine.this.engine.getEnergyPerProcess(), x + 36, y + 20, subColor);
} else {
Tab.tabFontRenderer.drawStringWithShadow("None", x + 36, y + 20, subColor);
}
Tab.tabFontRenderer.drawStringWithShadow("Throttle:", x + 8, y + 30, 16777215);
if (throttle > 0.0F) {
Tab.tabFontRenderer.drawStringWithShadow("" + throttle, x + 55, y + 30, subColor);
} else {
Tab.tabFontRenderer.drawStringWithShadow("None", x + 55, y + 30, subColor);
}
}
public String getTooltip() {
return null;
}
}
private class InfoTab extends Tab {
public ArrayList<String> infoStrings = new ArrayList<String>();
private String currentInfo;
private int index;
public InfoTab(Gui gui) {
super(gui);
this.leftSide = false;
this.overlayColor = 1217260;
this.maxHeight = 100;
this.maxWidth = 120;
initializeItems();
this.currentInfo = getRandomItem();
this.index = -1;
}
private void initializeItems() {
this.infoStrings.add("The Force Engine can be throttled with a few liquids, most notably water.");
this.infoStrings.add("The Force Engine's output is determined by the base output of the Fuel multiplied by the Throttle's value.");
this.infoStrings.add("The Force Engine will never explode or die of loneliness.");
this.infoStrings.add("The Force Engine requires a redstone signal to run.");
this.infoStrings.add("You can right-click the Force Engine with a valid liquid container to add liquid quickly.");
if (Loader.isModLoaded("BuildCraft|Energy")) {
this.infoStrings.add("A wide variety of fuels are usable inside the Force Engine. While Liquid Force is the most effective, BuildCraft Fuel or even lava is also usable.");
this.infoStrings.add("Using Fuel or Lava in the Force Engine will yield the same output as the Combustion Engine if water is used as a throttle.");
} else {
this.infoStrings.add("Lava is also a valid Force Engine Fuel, although not as effective as Liquid Force.");
}
if (Loader.isModLoaded("Forestry")) {
this.infoStrings.add("Liquid Force may also be obtained by squeezing Force Logs.");
this.infoStrings.add("Milk is also an effective throttle.");
this.infoStrings.add("Did someone say Glacial bees?");
}
}
public void toggleOpen() {
super.toggleOpen();
if (isOpen()) {
this.index++;
if (this.index > this.infoStrings.size())
this.index = 0;
try {
this.currentInfo = this.infoStrings.get(this.index);
} catch (Exception e) {
this.currentInfo = getRandomItem();
}
}
}
public void draw(int x, int y) {
drawBackground(x, y);
drawIcon("items.png", 0, x + 2, y + 2);
if (!isFullyOpened())
return;
Tab.tabFontRenderer.drawStringWithShadow("Information", x + 22, y + 6, 16777215);
Tab.tabFontRenderer.drawSplitString(this.currentInfo, x + 8, y + 20, this.maxWidth - 14, 0);
}
private String getRandomItem() {
return FortunesUtil.getFortune();
}
public String getTooltip() {
return null;
}
}
}

View file

@ -2,12 +2,14 @@ package ley.modding.dartcraft.client.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import ley.modding.dartcraft.item.ItemClipboard;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.util.EntityUtils;
import ley.modding.dartcraft.util.ItemCraftingInventory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class GuiHandler implements IGuiHandler {
@ -21,6 +23,13 @@ public class GuiHandler implements IGuiHandler {
if (clipStack != null)
return new ContainerClipboard(player, new ItemCraftingInventory(9, clipStack));
break;
case 7:
TileEntity te2 = world.getTileEntity(x, y, z);
if (te2 != null && te2 instanceof TileEntityForceEngine) {
TileEntityForceEngine engine = (TileEntityForceEngine)te2;
return new ContainerForceEngine(player, engine);
}
break;
}
return null;
}
@ -34,6 +43,13 @@ public class GuiHandler implements IGuiHandler {
if (clipStack != null)
return new GuiClipboard(new ContainerClipboard(player, new ItemCraftingInventory(9, clipStack)));
break;
case 7:
TileEntity te2 = world.getTileEntity(x, y, z);
if (te2 instanceof TileEntityForceEngine) {
TileEntityForceEngine engine = (TileEntityForceEngine)te2;
return new GuiEngine(new ContainerForceEngine(player, engine));
}
break;
}
return null;
}

View file

@ -0,0 +1,295 @@
package ley.modding.dartcraft.client.gui.tabs;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
public abstract class GuiTab extends GuiContainer {
protected enum SlotColor {
BLUE, RED, YELLOW, ORANGE, GREEN, PURPLE;
}
protected enum SlotType {
//SINGLE, OUTPUT, DOUBLEOUTPUT;
TOP, BOTTOM, FULL
}
protected enum SlotRender {
TOP, BOTTOM, FULL;
}
protected static int SCALE_ENERGY = 42;
protected static int SCALE_LIQUID = 60;
protected static int SCALE_PROGRESS = 24;
protected static int SCALE_SPEED = 16;
protected ArrayList<Tab> tabListLeft = new ArrayList<Tab>();
protected ArrayList<Tab> tabListRight = new ArrayList<Tab>();
protected int mouseX = 0;
protected int mouseY = 0;
public static boolean enableGuiBorders;
public static boolean enableInfoTabs;
public static boolean enableTutorialTabs;
public GuiTab(Container container) {
super(container);
}
protected void func_74189_g(int i, int j) {
GL11.glDisable(2896);
GL11.glDisable(2929);
drawTabs(this.mouseX, this.mouseY);
drawTooltips();
GL11.glEnable(2896);
GL11.glEnable(2929);
}
protected abstract void drawTooltips();
protected void drawColoredSlot(int x, int y, SlotColor color, SlotType type, SlotRender render) {
if (enableGuiBorders) {
drawColoredSlotWithBorder(x, y, color, type, render);
} else {
drawColoredSlotNoBorder(x, y, color, type, render);
}
}
protected void drawColoredSlotNoBorder(int x, int y, SlotColor color, SlotType type, SlotRender render) {
int sizeX = 0;
int sizeY = 0;
int offsetX = color.ordinal() / 3 * 128;
int offsetY = color.ordinal() % 3 * 32;
switch (type) {
case TOP:
sizeX = 16;
sizeY = 16;
offsetX += 8;
offsetY += 8;
break;
case BOTTOM:
sizeX = 24;
sizeY = 24;
offsetX += 36;
offsetY += 4;
break;
case FULL:
sizeX = 42;
sizeY = 24;
offsetX += 75;
offsetY += 4;
break;
}
switch (render) {
case TOP:
sizeY /= 2;
break;
case BOTTOM:
sizeY /= 2;
y += sizeY;
offsetY += sizeY;
break;
}
drawTexturedModalRect(x, y, offsetX, offsetY, sizeX, sizeY);
}
protected void drawColoredSlotWithBorder(int x, int y, SlotColor color, SlotType type, SlotRender render) {
int sizeX = 32;
int sizeY = 32;
int offsetX = color.ordinal() / 3 * 128;
int offsetY = color.ordinal() % 3 * 32;
offsetX += type.ordinal() * 32;
if (type.ordinal() == 2)
sizeX = 64;
switch (type) {
case TOP:
x -= 8;
y -= 8;
break;
case BOTTOM:
x -= 4;
y -= 4;
break;
case FULL:
x -= 11;
y -= 4;
break;
}
switch (render) {
case TOP:
sizeY /= 2;
break;
case BOTTOM:
sizeY /= 2;
y += sizeY;
offsetY += sizeY;
break;
}
drawTexturedModalRect(x, y, offsetX, offsetY, sizeX, sizeY);
}
protected void drawColoredLiquidSlot(int x, int y, SlotColor color) {
if (enableGuiBorders) {
drawColoredLiquidSlotWithBorder(x, y, color);
} else {
drawColoredLiquidSlotNoBorder(x, y, color);
}
}
protected void drawColoredLiquidSlotNoBorder(int x, int y, SlotColor color) {
int sizeX = 16;
int sizeY = 60;
int offsetX = color.ordinal() * 32;
int offsetY = 96;
drawTexturedModalRect(x, y, offsetX + 8, offsetY + 2, sizeX, sizeY);
}
protected void drawColoredLiquidSlotWithBorder(int x, int y, SlotColor color) {
int sizeX = 32;
int sizeY = 64;
int offsetX = color.ordinal() * 32;
int offsetY = 96;
drawTexturedModalRect(x - 8, y - 2, offsetX, offsetY, sizeX, sizeY);
}
protected void drawLiquid(int j, int k, int liquidId, NBTTagCompound comp, int width, int height) {
int liquidImgIndex = 0;
try {
FluidStack tempStack = new FluidStack(liquidId, 0, comp);
liquidImgIndex = tempStack.getFluid().getSpriteNumber();
} catch (Exception e) {
return;
}
int imgLine = liquidImgIndex / 16;
int imgColumn = liquidImgIndex - imgLine * 16;
int x = 0;
int y = 0;
int drawHeight = 0;
int drawWidth = 0;
for (x = 0; x < width; x += 16) {
for (y = 0; y < height; y += 16) {
drawWidth = Math.min(width - x, 16);
drawHeight = Math.min(height - y, 16);
drawTexturedModalRect(j + x, k + y, imgColumn * 16, imgLine * 16, drawWidth, drawHeight);
}
}
}
protected void drawTooltip(String tooltip) {
drawCreativeTabHoveringText(tooltip, this.mouseX, this.mouseY);
}
protected int getCenteredOffset(String string) {
return getCenteredOffset(string, this.xSize);
}
protected int getCenteredOffset(String string, int xWidth) {
return (xWidth - fontRendererObj.getStringWidth(string)) / 2;
}
protected void mouseClicked(int x, int y, int mouseButton) {
super.mouseClicked(x, y, mouseButton);
Tab tab = getTabAtPosition(this.mouseX, this.mouseY);
if (tab != null && !tab.handleMouseClicked(this.mouseX, this.mouseY, mouseButton)) {
if (tab.leftSide) {
for (Tab other : this.tabListLeft) {
if (other != tab && other.isOpen())
other.toggleOpen();
}
} else {
for (Tab other : this.tabListRight) {
if (other != tab && other.isOpen())
other.toggleOpen();
}
}
tab.toggleOpen();
}
}
public void handleMouseInput() {
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
int y = this.height- Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
this.mouseX = x - (this.width - this.xSize) / 2;
this.mouseY = y - (this.height - this.ySize) / 2;
super.handleMouseInput();
}
public void addTab(Tab tab) {
if (tab.leftSide) {
this.tabListLeft.add(tab);
if (TabVars.getOpenedLeftTab() != null && tab.getClass().equals(TabVars.getOpenedLeftTab()))
tab.setFullyOpen();
} else {
this.tabListRight.add(tab);
if (TabVars.getOpenedRightTab() != null && tab.getClass().equals(TabVars.getOpenedRightTab()))
tab.setFullyOpen();
}
}
protected void drawTabs(int mX, int mY) {
int yPosRight = 4;
int yPosLeft = 4;
for (Tab tab1 : this.tabListLeft) {
tab1.update();
if (!tab1.isVisible())
continue;
tab1.draw(0, yPosLeft);
yPosLeft += tab1.getHeight();
}
for (Tab tab1 : this.tabListRight) {
tab1.update();
if (!tab1.isVisible())
continue;
tab1.draw(this.xSize, yPosRight);
yPosRight += tab1.getHeight();
}
Tab tab = getTabAtPosition(mX, mY);
if (tab != null) {
String tooltip = tab.getTooltip();
if (tooltip != null)
drawTooltip(tooltip);
}
}
protected Tab getTabAtPosition(int mX, int mY) {
int xShift = 0;
int yShift = 4;
int i;
for (i = 0; i < this.tabListLeft.size(); i++) {
Tab tab = this.tabListLeft.get(i);
if (tab.isVisible()) {
tab.currentShiftX = xShift;
tab.currentShiftY = yShift;
if (tab.intersectsWith(mX, mY, xShift, yShift))
return tab;
yShift += tab.getHeight();
}
}
xShift = this.xSize;
yShift = 4;
for (i = 0; i < this.tabListRight.size(); i++) {
Tab tab = this.tabListRight.get(i);
if (tab.isVisible()) {
tab.currentShiftX = xShift;
tab.currentShiftY = yShift;
if (tab.intersectsWith(mX, mY, xShift, yShift))
return tab;
yShift += tab.getHeight();
}
}
return null;
}
}

View file

@ -0,0 +1,151 @@
package ley.modding.dartcraft.client.gui.tabs;
import cpw.mods.fml.client.FMLClientHandler;
import ley.modding.dartcraft.Dartcraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import org.lwjgl.opengl.GL11;
public abstract class Tab {
protected static FontRenderer tabFontRenderer = (FMLClientHandler.instance().getClient()).fontRenderer;
private boolean open;
protected Gui myGui;
public boolean leftSide;
protected int overlayColor = 16777215;
public int currentShiftX = 0;
public int currentShiftY = 0;
protected int limitWidth = 128;
public int maxWidth = 124;
protected int minWidth = 22;
protected int currentWidth = this.minWidth;
public int maxHeight = 22;
protected int minHeight = 22;
protected int currentHeight = this.minHeight;
public Tab(Gui gui) {
this.myGui = gui;
}
public abstract void draw(int paramInt1, int paramInt2);
protected void drawBackground(int x, int y) {
float colorR = (this.overlayColor >> 16 & 0xFF) / 255.0F;
float colorG = (this.overlayColor >> 8 & 0xFF) / 255.0F;
float colorB = (this.overlayColor & 0xFF) / 255.0F;
GL11.glColor4f(colorR, colorG, colorB, 1.0F);
if (this.leftSide) {
Dartcraft.proxy.bindTexture("tab_left.png");
this.myGui.drawTexturedModalRect(x - this.currentWidth, y + 4, 0, 256 - this.currentHeight + 4, 4, this.currentHeight - 4);
this.myGui.drawTexturedModalRect(x - this.currentWidth + 4, y, 256 - this.currentWidth + 4, 0, this.currentWidth - 4, 4);
this.myGui.drawTexturedModalRect(x - this.currentWidth, y, 0, 0, 4, 4);
this.myGui.drawTexturedModalRect(x - this.currentWidth + 4, y + 4, 256 - this.currentWidth + 4, 256 - this.currentHeight + 4, this.currentWidth - 4, this.currentHeight - 4);
} else {
Dartcraft.proxy.bindTexture("tab_right.png");
this.myGui.drawTexturedModalRect(x, y, 0, 256 - this.currentHeight, 4, this.currentHeight);
this.myGui.drawTexturedModalRect(x + 4, y, 256 - this.currentWidth + 4, 0, this.currentWidth - 4, 4);
this.myGui.drawTexturedModalRect(x, y, 0, 0, 4, 4);
this.myGui.drawTexturedModalRect(x + 4, y + 4, 256 - this.currentWidth + 4, 256 - this.currentHeight + 4, this.currentWidth - 4, this.currentHeight - 4);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
protected void drawIcon(String texture, int iconIndex, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Dartcraft.proxy.bindTexture(texture);
int textureRow = iconIndex >> 4;
int textureColumn = iconIndex - 16 * textureRow;
this.myGui.drawTexturedModalRect(x, y, 16 * textureColumn, 16 * textureRow, 16, 16);
}
public int getHeight() {
return this.currentHeight;
}
public abstract String getTooltip();
public boolean handleMouseClicked(int x, int y, int mouseButton) {
return false;
}
public boolean intersectsWith(int mouseX, int mouseY, int shiftX, int shiftY) {
if (this.leftSide) {
if (mouseX <= shiftX && mouseX >= shiftX - this.currentWidth && mouseY >= shiftY && mouseY <= shiftY + this.currentHeight)
return true;
} else if (mouseX >= shiftX && mouseX <= shiftX + this.currentWidth && mouseY >= shiftY && mouseY <= shiftY + this.currentHeight) {
return true;
}
return false;
}
protected boolean isFullyOpened() {
return (this.currentWidth >= this.maxWidth);
}
public boolean isOpen() {
return this.open;
}
public boolean isVisible() {
return true;
}
public void setFullyOpen() {
this.open = true;
this.currentWidth = this.maxWidth;
this.currentHeight = this.maxHeight;
}
public void toggleOpen() {
if (this.open) {
this.open = false;
if (this.leftSide) {
TabVars.setOpenedLeftTab(null);
} else {
TabVars.setOpenedRightTab(null);
}
} else {
this.open = true;
if (this.leftSide) {
TabVars.setOpenedLeftTab(getClass());
} else {
TabVars.setOpenedRightTab(getClass());
}
}
}
public void update() {
if (this.open && this.currentWidth < this.maxWidth) {
this.currentWidth += 8;
} else if (!this.open && this.currentWidth > this.minWidth) {
this.currentWidth -= 8;
}
if (this.currentWidth > this.maxWidth) {
this.currentWidth = this.maxWidth;
} else if (this.currentWidth < this.minWidth) {
this.currentWidth = this.minWidth;
}
if (this.open && this.currentHeight < this.maxHeight) {
this.currentHeight += 8;
} else if (!this.open && this.currentHeight > this.minHeight) {
this.currentHeight -= 8;
}
if (this.currentHeight > this.maxHeight) {
this.currentHeight = this.maxHeight;
} else if (this.currentHeight < this.minHeight) {
this.currentHeight = this.minHeight;
}
}
}

View file

@ -0,0 +1,23 @@
package ley.modding.dartcraft.client.gui.tabs;
public class TabVars {
private static Class openedLeftTab;
private static Class openedRightTab;
public static Class getOpenedLeftTab() {
return openedLeftTab;
}
public static Class getOpenedRightTab() {
return openedRightTab;
}
public static void setOpenedLeftTab(Class tabClass) {
openedLeftTab = tabClass;
}
public static void setOpenedRightTab(Class tabClass) {
openedRightTab = tabClass;
}
}

View file

@ -0,0 +1,34 @@
package ley.modding.dartcraft.client.model;
import net.minecraft.client.renderer.entity.RenderItem;
public class ModelEngine {
public static float[][] angleBaseYNeg = new float[6][3];
public static float[][] angleBaseYPos = new float[6][3];
public static float[][] angleBaseXPos = new float[6][3];
public static final float factor = 0.0625F;
public static final RenderItem itemRenderer = new RenderItem();
static {
float pi = 3.141593F;
angleBaseYNeg[0][2] = pi;
angleBaseYNeg[2][0] = -pi / 2.0F;
angleBaseYNeg[3][0] = pi / 2.0F;
angleBaseYNeg[4][2] = pi / 2.0F;
angleBaseYNeg[5][2] = -pi / 2.0F;
angleBaseYPos[1][2] = pi;
angleBaseYPos[2][0] = pi / 2.0F;
angleBaseYPos[3][0] = -pi / 2.0F;
angleBaseYPos[4][2] = -pi / 2.0F;
angleBaseYPos[5][2] = pi / 2.0F;
angleBaseXPos[0][0] = -pi / 2.0F;
angleBaseXPos[1][0] = pi / 2.0F;
angleBaseXPos[2][1] = pi;
angleBaseXPos[4][1] = -pi / 2.0F;
angleBaseXPos[5][1] = pi / 2.0F;
}
}

View file

@ -0,0 +1,117 @@
package ley.modding.dartcraft.client.renderer.block;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.client.model.ModelEngine;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
public class RenderTileForceEngine extends TileEntitySpecialRenderer {
private static ModelRenderer base;
static ModelBase model = new ModelBase() {
};
static ModelRenderer piston;
static ModelRenderer extension;
static ModelRenderer[] trunk = new ModelRenderer[2];
static double[][] translate = new double[6][3];
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) {
TileEntityForceEngine engine;
if (tile instanceof TileEntityForceEngine) {
engine = (TileEntityForceEngine)tile;
} else {
return;
}
render(engine.isActive, engine.getCycleProgress(), engine.getFacing().ordinal(), x, y, z);
}
public void render(boolean active, float progress, int facing, double x, double y, double z) {
float step;
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
if (progress > 1.0F)
progress = 1.0F;
if (progress > 0.5D) {
step = 8.0F - (progress - 0.5F) * 2.0F * 8.0F;
} else {
step = progress * 16.0F;
}
float translateFactor = step / 16.0F;
base.rotateAngleX = ModelEngine.angleBaseYNeg[facing][0];
base.rotateAngleY = ModelEngine.angleBaseYNeg[facing][1];
base.rotateAngleZ = ModelEngine.angleBaseYNeg[facing][2];
piston.rotateAngleX = ModelEngine.angleBaseYNeg[facing][0];
piston.rotateAngleY = ModelEngine.angleBaseYNeg[facing][1];
piston.rotateAngleZ = ModelEngine.angleBaseYNeg[facing][2];
extension.rotateAngleX = ModelEngine.angleBaseYNeg[facing][0];
extension.rotateAngleY = ModelEngine.angleBaseYNeg[facing][1];
extension.rotateAngleZ = ModelEngine.angleBaseYNeg[facing][2];
Dartcraft.proxy.bindTexture("forceEngine.png");
base.render(0.0625F);
GL11.glPushMatrix();
GL11.glTranslated(translate[facing][0] * translateFactor, translate[facing][1] * translateFactor, translate[facing][2] * translateFactor);
piston.render(0.0625F);
GL11.glPopMatrix();
if (active) {
(trunk[1]).rotateAngleX = ModelEngine.angleBaseYNeg[facing][0];
(trunk[1]).rotateAngleY = ModelEngine.angleBaseYNeg[facing][1];
(trunk[1]).rotateAngleZ = ModelEngine.angleBaseYNeg[facing][2];
trunk[1].render(0.0625F);
} else {
(trunk[0]).rotateAngleX = ModelEngine.angleBaseYNeg[facing][0];
(trunk[0]).rotateAngleY = ModelEngine.angleBaseYNeg[facing][1];
(trunk[0]).rotateAngleZ = ModelEngine.angleBaseYNeg[facing][2];
trunk[0].render(0.0625F);
}
float extensionFactor = 0.125F;
for (int i = 0; i < step + 2.0F; i += 2) {
extension.render(0.0625F);
GL11.glTranslated(translate[facing][0] * extensionFactor, translate[facing][1] * extensionFactor, translate[facing][2] * extensionFactor);
}
GL11.glPopMatrix();
}
static {
translate[0][1] = -1.0D;
translate[1][1] = 1.0D;
translate[2][2] = -1.0D;
translate[3][2] = 1.0D;
translate[4][0] = -1.0D;
translate[5][0] = 1.0D;
base = new ModelRenderer(model, 0, 0);
base.setTextureSize(128, 64);
base.addBox(-8.0F, -8.0F, -8.0F, 16, 4, 16);
base.rotationPointX = 8.0F;
base.rotationPointY = 8.0F;
base.rotationPointZ = 8.0F;
piston = new ModelRenderer(model, 64, 0);
piston.setTextureSize(128, 64);
piston.addBox(-7.0F, -4.0F, -7.0F, 14, 4, 14);
piston.rotationPointX = 8.0F;
piston.rotationPointY = 8.0F;
piston.rotationPointZ = 8.0F;
extension = new ModelRenderer(model, 0, 20);
extension.setTextureSize(128, 64);
extension.addBox(-5.0F, -4.5F, -5.0F, 10, 2, 10);
extension.rotationPointX = 8.0F;
extension.rotationPointY = 8.0F;
extension.rotationPointZ = 8.0F;
for (int i = 0; i < 2; i++) {
trunk[i] = new ModelRenderer(model, 32 * i, 44);
trunk[i].setTextureSize(128, 64);
trunk[i].addBox(-4.0F, -4.0F, -4.0F, 8, 12, 8);
(trunk[i]).rotationPointX = 8.0F;
(trunk[i]).rotationPointY = 8.0F;
(trunk[i]).rotationPointZ = 8.0F;
}
}
}

View file

@ -0,0 +1,23 @@
package ley.modding.dartcraft.client.renderer.item;
import ley.modding.dartcraft.proxy.ClientProxy;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
public class RenderItemEngine implements IItemRenderer {
public boolean handleRenderType(ItemStack item, IItemRenderer.ItemRenderType type) {
return true;
}
public boolean shouldUseRenderHelper(IItemRenderer.ItemRenderType type, ItemStack item, IItemRenderer.ItemRendererHelper helper) {
return true;
}
public void renderItem(IItemRenderer.ItemRenderType type, ItemStack item, Object... data) {
if (type == IItemRenderer.ItemRenderType.EQUIPPED || type == IItemRenderer.ItemRenderType.INVENTORY) {
ClientProxy.engineRender.render(false, 0.25F, 1, 0.0D, 0.0D, 0.0D);
} else {
ClientProxy.engineRender.render(false, 0.25F, 1, -0.5D, -0.5D, -0.5D);
}
}
}

View file

@ -1,25 +1,32 @@
package ley.modding.dartcraft.proxy;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.block.DartBlocks;
import ley.modding.dartcraft.client.renderer.block.PowerOreRenderer;
import ley.modding.dartcraft.client.renderer.block.RenderTileForceEngine;
import ley.modding.dartcraft.client.renderer.entity.RenderColdAnimal;
import ley.modding.dartcraft.client.renderer.entity.RenderEntityBottle;
import ley.modding.dartcraft.client.renderer.item.RenderItemEngine;
import ley.modding.dartcraft.client.renderer.item.RenderItemForceFlask;
import ley.modding.dartcraft.entity.*;
import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.network.DartPacket;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import net.minecraft.client.model.ModelChicken;
import net.minecraft.client.model.ModelCow;
import net.minecraft.client.model.ModelPig;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
public class ClientProxy extends CommonProxy {
public static RenderTileForceEngine engineRender;
public boolean isSimulating(World world) {
return world != null && !world.isRemote;
}
@ -41,11 +48,14 @@ public class ClientProxy extends CommonProxy {
RenderingRegistry.registerEntityRenderingHandler(EntityColdPig.class, new RenderColdAnimal(new ModelPig(), 0.6f, "textures/entity/coldPig.png"));
Config.powerOreRenderID = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new PowerOreRenderer());
engineRender = new RenderTileForceEngine();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityForceEngine.class, engineRender);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(DartBlocks.engine), new RenderItemEngine());
}
public void sendPacketToServer(DartPacket packet) {
try {
Dartcraft.channel.sendToServer((IMessage)packet);
Dartcraft.channel.sendToServer(packet);
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -0,0 +1,532 @@
package ley.modding.dartcraft.tile;
import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.api.energy.EngineLiquid;
import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.util.ForceEngineLiquids;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
public class TileEntityForceEngine extends TileEntity implements IFluidHandler, IInventory, IEnergyProvider { //TODO Fix GUI
public static final int MAX_STORED = 50000;
public static final int MAX_LIQUID = 10000;
public static final int CYCLE_TIME = 20;
public InventoryBasic liquidInventory;
public ItemStack liquidSlot;
public ForgeDirection facing;
public boolean isActive;
public boolean isShutdown;
public boolean canCycle;
public boolean stageCycle;
public float fuelRF;
public float cycleProgress;
public int fuelLossCycle;
public int throttleLossCycle;
public int packetTime;
public FluidTank fuelTank;
public FluidTank throttleTank;
public TileEntityForceEngine() {
this.fuelTank = new FluidTank(10000);
this.throttleTank = new FluidTank(10000);
this.fuelLossCycle = this.throttleLossCycle = 0;
this.liquidInventory = new InventoryBasic("forceEngine.stacks", false, 2);
this.liquidInventory.setInventorySlotContents(0, (ItemStack)null);
this.liquidInventory.setInventorySlotContents(1, (ItemStack)null);
this.facing = ForgeDirection.UP;
}
public ForgeDirection getFacing() {
return this.facing;
}
public float getCycleProgress() {
return this.cycleProgress;
}
public boolean setFacing(ForgeDirection dir) {
this.facing = dir;
return true;
}
public boolean rotateBlock() {
for(int i = this.facing.ordinal() + 1; i < this.facing.ordinal() + 6; ++i) {
ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[i % 6];
TileEntity tile = this.worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
if(tile instanceof IEnergyReceiver && ((IEnergyReceiver) tile).canConnectEnergy(dir.getOpposite())) {
this.facing = dir;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
this.worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
return true;
}
}
return false;
}
public int getLightValue() {
return this.isActive ? 7 : 0;
}
protected boolean canCycle() {
TileEntity tile = this.worldObj.getTileEntity(xCoord + facing.offsetX, yCoord + facing.offsetY, zCoord + facing.offsetZ);
if(tile instanceof IEnergyReceiver) {
this.canCycle = true;
} else {
this.canCycle = false;
}
return this.canCycle;
}
protected boolean canProcess() {
return this.fuelTank.getFluid() != null && this.fuelTank.getFluid().amount > 0;
}
public float getEnergyPerProcess() {
if(this.fuelTank.getFluid() == null) {
return 0.0F;
} else {
EngineLiquid fuel = ForceEngineLiquids.getEngineLiquid(this.fuelTank.getFluid());
EngineLiquid throttle = null;
if(this.throttleTank.getFluid() != null) {
throttle = ForceEngineLiquids.getEngineLiquid(this.throttleTank.getFluid());
}
if(fuel == null) {
return 0.0F;
} else {
float energy = fuel.getModifier();
if(throttle != null) {
energy *= throttle.getModifier();
}
return energy;
}
}
}
private void doLoss() {
if(this.fuelTank.getFluid() != null) {
EngineLiquid fuel = ForceEngineLiquids.getEngineLiquid(this.fuelTank.getFluid());
EngineLiquid throttle = null;
if(this.throttleTank.getFluid() != null) {
throttle = ForceEngineLiquids.getEngineLiquid(this.throttleTank.getFluid());
}
FluidStack var10000;
if(fuel != null) {
++this.fuelLossCycle;
if(this.fuelLossCycle >= fuel.getBurnTime() / 1000) {
var10000 = this.fuelTank.getFluid();
var10000.amount -= 1000 / fuel.getBurnTime() > 0?1000 / fuel.getBurnTime():1;
this.fuelLossCycle = 0;
}
}
if(throttle != null) {
++this.throttleLossCycle;
if(this.throttleLossCycle >= throttle.getBurnTime() / 1000) {
var10000 = this.throttleTank.getFluid();
var10000.amount -= 1000 / throttle.getBurnTime() > 0?1000 / throttle.getBurnTime():1;
this.throttleLossCycle = 0;
}
}
if(this.fuelTank.getFluid() != null && this.fuelTank.getFluid().amount <= 0) {
this.fuelTank.setFluid(null);
}
if(this.throttleTank.getFluid() != null && this.throttleTank.getFluid().amount <= 0) {
this.throttleTank.setFluid(null);
}
}
}
public void processActive() {
this.doLoss();
}
protected void transferEnergy() { //TODO better energy transfer
TileEntity tile = this.worldObj.getTileEntity(xCoord + facing.offsetX, yCoord + facing.offsetY, zCoord + facing.offsetZ);
if(tile instanceof IEnergyReceiver && ((IEnergyReceiver) tile).canConnectEnergy(facing.getOpposite())) {
int energy = (int) this.getEnergyPerProcess() * 200;
((IEnergyReceiver) tile).receiveEnergy(facing.getOpposite(), energy, false);
}
}
public void updateEntity() {
if(!Dartcraft.proxy.isSimulating(worldObj)) {
if(this.cycleProgress > 0.0F || this.isActive && this.canCycle) {
this.cycleProgress += 0.04F;
if(this.cycleProgress >= 1.0F) {
this.cycleProgress = 0.0F;
}
}
} else {
FluidStack curActive;
if(this.liquidInventory.getStackInSlot(0) != null) {
curActive = FluidContainerRegistry.getFluidForFilledItem(this.liquidInventory.getStackInSlot(0));
Fluid curCycle = FluidRegistry.getFluid("liquidforce");
if(curActive != null) {
EngineLiquid temp = ForceEngineLiquids.getEngineLiquid(curActive);
if(temp != null && (this.fuelTank.getFluid() == null || this.fuelTank.getFluid().isFluidEqual(curActive)) && (this.fuelTank.getFluid() == null || 10000 >= this.fuelTank.getFluid().amount + curActive.amount)) {
this.fuelTank.fill(curActive, true);
ItemStack temp1 = this.liquidInventory.getStackInSlot(0);
if(temp1.stackSize == 1 && temp1.getItem().hasContainerItem()) {
this.liquidInventory.setInventorySlotContents(0, temp1.getItem().getContainerItem(temp1));
} else {
this.liquidInventory.decrStackSize(0, 1);
}
}
}
if(this.liquidInventory.getStackInSlot(0) != null && this.liquidInventory.getStackInSlot(0).getItem() == DartItems.forcegem && curCycle != null && (this.fuelTank.getFluid() == null || 10000 >= this.fuelTank.getFluid().amount + (int)(1000.0F * Config.gemValue))) {
this.fuelTank.fill(new FluidStack(curCycle, (int)(1000.0F * Config.gemValue)), true);
this.liquidInventory.decrStackSize(0, 1);
}
}
if(this.liquidInventory.getStackInSlot(1) != null) {
curActive = FluidContainerRegistry.getFluidForFilledItem(this.liquidInventory.getStackInSlot(1));
if(curActive != null) {
EngineLiquid curCycle1 = ForceEngineLiquids.getEngineLiquid(curActive);
if(curCycle1 != null && (this.throttleTank.getFluid() == null || this.throttleTank.getFluid().isFluidEqual(curActive)) && (this.throttleTank.getFluid() == null || 10000 >= this.throttleTank.getFluid().amount + curActive.amount)) {
this.throttleTank.fill(curActive, true);
ItemStack temp2 = this.liquidInventory.getStackInSlot(1);
if(temp2.stackSize == 1 && temp2.getItem().hasContainerItem()) {
this.liquidInventory.setInventorySlotContents(1, temp2.getItem().getContainerItem(temp2));
} else {
this.liquidInventory.decrStackSize(1, 1);
}
}
}
}
if(this.cycleProgress > 0.0F || this.isActive && this.canCycle) {
this.cycleProgress += 0.04F;
if(this.cycleProgress >= 1.0F) {
this.cycleProgress = 0.0F;
this.stageCycle = false;
} else if((double)this.cycleProgress >= 0.5D && !this.stageCycle) {
this.transferEnergy();
this.stageCycle = true;
}
}
if(this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && this.canCycle()) {
if(this.canProcess()) {
this.isActive = true;
this.processActive();
} else {
this.isActive = false;
}
} else {
this.isActive = false;
}
//TODO Fix Cycling update
}
}
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.facing = ForgeDirection.getOrientation(data.getByte("facing"));
this.isActive = data.getBoolean("active");
this.fuelRF = data.getFloat("fuelRF");
this.canCycle = data.getBoolean("cycle");
if(data.hasKey("fuel")) {
this.fuelTank.setFluid(FluidStack.loadFluidStackFromNBT(data.getCompoundTag("fuel")));
}
if(data.hasKey("throttle")) {
this.throttleTank.setFluid(FluidStack.loadFluidStackFromNBT(data.getCompoundTag("throttle")));
}
if(data.hasKey("fuelSlot")) {
this.liquidInventory.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(data.getCompoundTag("fuelSlot")));
} else {
this.liquidInventory.setInventorySlotContents(0, (ItemStack)null);
}
if(data.hasKey("throttleSlot")) {
this.liquidInventory.setInventorySlotContents(1, ItemStack.loadItemStackFromNBT(data.getCompoundTag("throttleSlot")));
} else {
this.liquidInventory.setInventorySlotContents(1, (ItemStack)null);
}
}
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setByte("facing", (byte)this.facing.ordinal());
data.setBoolean("active", this.isActive);
data.setFloat("fuelRF", this.fuelRF);
data.setBoolean("cycle", this.canCycle);
if(this.fuelTank.getFluid() != null) {
data.setTag("fuel", this.fuelTank.getFluid().writeToNBT(new NBTTagCompound()));
}
if(this.throttleTank.getFluid() != null) {
data.setTag("throttle", this.throttleTank.getFluid().writeToNBT(new NBTTagCompound()));
}
if(this.liquidInventory.getStackInSlot(0) != null) {
data.setTag("fuelSlot", this.liquidInventory.getStackInSlot(0).writeToNBT(new NBTTagCompound()));
}
if(this.liquidInventory.getStackInSlot(1) != null) {
data.setTag("throttleSlot", this.liquidInventory.getStackInSlot(1).writeToNBT(new NBTTagCompound()));
}
}
@Override
public int extractEnergy(ForgeDirection var1, int var2, boolean var3) {
return 0;
}
@Override
public int getEnergyStored(ForgeDirection var1) {
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection var1) {
return 0;
}
@Override
public boolean canConnectEnergy(ForgeDirection var1) {
return var1 == facing;
}
@Override
public int getSizeInventory() {
return this.liquidInventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i) {
return this.liquidInventory.getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j) {
return this.liquidInventory.decrStackSize(i, j);
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
return this.liquidInventory.getStackInSlotOnClosing(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack stack) {
this.liquidInventory.setInventorySlotContents(i, stack);
}
@Override
public String getInventoryName() {
return this.liquidInventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return this.liquidInventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return this.liquidInventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.liquidInventory.isUseableByPlayer(player);
}
@Override
public void openInventory() {
this.liquidInventory.openInventory();
}
@Override
public void closeInventory() {
this.liquidInventory.closeInventory();
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
switch(i) {
case 0:
return ForceEngineLiquids.isFuel(FluidContainerRegistry.getFluidForFilledItem(stack));
case 1:
return ForceEngineLiquids.isThrottle(FluidContainerRegistry.getFluidForFilledItem(stack));
default:
return false;
}
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
int filled;
if(ForceEngineLiquids.isFuel(resource)) {
filled = this.fuelTank.fill(resource, doFill);
return filled;
} else if(ForceEngineLiquids.isThrottle(resource)) {
filled = this.throttleTank.fill(resource, doFill);
return filled;
} else {
return 0;
}
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return (from != null && fluid != null) && this.fill(from, new FluidStack(fluid, 1), false) > 0;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return new FluidTankInfo[]{this.fuelTank.getInfo(), this.throttleTank.getInfo()};
}
public Packet getDescriptionPacket() {
NBTTagCompound comp = new NBTTagCompound();
this.writeToNBT(comp);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, comp);
}
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
if(pkt != null && pkt.func_148857_g() != null) {
this.readFromNBT(pkt.func_148857_g());
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); //TODO Lighting
//worldObj.updateAllLightTypes(this.field_70329_l, this.field_70330_m, this.field_70327_n);
}
}
public void sendGuiNetworkData(Container container, ICrafting craft) {
byte throttleMeta = 0;
int throttleID = 0;
int throttleAmount = 0;
byte fuelMeta = 0;
int fuelID = 0;
int fuelAmount = 0;
if(this.fuelTank.getFluid() != null) {
fuelID = this.fuelTank.getFluid().getFluidID();
fuelAmount = this.fuelTank.getFluid().amount;
}
if(this.throttleTank.getFluid() != null) {
throttleID = this.throttleTank.getFluid().getFluidID();
throttleAmount = this.throttleTank.getFluid().amount;
}
craft.sendProgressBarUpdate(container, 0, fuelID);
craft.sendProgressBarUpdate(container, 1, fuelMeta);
craft.sendProgressBarUpdate(container, 2, fuelAmount);
craft.sendProgressBarUpdate(container, 3, throttleID);
craft.sendProgressBarUpdate(container, 4, throttleMeta);
craft.sendProgressBarUpdate(container, 5, throttleAmount);
if(craft instanceof EntityPlayerMP && Dartcraft.proxy.isSimulating(worldObj)) {
((EntityPlayerMP) craft).playerNetServerHandler.sendPacket(getDescriptionPacket());
}
}
public void receiveGuiNetworkData(int i, int j) {
FluidStack tempStack = this.fuelTank.getFluid();
FluidStack tempStack2 = this.throttleTank.getFluid();
switch(i) {
case 0:
if(this.fuelTank.getFluid() != null) {
this.fuelTank.setFluid(new FluidStack(j, tempStack.amount, tempStack.tag));
} else if (j > 0) {
this.fuelTank.setFluid(new FluidStack(j, 0));
}
break;
case 1:
if(this.fuelTank.getFluid() != null) {
this.fuelTank.setFluid(new FluidStack(tempStack.getFluidID(), tempStack.amount, (NBTTagCompound)null));
}
break;
case 2:
if(this.fuelTank.getFluid() != null) {
this.fuelTank.getFluid().amount = j;
}
break;
case 3:
if(this.throttleTank.getFluid() != null) {
this.throttleTank.setFluid(new FluidStack(j, tempStack2.amount, tempStack2.tag));
} else if (j > 0) {
this.throttleTank.setFluid(new FluidStack(j, 0));
}
break;
case 4:
if(this.throttleTank.getFluid() != null) {
this.throttleTank.setFluid(new FluidStack(tempStack2.getFluidID(), tempStack2.amount, (NBTTagCompound)null));
}
break;
case 5:
if(this.throttleTank.getFluid() != null) {
this.throttleTank.getFluid().amount = j;
}
}
}
}

View file

@ -0,0 +1,83 @@
package ley.modding.dartcraft.util;
import buildcraft.api.tools.IToolWrench;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.proxy.CommonProxy;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
public class DartUtils {
public static boolean isHoldingWrench(EntityPlayer player) {
if(player.getCurrentEquippedItem() == null) {
return false;
} else {
Item equipped = player.getCurrentEquippedItem().getItem();
return equipped instanceof IToolWrench;
}
}
public static boolean fillTankWithContainer(IFluidHandler theTile, EntityPlayer player) {
ItemStack theContainer = player.getCurrentEquippedItem();
FluidStack theLiquid = FluidContainerRegistry.getFluidForFilledItem(theContainer);
if(theLiquid != null && (theTile.fill(ForgeDirection.UNKNOWN, theLiquid, false) == theLiquid.amount || player.capabilities.isCreativeMode)) {
theTile.fill(ForgeDirection.UNKNOWN, theLiquid, true);
ItemStack returnStack = consumeItem(theContainer);
if(!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, returnStack);
}
return true;
} else {
return false;
}
}
public static ItemStack consumeItem(ItemStack theStack) {
if(theStack.stackSize == 1) {
return theStack.getItem().hasContainerItem()?theStack.getItem().getContainerItem(theStack):null;
} else {
theStack.splitStack(1);
return theStack;
}
}
public static void dropItem(ItemStack stack, World world, double x, double y, double z) {
if(stack != null && world != null && Dartcraft.proxy.isSimulating(world)) {
float xRand = CommonProxy.rand.nextFloat() * 0.2F + 0.1F;
float yRand = CommonProxy.rand.nextFloat() * 0.8F + 0.1F;
float zRand = CommonProxy.rand.nextFloat() * 0.2F + 0.1F;
while(stack.stackSize > 0) {
int randInt = CommonProxy.rand.nextInt(21) + 10;
if(randInt > stack.stackSize) {
randInt = stack.stackSize;
}
stack.stackSize -= randInt;
EntityItem droppedItem = new EntityItem(world, (double)((float)x + xRand), (double)((float)y + yRand), (double)((float)z + zRand), new ItemStack(stack.getItem(), randInt, stack.getItemDamage()));
if(stack.hasTagCompound()) {
droppedItem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
}
float modifier = 0.025F;
CommonProxy var10001 = Dartcraft.proxy;
droppedItem.motionX = (double)((float)CommonProxy.rand.nextGaussian() * modifier);
droppedItem.motionY = (double)((float)CommonProxy.rand.nextGaussian() * modifier + 0.2F);
droppedItem.motionZ = (double)((float)CommonProxy.rand.nextGaussian() * modifier);
droppedItem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(droppedItem);
}
}
}
}

View file

@ -1,12 +1,15 @@
package ley.modding.dartcraft.util;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.api.IForceConsumer;
import ley.modding.dartcraft.api.inventory.ItemInventory;
import ley.modding.dartcraft.item.DartItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@ -112,4 +115,29 @@ public class ForceConsumerUtils {
return canUse;
}
public static boolean isForceContainer(ItemStack stack)
{
if (stack == null) {
return false;
}
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
Fluid liquidForce = FluidRegistry.getFluid("liquidforce");
if ((liquid != null) && (liquidForce != null) && (liquid.getFluidID() == liquidForce.getID())) {
return true;
}
return (stack.getItem() == DartItems.forcegem) || (stack.getItem() == DartItems.forceshard);
}
public static boolean openForceConsumerGui(EntityPlayer player, ItemStack stack)
{
if ((stack == null) || (stack.getItem() == null) || (!stack.hasTagCompound()) || (!(stack.getItem() instanceof IForceConsumer)) || (player == null))
{
return false;
}
player.openGui(Dartcraft.instance, 16, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ);
return true;
}
}

View file

@ -0,0 +1,290 @@
package ley.modding.dartcraft.util;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.api.energy.EngineLiquid;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class ForceEngineLiquids {
private static ArrayList fuels = new ArrayList();
private static ArrayList throttles = new ArrayList();
public static void load() {
assertMilk();
new ArrayList();
boolean defaults = false;
ArrayList input = Config.getFuels();
if(input == null || input.size() <= 0) {
defaults = true;
}
try {
ArrayList e = getValues(input);
HashMap fuels = (HashMap)e.get(0);
HashMap throttles = (HashMap)e.get(1);
if(defaults || fuels.size() < 1 || throttles.size() < 1 || !fuels.containsKey("liquidforce")) {
throw new Exception();
}
Iterator i$ = fuels.keySet().iterator();
String name;
FluidStack e1;
EngineLiquid throttle;
while(i$.hasNext()) {
name = (String)i$.next();
try {
e1 = new FluidStack(FluidRegistry.getFluid(name), 1000);
throttle = new EngineLiquid(e1, 0, (int)((float[])fuels.get(name))[1], ((float[])fuels.get(name))[0]);
addLiquid(throttle);
} catch (Exception err) {
err.printStackTrace();
}
}
i$ = throttles.keySet().iterator();
while(i$.hasNext()) {
name = (String)i$.next();
try {
e1 = new FluidStack(FluidRegistry.getFluid(name), 1000);
throttle = new EngineLiquid(e1, 1, (int)((float[])throttles.get(name))[1], ((float[])throttles.get(name))[0]);
addLiquid(throttle);
} catch (Exception err) {
err.printStackTrace();
}
}
} catch (Exception e) {
// Dartcraft..warning("There was an error loading the fuels.txt. Please configure it correctly.");
e.printStackTrace();
defaults = true;
}
if(defaults) {
//DartCraft.dartLog.info("Loading default Fuels.");
vanillaSupport();
buildcraftSupport();
forestrySupport();
}
}
private static void assertMilk() {
try {
if(FluidRegistry.isFluidRegistered("milk") && FluidContainerRegistry.getFluidForFilledItem(new ItemStack(Items.milk_bucket)) == null) {
Fluid e = FluidRegistry.getFluid("milk");
FluidStack milkStack = new FluidStack(e, 1000);
FluidContainerRegistry.registerFluidContainer(new FluidContainerRegistry.FluidContainerData(milkStack, new ItemStack(Items.milk_bucket), FluidContainerRegistry.EMPTY_BUCKET));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static ArrayList getValues(ArrayList input) {
ArrayList values = new ArrayList();
HashMap fuels = new HashMap();
HashMap throttles = new HashMap();
try {
Iterator e = input.iterator();
while(e.hasNext()) {
String check = (String)e.next();
if(check != null && check.length() > 0) {
try {
String e1 = "";
float value = 0.0F;
boolean time = false;
int time1;
switch(check.charAt(0)) {
case 102:
e1 = check.substring(2, check.indexOf(61));
if(!fuels.containsKey(e1) && FluidRegistry.getFluid(e1) != null) {
value = (new Float(check.substring(check.indexOf(61) + 1, check.indexOf(59)))).floatValue();
time1 = (new Integer(check.substring(check.indexOf(59) + 1))).intValue();
if(value < 0.5F) {
value = 0.5F;
}
if(value > 20.0F) {
value = 20.0F;
}
if(time1 < 100) {
time1 = 100;
}
if(time1 > 1000000) {
time1 = 1000000;
}
fuels.put(e1, new float[]{value, (float)time1});
}
break;
case 116:
e1 = check.substring(2, check.indexOf(61));
if(!throttles.containsKey(e1) && FluidRegistry.getFluid(e1) != null) {
value = (new Float(check.substring(check.indexOf(61) + 1, check.indexOf(59)))).floatValue();
time1 = (new Integer(check.substring(check.indexOf(59) + 1))).intValue();
if(value < 1.0F) {
value = 1.0F;
}
if(value > 20.0F) {
value = 20.0F;
}
if(time1 < 100) {
time1 = 100;
}
if(time1 > 1000000) {
time1 = 1000000;
}
throttles.put(e1, new float[]{value, (float)time1});
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
values.add(fuels);
values.add(throttles);
return values;
}
private static void vanillaSupport() {
Fluid liquidForce = FluidRegistry.getFluid("liquidforce");
FluidStack milk = FluidRegistry.getFluidStack("milk", 1000);
if(liquidForce != null) {
addLiquid(new EngineLiquid(new FluidStack(liquidForce, 1000), 0, 20000, 4.0F));
}
if(milk != null) {
addLiquid(new EngineLiquid(milk, 1, 3000, 2.5F));
}
addLiquid(new EngineLiquid(new FluidStack(FluidRegistry.WATER, 1000), 1, 600, 2.0F));
addLiquid(new EngineLiquid(new FluidStack(FluidRegistry.LAVA, 1000), 0, 20000, 0.5F));
}
private static void buildcraftSupport() {
FluidStack oil = FluidRegistry.getFluidStack("oil", 1000);
if(oil != null) {
addLiquid(new EngineLiquid(oil, 0, 20000, 1.5F));
}
FluidStack fuel = FluidRegistry.getFluidStack("fuel", 1000);
if(fuel != null) {
addLiquid(new EngineLiquid(fuel, 0, 100000, 3.0F));
}
}
private static void forestrySupport() {
FluidStack crushedIce = FluidRegistry.getFluidStack("ice", 1000);
if(crushedIce != null) {
addLiquid(new EngineLiquid(crushedIce, 1, 20000, 4.0F));
}
FluidStack ethanol = FluidRegistry.getFluidStack("bioethanol", 1000);
if(ethanol != null) {
addLiquid(new EngineLiquid(ethanol, 0, '\uea60', 2.0F));
}
}
public static void addLiquid(EngineLiquid liquid) {
if(liquid != null) {
if(liquid.getType() == 0 && !isThrottle(liquid.getLiquid())) {
fuels.add(liquid);
System.out.println("Added fuel: " + liquid.getLiquid().getFluid().getName());
}
if(liquid.getType() == 1 && !isFuel(liquid.getLiquid())) {
throttles.add(liquid);
System.out.println("Added throttle: " + liquid.getLiquid().getFluid().getName());
}
}
}
public static boolean isFuel(FluidStack liquid) {
if(fuels != null && fuels.size() > 0 && liquid != null) {
Iterator i$ = fuels.iterator();
while(i$.hasNext()) {
EngineLiquid fuel = (EngineLiquid)i$.next();
if(fuel != null && fuel.getLiquid() != null && fuel.getLiquid().isFluidEqual(liquid)) {
return true;
}
}
}
return false;
}
public static boolean isThrottle(FluidStack liquid) {
if(throttles != null && throttles.size() > 0 && liquid != null) {
Iterator i$ = throttles.iterator();
while(i$.hasNext()) {
EngineLiquid throttle = (EngineLiquid) i$.next();
if(throttle != null && throttle.getLiquid() != null && throttle.getLiquid().isFluidEqual(liquid)) {
return true;
}
}
}
return false;
}
public static EngineLiquid getEngineLiquid(FluidStack liquid) {
Iterator i$;
EngineLiquid throttle;
if(fuels != null && fuels.size() > 0 && liquid != null) {
i$ = fuels.iterator();
while(i$.hasNext()) {
throttle = (EngineLiquid)i$.next();
if(throttle != null && throttle.getLiquid() != null && throttle.getLiquid().isFluidEqual(liquid)) {
return throttle;
}
}
}
if(throttles != null && throttles.size() > 0 && liquid != null) {
i$ = throttles.iterator();
while(i$.hasNext()) {
throttle = (EngineLiquid)i$.next();
if(throttle != null && throttle.getLiquid() != null && throttle.getLiquid().isFluidEqual(liquid)) {
return throttle;
}
}
}
return null;
}
}

View file

@ -0,0 +1,220 @@
package ley.modding.dartcraft.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class FortunesUtil {
private static Random rand;
private static List<String> fortunes = new ArrayList<String>();
public static void addFortune(String fortune) {
if (fortunes != null && fortune != null)
fortunes.add(fortune);
}
public static void load() {
rand = new Random(System.nanoTime());
loadFortunes();
}
public static String getFortune() {
if (fortunes == null || fortunes.size() < 1)
return "";
int index = rand.nextInt(fortunes.size());
if (index >= fortunes.size())
return "";
return fortunes.get(index);
}
private static void loadFortunes() {
addFortune("You aren't supposed to eat me.");
addFortune("Beauty is in the eye of the tiger.");
addFortune("Creeper!");
addFortune("Which came first, the chicken or the chunk?");
addFortune("Whatever happened to Doritos 3D?");
addFortune("Diabetes, anyone?");
addFortune("That wasn't a cookie!");
addFortune("If a tree falls down in the woods, you have a special mod installed.");
addFortune("The cake is a lie of omission.");
addFortune("A wise man once said, \"Yes honey, it does make you look fat.\" He never said that again.");
addFortune("Don't stare directly at the pixels.");
addFortune("I know where you live.");
addFortune("Your lucky numbers are 0, -7, and 437922904678137496.708162");
addFortune("There is never enough redstone.");
addFortune("What you seek is surrounded by blocks.");
addFortune("Today is Tuesday, or is it Friday - I can never tell.");
addFortune("In the event of a creeper explosion, your keyboard can double as a broken keyboard.");
addFortune("I didn't do it.");
addFortune("You are 5.6 grams heavier than you were 10 seconds ago.");
addFortune("I dropped my cookie.");
addFortune("...Saltpeter? Really?");
addFortune("We're no strangers to love. You know the rules and so do I.");
addFortune("Eat another cookie.");
addFortune("fontRenderer.drawString(\"Totally Real Accidental Glitch\", posX, posY, 0xFFFFFF);");
addFortune("I CAN believe it's not butter.");
addFortune("Beware enderman with a short fuse...");
addFortune("Remember to repair your tools.");
addFortune("Every rose has its bounding box.");
addFortune("Get out of my chest!");
addFortune("Please recycle.");
addFortune("Great, now you've spoiled your dinner!");
addFortune("Welcome to Hoarders: Minecraft edition!");
addFortune("Not all Blocks are created equal.");
addFortune("Don't touch that!");
addFortune("Always name your machinations.");
addFortune("Look in your inventory, now back to me - this fortune is now diamonds!");
addFortune("Who put that there?");
addFortune("Winners never cheat and cheaters never win, unless the winners cheated, in which case the cheaters won.");
addFortune("Hi Bob! What, they can't all be zingers.");
addFortune("Have you ever thought to yourself, \"My, that's an awfully large open grave!\"");
addFortune("Could you pick up my dry-cleaning?");
addFortune("Never shower in a thunderstorm. It's less efficient than bathing indoors and you'll freak out your neighbors.");
addFortune("It is said that everyone experiences hardships, but God must REALLY hate YOU.");
addFortune("If you play a country song backwards, you waste about 4 minutes of your life listening to garbled nonsense.");
addFortune("No, you can't make that jump.");
addFortune("I know they're furry and cuddly, but trust me, they're evil incarnate.");
addFortune("Do you Dew?");
addFortune("I see the land, but where exactly are the tracts?");
addFortune("Creepers were originally from Dr. Who.");
addFortune("Don't bogart my nasal spray!");
addFortune("You'll live.");
addFortune("Don't make me come back there!");
addFortune("I've burned everything that reminds me of you in a ritualistic bonfire.");
addFortune("We will be an unstoppable force; to our enemies we bring only death, to our allies we always bring cake.");
addFortune("Heavy is the head that eats the crayons.");
addFortune("Beware skinwalkers.");
addFortune("Don't fear the creeper.");
addFortune("Goodness and love will always win!");
addFortune("I told you not to eat that!");
addFortune("Winner!");
addFortune("Beware anyone without an eye-patch!");
addFortune("Don't kill all the animals!");
addFortune("It's a wonder you get anything done!");
addFortune("You will find happiness with a new love: Minecraft's latest patch.");
addFortune("Seriously, who is in charge of the song/cowbell ratio?");
addFortune("It's not a bug, it's a \"feature.\"");
addFortune("Do you really need this many cookies?");
addFortune("NCC1701");
addFortune("I wanted to be a newspaper.");
addFortune("Thank you! It was really dark in there!");
addFortune("Thank you for not eating me.");
addFortune("Burn the door!");
addFortune("That's the biggest flapjack I've ever seen!");
addFortune("Please be kind, de-rind");
addFortune("It's a secret to everybody.");
addFortune("I AM ERROR.");
addFortune("If all else fails use fire.");
addFortune("Dig it! Dig it! Dig to the center of the earth!");
addFortune("No! Not into the pit! It BURNS!");
addFortune("Dawn of the First Day, 72 hours remain.");
addFortune("Don't stare directly at the potato.");
addFortune("The chicken is a double-agent.");
addFortune("Good lord!");
addFortune("What's all this junk?");
addFortune("Creepers blow chunks.");
addFortune("Equivalence is a lie.");
addFortune("Body by Sycamore.");
addFortune("I hear 'Innards of the Machine' is on tour.");
addFortune("Do something else.");
addFortune("The capital of The Ukraine is Kiev.");
addFortune("DebugCookie4A73N82");
addFortune("Point that somewhere else!");
addFortune("Forking is strictly prohibited.");
addFortune("Void where prohibited.");
addFortune("This parrot is no more!");
addFortune("He's dead, Jim.");
addFortune("Leave me alone for a bit, okay?");
addFortune("Don't you dare shift-click me!");
addFortune("Me again.");
addFortune("My summer home is a no-bake.");
addFortune("We can still be friends.");
addFortune("The night is young, but you are not.");
addFortune("Keyboard cat has carpal tunnel.");
addFortune("Pull lever, get key.");
addFortune("Boats n' Hoes");
addFortune("Never eat an entire chocolate bunny in one sitting.");
addFortune("Push that button and die.");
addFortune("That cookie was mostly spackle.");
addFortune("Slime Chunkery.");
addFortune("I hate Thaumic Slimes.");
addFortune("Inertia is a property of mallard.");
addFortune("I prefer cake.");
addFortune("If you can read this, you're literate.");
addFortune("Don't touch the sides!");
addFortune("Crunchitize me Cap'n!");
addFortune("Please head in an orderly fashion to the disintegration chamber.");
addFortune("It's the deer's ears.");
addFortune("Happy anniversary, Carol!");
addFortune("Never startle a ninja.");
addFortune("If the shoe fits, you probably own it.");
addFortune("Cattle reproduce by budding.");
addFortune("Has anyone seen my Fedora?");
addFortune("I beg to defer.");
addFortune("Everybody loops.");
addFortune("Why is Count Chocula seasonal? Pedophilic vampires are always in style!");
addFortune("Eekum Bokum.");
addFortune("Churba wurt!");
addFortune("Darwa jit!");
addFortune("Success is often preceded by failure, then followed again by failure.");
addFortune("Man with Steve skin receive no cake.");
addFortune("It's all Melnics to me!");
addFortune("\"Steve\" means \"lazy\" in Swedish.");
addFortune("This is the word of Notch.");
addFortune("Don't attack the cute little endermen - you'll be sorry.");
addFortune("I miss my sanity, but then again I never used it.");
addFortune("So this is where germs are born!");
addFortune("I hate mondays.");
addFortune("My old nemesis: gravity.");
addFortune("I'm upgrade fodder!");
addFortune("You can do anything at Zombo.com.");
addFortune("Remember to feed the cattle.");
addFortune("TROGDOR was a man. I mean, he was a dragon-man... Maybe he was just a dragon.");
addFortune("Charles in charge of our clicks left and right. Charles in charge of every block in sight.");
addFortune("Charles was never really in charge.");
addFortune("Remember to use every part of the chicken.");
addFortune("I'm not responsible for this.");
addFortune("Every 10 minutes another crappy fortune is written.");
addFortune("How many licks does it take to get to the center of a Chuck Norris?");
addFortune("Roundhouse-kick for the win!");
addFortune("DO NOT feed the beast! (After midnight)");
addFortune("Please stop doing that.");
addFortune("I'm not a vending machine!");
addFortune("Try Ubuntu.");
addFortune("If you program for more than 20 hours straight, do not blink.");
addFortune("Ceiling cat is watching you procrastinate.");
addFortune("Get your hand off my thigh! You can have the leg.");
addFortune("Protective eyewear is a must!");
addFortune("It's all in the wristwatch.");
addFortune("Endermen in the UCB!");
addFortune("Endermen can move TNT. I'm serious.");
addFortune("Aww, you got blood all over my new sword!");
addFortune("The human pancreas can take only so many twinkies.");
addFortune("Humus is something you eat when you want your innards to cry.");
addFortune("By Mennen");
addFortune("Put me back in!");
addFortune("...I got nothin'.");
addFortune("We're out of milk.");
addFortune("Always edit-out the derps.");
addFortune("I want a lawyer.");
addFortune("Bring me a shrubbery!");
addFortune("It's bigger on the inside.");
addFortune("That's what she said.");
addFortune("Have you heard the one about the Rabbi and the Priest? Oh I forgot, you're deaf.");
addFortune("There are worse appendages to get caught sticking inside the cookie jar.");
addFortune("Ever have the feeling you're being watched? That's me!");
addFortune("He who handles his NullPointerExceptions is a wise man indeed.");
addFortune("Taking candy from a baby often prevents choking.");
addFortune("Texting while driving is a potent form of natural-selection.");
addFortune("The secret to a good marriage is matching tattoos.");
addFortune("A sucker is born every minute, however an idiot is born every two seconds.");
addFortune("Error in Thread Main: ExceptionNotCaughtException: DartCraft.java:32");
addFortune("I'll tear YOUR stub!");
addFortune("Daydreaming is free, cookies are not.");
addFortune("PINGAS!");
addFortune("The run is dead.");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,45 @@
{
"animation": {
"frametime": 3,
"frames": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
18,
17,
16,
15,
14,
13,
12,
11,
10,
9,
8,
7,
6,
5,
4,
3,
2,
1
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

View file

@ -0,0 +1,42 @@
{
"animation": {
"frames": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
{
"index":0,
"time": 64
}
]
}
}