mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 11:29:30 +00:00
Added electromagnet.
This commit is contained in:
1 parent
b2455eaef6
commit
ec812220fe
10 files changed
+308
-16
No files matched your search
@@ -127,6 +127,10 @@ public final class Config {
|
||||
public static float farmContinuousEnergyUse = 1;
|
||||
public static float farmActionEnergyUse = 40;
|
||||
public static int farmDefaultSize = 3;
|
||||
|
||||
public static int magnetPowerUsePerTickRF = 5;
|
||||
public static int magnetPowerCapacityRF = 100000;
|
||||
public static int magnetRange = 5;
|
||||
|
||||
public static void load(FMLPreInitializationEvent event) {
|
||||
configDirectory = new File(event.getModConfigurationDirectory(), "enderio");
|
||||
@@ -379,6 +383,14 @@ public final class Config {
|
||||
"The amount of power used by a farm per action (eg plant, till, harvest) ").getDouble(farmActionEnergyUse);
|
||||
farmDefaultSize = config.get("Settings", "farmDefaultSize", farmDefaultSize,
|
||||
"The numver of blocks a farm will extend from its center").getInt(farmDefaultSize);
|
||||
|
||||
|
||||
magnetPowerUsePerTickRF = config.get("Settings", "magnetPowerUsePerTickRF", magnetPowerUsePerTickRF,
|
||||
"The amount of RF power used per tick when the magnet is active").getInt(magnetPowerUsePerTickRF);
|
||||
magnetPowerCapacityRF = config.get("Settings", "magnetPowerCapacityRF", magnetPowerCapacityRF,
|
||||
"Amount of RF power stored in a fully charged magnet").getInt(magnetPowerCapacityRF);
|
||||
magnetRange = config.get("Settings", "magnetRange", magnetRange,
|
||||
"Range of the magnet in blocks.").getInt(magnetRange);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import crazypants.enderio.enderface.ItemEnderface;
|
||||
import crazypants.enderio.fluid.BlockFluidEio;
|
||||
import crazypants.enderio.fluid.Fluids;
|
||||
import crazypants.enderio.fluid.ItemBucketEio;
|
||||
import crazypants.enderio.item.ItemMagnet;
|
||||
import crazypants.enderio.item.ItemRecipes;
|
||||
import crazypants.enderio.item.ItemYetaWrench;
|
||||
import crazypants.enderio.item.darksteel.ItemDarkSteelArmor;
|
||||
@@ -143,6 +144,7 @@ public class EnderIO {
|
||||
public static BlockHyperCube blockHyperCube;
|
||||
public static BlockPowerMonitor blockPowerMonitor;
|
||||
public static BlockVat blockVat;
|
||||
public static BlockFarmStation blockFarmStation;
|
||||
|
||||
public static BlockElectricLight blockElectricLight;
|
||||
public static BlockLightNode blockLightNode;
|
||||
@@ -167,6 +169,7 @@ public class EnderIO {
|
||||
// Items
|
||||
public static ItemYetaWrench itemYetaWench;
|
||||
public static ItemConduitProbe itemConduitProbe;
|
||||
public static ItemMagnet itemMagnet;
|
||||
|
||||
public static ItemDarkSteelArmor itemDarkSteelHelmet;
|
||||
public static ItemDarkSteelArmor itemDarkSteelChestplate;
|
||||
@@ -175,7 +178,7 @@ public class EnderIO {
|
||||
public static ItemDarkSteelSword itemDarkSteelSword;
|
||||
public static ItemDarkSteelPickaxe itemDarkSteelPickaxe;
|
||||
|
||||
public static BlockFarmStation blockFarmStation;
|
||||
|
||||
|
||||
// public static ITrigger triggerNoEnergy;
|
||||
// public static ITrigger triggerHasEnergy;
|
||||
@@ -281,6 +284,8 @@ public class EnderIO {
|
||||
itemEnderface = ItemEnderface.create();
|
||||
itemTravelStaff = ItemTravelStaff.create();
|
||||
itemConduitProbe = ItemConduitProbe.create();
|
||||
|
||||
itemMagnet = ItemMagnet.create();
|
||||
|
||||
itemDarkSteelHelmet = ItemDarkSteelArmor.create(0);
|
||||
itemDarkSteelChestplate = ItemDarkSteelArmor.create(1);
|
||||
@@ -289,6 +294,8 @@ public class EnderIO {
|
||||
|
||||
itemDarkSteelSword = ItemDarkSteelSword.create();
|
||||
itemDarkSteelPickaxe = ItemDarkSteelPickaxe.create();
|
||||
|
||||
|
||||
|
||||
MaterialRecipes.registerOresInDictionary();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ public enum ModObject {
|
||||
itemYetaWrench,
|
||||
|
||||
blockTravelAnchor,
|
||||
itemTravelStaff;
|
||||
itemTravelStaff,
|
||||
itemMagnet;
|
||||
|
||||
public final String unlocalisedName;
|
||||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
package crazypants.enderio.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cofh.api.energy.ItemEnergyContainer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil.PowerType;
|
||||
import crazypants.enderio.material.Material;
|
||||
import crazypants.enderio.teleport.TravelController;
|
||||
import crazypants.util.ItemUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
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.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipProvider {
|
||||
|
||||
private static final String ACTIVE_KEY = "magnetActive";
|
||||
|
||||
public static void setActive(ItemStack item, boolean active) {
|
||||
if(item == null) {
|
||||
return;
|
||||
}
|
||||
NBTTagCompound nbt = ItemUtil.getOrCreateNBT(item);
|
||||
nbt.setBoolean(ACTIVE_KEY, active);
|
||||
}
|
||||
|
||||
public static boolean isActive(ItemStack item) {
|
||||
if(item == null) {
|
||||
return false;
|
||||
}
|
||||
if(item.stackTagCompound == null) {
|
||||
return false;
|
||||
}
|
||||
if(!item.stackTagCompound.hasKey(ACTIVE_KEY)) {
|
||||
return false;
|
||||
}
|
||||
return item.stackTagCompound.getBoolean(ACTIVE_KEY);
|
||||
}
|
||||
|
||||
public static boolean hasPower(ItemStack itemStack) {
|
||||
return EnderIO.itemMagnet.getEnergyStored(itemStack) > 0;
|
||||
}
|
||||
|
||||
public static void drainPerTickPower(ItemStack itemStack) {
|
||||
EnderIO.itemMagnet.extractEnergy(itemStack, Config.magnetPowerUsePerTickRF, false);
|
||||
}
|
||||
|
||||
public static ItemMagnet create() {
|
||||
ItemMagnet result = new ItemMagnet();
|
||||
result.init();
|
||||
FMLCommonHandler.instance().bus().register(new MagnetController());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected ItemMagnet() {
|
||||
super(Config.magnetPowerCapacityRF, Config.magnetPowerCapacityRF/100);
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
setUnlocalizedName(ModObject.itemMagnet.unlocalisedName);
|
||||
setMaxDamage(16);
|
||||
setMaxStackSize(1);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
GameRegistry.registerItem(this, ModObject.itemMagnet.unlocalisedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister IIconRegister) {
|
||||
itemIcon = IIconRegister.registerIcon("enderio:magnet");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
ItemStack is = new ItemStack(this);
|
||||
setFull(is);
|
||||
par3List.add(is);
|
||||
|
||||
is = new ItemStack(this);
|
||||
setEnergy(is, 0);
|
||||
par3List.add(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
|
||||
super.addInformation(itemStack, par2EntityPlayer, list, par4);
|
||||
String str = PowerDisplayUtil.formatPower(PowerType.RF, getEnergyStored(itemStack)) + "/"
|
||||
+ PowerDisplayUtil.formatPower(PowerType.RF, getMaxEnergyStored(itemStack)) + " " + PowerDisplayUtil.abrevation();
|
||||
list.add(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEffect(ItemStack item, int pass) {
|
||||
return isActive(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
|
||||
setEnergy(itemStack, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
int res = super.receiveEnergy(container, maxReceive, simulate);
|
||||
if(res != 0 && !simulate) {
|
||||
updateDamage(container);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
int res = super.extractEnergy(container, maxExtract, simulate);
|
||||
if(res != 0 && !simulate) {
|
||||
updateDamage(container);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void extractInternal(ItemStack item, int powerUse) {
|
||||
int res = Math.max(0, getEnergyStored(item) - powerUse);
|
||||
setEnergy(item, res);
|
||||
}
|
||||
|
||||
void setEnergy(ItemStack container, int energy) {
|
||||
if(container.stackTagCompound == null) {
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
container.stackTagCompound.setInteger("Energy", energy);
|
||||
updateDamage(container);
|
||||
}
|
||||
|
||||
void setFull(ItemStack container) {
|
||||
setEnergy(container, Config.magnetPowerCapacityRF);
|
||||
}
|
||||
|
||||
private void updateDamage(ItemStack stack) {
|
||||
float r = (float) getEnergyStored(stack) / getMaxEnergyStored(stack);
|
||||
int res = 16 - (int) (r * 16);
|
||||
stack.setItemDamage(res);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) {
|
||||
if(player.isSneaking()) {
|
||||
setActive(equipped, !isActive(equipped));
|
||||
}
|
||||
return equipped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedNameForTooltip() {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -13,25 +13,24 @@ public class ItemRecipes {
|
||||
public static void addRecipes() {
|
||||
ItemStack basicGear = new ItemStack(EnderIO.itemMachinePart, 1, MachinePart.BASIC_GEAR.ordinal());
|
||||
ItemStack electricalSteel = new ItemStack(EnderIO.itemAlloy, 1, Alloy.ELECTRICAL_STEEL.ordinal());
|
||||
ItemStack wrench = new ItemStack(EnderIO.itemYetaWench, 1, 0);
|
||||
ItemStack conductiveIron = new ItemStack(EnderIO.itemAlloy, 1, Alloy.CONDUCTIVE_IRON.ordinal());
|
||||
ItemStack vibCry = new ItemStack(EnderIO.itemMaterial, 1, Material.VIBRANT_CYSTAL.ordinal());
|
||||
ItemStack darkSteel = new ItemStack(EnderIO.itemAlloy, 1, Alloy.DARK_STEEL.ordinal());
|
||||
|
||||
// Wrench
|
||||
ItemStack wrench = new ItemStack(EnderIO.itemYetaWench, 1, 0);
|
||||
GameRegistry.addShapedRecipe(wrench, "s s", " b ", " s ", 's', electricalSteel, 'b', basicGear);
|
||||
|
||||
ItemStack magnet = new ItemStack(EnderIO.itemMagnet, 1, 0);
|
||||
GameRegistry.addShapedRecipe(magnet, "s s", "c c", "cvc", 's', electricalSteel, 'c', conductiveIron, 'v', vibCry);
|
||||
|
||||
ItemStack darkSteel = new ItemStack(EnderIO.itemAlloy, 1, Alloy.DARK_STEEL.ordinal());
|
||||
|
||||
//Dark Steel
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelHelmet.createItemStack(), "sss", "s s", " ", 's', darkSteel);
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelHelmet.createItemStack(), " ", "sss", "s s", 's', darkSteel);
|
||||
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelChestplate.createItemStack(), "s s", "sss", "sss", 's', darkSteel);
|
||||
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelLeggings.createItemStack(), "sss", "s s", "s s", 's', darkSteel);
|
||||
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelBoots.createItemStack(), "s s", "s s", " ", 's', darkSteel);
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelBoots.createItemStack(), " ", "s s", "s s", 's', darkSteel);
|
||||
|
||||
GameRegistry.addShapedRecipe(EnderIO.itemDarkSteelBoots.createItemStack(), " ", "s s", "s s", 's', darkSteel);
|
||||
|
||||
}
|
||||
|
||||
public static void addOreDictionaryRecipes() {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package crazypants.enderio.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.command.IEntitySelector;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class MagnetController implements IEntitySelector {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
|
||||
ActiveMagnet mag = getActiveMagnet(event.player);
|
||||
if(mag != null) {
|
||||
doHoover(event.player);
|
||||
if(event.side == Side.SERVER) {
|
||||
ItemMagnet.drainPerTickPower(mag.item);
|
||||
event.player.inventory.setInventorySlotContents(mag.slot, mag.item);
|
||||
event.player.inventory.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ActiveMagnet getActiveMagnet(EntityPlayer player) {
|
||||
ItemStack[] inv = player.inventory.mainInventory;
|
||||
for(int i=0;i<9;i++) {
|
||||
if(ItemMagnet.isActive(inv[i]) && ItemMagnet.hasPower(inv[i])) {
|
||||
return new ActiveMagnet(inv[i], i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void doHoover(EntityPlayer player) {
|
||||
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
|
||||
player.posX - Config.magnetRange, player.posY - Config.magnetRange, player.posZ - Config.magnetRange,
|
||||
player.posX + Config.magnetRange, player.posY + Config.magnetRange, player.posZ + Config.magnetRange);
|
||||
|
||||
List<EntityItem> interestingItems = player.worldObj.selectEntitiesWithinAABB(EntityItem.class, aabb, this);
|
||||
|
||||
for (EntityItem entity : interestingItems) {
|
||||
double x = player.posX + 0.5D - entity.posX;
|
||||
double y = player.posY + 1D - entity.posY;
|
||||
double z = player.posZ + 0.5D - entity.posZ;
|
||||
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
if(distance < 1.25) {
|
||||
entity.onCollideWithPlayer(player);
|
||||
} else {
|
||||
double speed = 0.035;
|
||||
entity.motionX += x / distance * speed;
|
||||
entity.motionY += y * speed;
|
||||
if(y > 0) {
|
||||
entity.motionY = 0.12;
|
||||
}
|
||||
entity.motionZ += z / distance * speed;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityApplicable(Entity var1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class ActiveMagnet {
|
||||
ItemStack item;
|
||||
int slot;
|
||||
|
||||
ActiveMagnet(ItemStack item, int slot) {
|
||||
this.item = item;
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,9 +25,6 @@ public abstract class AbstractMachineContainer extends Container {
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
// if(itemStack != null && itemStack.stackSize > 1) {
|
||||
// return false;
|
||||
// }
|
||||
return tileEntity.isItemValidForSlot(tileEntity.getSlotDefinition().getMinUpgradeSlot(), itemStack);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyContainerItem, IResourceTooltipProvider {
|
||||
public class ItemTravelStaff extends ItemEnergyContainer implements IResourceTooltipProvider {
|
||||
|
||||
public static boolean isEquipped(EntityPlayer ep) {
|
||||
if(ep == null || ep.getCurrentEquippedItem() == null) {
|
||||
|
||||
Reference in new issue
Block a user