mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Add wireless light and allow lights to be shift-wrenched
This commit is contained in:
1 parent
a5ac79c351
commit
368fec1dea
10 files changed
+149
-43
No files matched your search
@@ -14,6 +14,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.item.skull.BlockEndermanSkull;
|
||||
import crazypants.enderio.machine.light.BlockItemElectricLight;
|
||||
import crazypants.enderio.material.Alloy;
|
||||
import crazypants.enderio.material.FrankenSkull;
|
||||
import crazypants.enderio.material.MachinePart;
|
||||
@@ -243,7 +244,16 @@ public class MachineRecipes {
|
||||
ClearConfigRecipe inst = new ClearConfigRecipe();
|
||||
MinecraftForge.EVENT_BUS.register(inst);
|
||||
GameRegistry.addRecipe(inst);
|
||||
|
||||
|
||||
//wireless light
|
||||
ItemStack poweredLamp = new ItemStack(EnderIO.blockElectricLight, 1, BlockItemElectricLight.Type.ELECTRIC.ordinal());
|
||||
ItemStack poweredLampInv = new ItemStack(EnderIO.blockElectricLight, 1, BlockItemElectricLight.Type.ELECTRIC_INV.ordinal());
|
||||
ItemStack wirelessLamp = new ItemStack(EnderIO.blockElectricLight, 1, BlockItemElectricLight.Type.WIRELESS.ordinal());
|
||||
ItemStack wirelessLampInv = new ItemStack(EnderIO.blockElectricLight, 1, BlockItemElectricLight.Type.WIRELESS_INV.ordinal());
|
||||
GameRegistry.addShapelessRecipe(wirelessLamp, poweredLamp, enderRes);
|
||||
GameRegistry.addShapelessRecipe(wirelessLamp, wirelessLampInv, Blocks.redstone_torch);
|
||||
GameRegistry.addShapelessRecipe(wirelessLampInv, poweredLampInv, enderRes);
|
||||
GameRegistry.addShapelessRecipe(wirelessLampInv, wirelessLamp, Blocks.redstone_torch);
|
||||
}
|
||||
|
||||
public static void addOreDictionaryRecipes() {
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
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.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
@@ -15,6 +15,8 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import cofh.api.item.IToolHammer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -171,6 +173,21 @@ public class BlockElectricLight extends BlockEio {
|
||||
((TileElectricLight) te).onNeighborBlockChange(blockID);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
Item equipped = player.getCurrentEquippedItem().getItem();
|
||||
if ((equipped instanceof IToolWrench || equipped instanceof IToolHammer) && player.isSneaking() && !world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof TileElectricLight) {
|
||||
((TileElectricLight) te).onBlockRemoved();
|
||||
world.setBlockToAir(x, y, z);
|
||||
dropBlockAsItem(world, x, y, z, createDrop((TileElectricLight) te));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
||||
@@ -184,7 +201,6 @@ public class BlockElectricLight extends BlockEio {
|
||||
te.onBlockRemoved();
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,11 +230,14 @@ public class BlockElectricLight extends BlockEio {
|
||||
int meta = te.isInvereted() ? 1 : 0;
|
||||
if(!te.isRequiresPower()) {
|
||||
meta += 2;
|
||||
} else if (te.isWireless()) {
|
||||
meta += 4;
|
||||
}
|
||||
ItemStack st = new ItemStack(this, 1, meta);
|
||||
return st;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
if(!world.isRemote) {
|
||||
@@ -226,14 +245,7 @@ public class BlockElectricLight extends BlockEio {
|
||||
if(te instanceof TileElectricLight) {
|
||||
TileElectricLight cb = (TileElectricLight) te;
|
||||
if(!player.capabilities.isCreativeMode) {
|
||||
ItemStack itemStack = createDrop(cb);
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
dropBlockAsItem(world, x, y, z, createDrop(cb));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,5 +260,4 @@ public class BlockElectricLight extends BlockEio {
|
||||
}
|
||||
return new ItemStack(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,20 +17,24 @@ import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
|
||||
public class BlockItemElectricLight extends ItemBlockWithMetadata implements IResourceTooltipProvider {
|
||||
|
||||
enum Type {
|
||||
ELECTRIC("item.itemElectricLight", false, true),
|
||||
ELECTRIC_INV("item.itemElectricLightInverted", true, true),
|
||||
BASIC("item.itemLight", false, false),
|
||||
BASIC_INV("item.itemLightInverted", true, false);
|
||||
public enum Type {
|
||||
ELECTRIC("item.itemElectricLight", false, true, false),
|
||||
ELECTRIC_INV("item.itemElectricLightInverted", true, true, false),
|
||||
BASIC("item.itemLight", false, false, false),
|
||||
BASIC_INV("item.itemLightInverted", true, false, false),
|
||||
WIRELESS("item.itemWirelessLight", false, true, true),
|
||||
WIRELESS_INV("item.itemWirelessLightInverted", true, true, true);
|
||||
|
||||
final String unlocName;
|
||||
final boolean isInverted;
|
||||
final boolean isPowered;
|
||||
final boolean isWireless;
|
||||
|
||||
private Type(String unlocName, boolean isInverted, boolean isPowered) {
|
||||
private Type(String unlocName, boolean isInverted, boolean isPowered, boolean isWireless) {
|
||||
this.unlocName = unlocName;
|
||||
this.isInverted = isInverted;
|
||||
this.isPowered = isPowered;
|
||||
this.isWireless = isWireless;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,6 +73,7 @@ public class BlockItemElectricLight extends ItemBlockWithMetadata implements IRe
|
||||
Type t= Type.values()[metadata];
|
||||
el.setInverted(t.isInverted);
|
||||
el.setRequiresPower(t.isPowered);
|
||||
el.setWireless(t.isWireless);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -78,7 +83,4 @@ public class BlockItemElectricLight extends ItemBlockWithMetadata implements IRe
|
||||
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
|
||||
return getUnlocalizedName(itemStack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package crazypants.enderio.machine.light;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -10,6 +11,9 @@ import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.wireless.IWirelessCharger;
|
||||
import crazypants.enderio.machine.wireless.WirelessChargerController;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.Capacitors;
|
||||
import crazypants.enderio.power.ICapacitor;
|
||||
@@ -38,6 +42,10 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
private boolean isInvereted;
|
||||
|
||||
private boolean requiresPower = true;
|
||||
|
||||
private boolean isWireless;
|
||||
private IWirelessCharger charger;
|
||||
private int ticksSinceLastSearch = 50;
|
||||
|
||||
private ICapacitor capacitor;
|
||||
|
||||
@@ -77,17 +85,25 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
public void setRequiresPower(boolean isPowered) {
|
||||
requiresPower = isPowered;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRequiresPower() {
|
||||
return requiresPower;
|
||||
}
|
||||
|
||||
public void setInvereted(boolean isInvereted) {
|
||||
this.isInvereted = isInvereted;
|
||||
}
|
||||
|
||||
public boolean isInvereted() {
|
||||
return isInvereted;
|
||||
}
|
||||
|
||||
public void setWireless(boolean wireless) {
|
||||
this.isWireless = true;
|
||||
}
|
||||
|
||||
public void setInvereted(boolean isInvereted) {
|
||||
this.isInvereted = isInvereted;
|
||||
public boolean isWireless() {
|
||||
return isWireless;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,9 +115,11 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
boolean hasRedstone = hasRedstoneSignal();
|
||||
|
||||
boolean isActivated = (requiresPower ? hasPower() : true) && (hasRedstone && !isInvereted || !hasRedstone && isInvereted);
|
||||
|
||||
if(isActivated && requiresPower) {
|
||||
setEnergyStored(getEnergyStored() - RF_USE_PER_TICK);
|
||||
}
|
||||
|
||||
if(!hasPower() && requiresPower) {
|
||||
isActivated = false;
|
||||
}
|
||||
@@ -127,6 +145,41 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
init = false;
|
||||
lastActive = isActivated;
|
||||
}
|
||||
|
||||
if (isWireless) {
|
||||
if (ticksSinceLastSearch > 50) {
|
||||
charger = findNearestCharger();
|
||||
ticksSinceLastSearch = 0;
|
||||
} else {
|
||||
ticksSinceLastSearch++;
|
||||
}
|
||||
|
||||
if (charger != null && energyStoredRF < getMaxEnergyStored()) {
|
||||
this.energyStoredRF += charger.takeEnergy(Math.min(getMaxEnergyStored() - energyStoredRF, 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IWirelessCharger findNearestCharger() {
|
||||
int minDist = Integer.MAX_VALUE;
|
||||
BlockCoord charger = null;
|
||||
Map<BlockCoord, IWirelessCharger> map = WirelessChargerController.instance.getChargerMap(worldObj);
|
||||
for (BlockCoord b : map.keySet()) {
|
||||
int dist = b.distance(new BlockCoord(this));
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
charger = b;
|
||||
}
|
||||
}
|
||||
|
||||
if (charger != null && minDist < Config.wirelessChargerRange) {
|
||||
TileEntity te = charger.getTileEntity(worldObj);
|
||||
if (te instanceof IWirelessCharger) {
|
||||
return (IWirelessCharger) te;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onBlockRemoved() {
|
||||
@@ -332,6 +385,7 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
face = ForgeDirection.values()[root.getShort("face")];
|
||||
isInvereted = root.getBoolean("isInverted");
|
||||
requiresPower = root.getBoolean("requiresPower");
|
||||
isWireless = root.getBoolean("isWireless");
|
||||
|
||||
if(root.hasKey("storedEnergy")) {
|
||||
float se = root.getFloat("storedEnergy");
|
||||
@@ -350,6 +404,7 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
|
||||
root.setInteger("storedEnergyRF", energyStoredRF);
|
||||
root.setBoolean("isInverted", isInvereted);
|
||||
root.setBoolean("requiresPower", requiresPower);
|
||||
root.setBoolean("isWireless", isWireless);
|
||||
|
||||
if(lightNodes != null) {
|
||||
int[] lnLoc = new int[lightNodes.size() * 3];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package crazypants.enderio.machine.wireless;
|
||||
|
||||
import crazypants.util.BlockCoord;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public interface IWirelessCharger {
|
||||
|
||||
@@ -11,5 +11,6 @@ public interface IWirelessCharger {
|
||||
BlockCoord getLocation();
|
||||
|
||||
boolean chargeItems(ItemStack[] armorInventory);
|
||||
|
||||
|
||||
int takeEnergy(int max);
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
@@ -51,7 +51,7 @@ public class TileWirelessCharger extends TileEntityEio implements IInternalPower
|
||||
(lastPowerUpdate != storedEnergyRF && worldObj.getTotalWorldTime() % 20 == 0)
|
||||
) {
|
||||
lastPowerUpdate = storedEnergyRF;
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketStoredEnergy(this), this);
|
||||
PacketHandler.sendToAllAround(new PacketStoredEnergy(this), this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -126,6 +126,13 @@ public class TileWirelessCharger extends TileEntityEio implements IInternalPower
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int takeEnergy(int max) {
|
||||
int prev = storedEnergyRF;
|
||||
storedEnergyRF = Math.max(0, storedEnergyRF - max);
|
||||
return prev - storedEnergyRF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package crazypants.enderio.machine.wireless;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import scala.Array;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -17,8 +12,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.item.darksteel.DarkSteelController;
|
||||
import crazypants.enderio.item.darksteel.DarkSteelRecipeManager;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class WirelessChargerController {
|
||||
@@ -93,5 +86,11 @@ public class WirelessChargerController {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public Collection<IWirelessCharger> getChargers(World world) {
|
||||
return getChargerMap(world).values();
|
||||
}
|
||||
|
||||
public Map<BlockCoord, IWirelessCharger> getChargerMap(World world) {
|
||||
return perWorldChargers.get(world.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package crazypants.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class BlockCoord {
|
||||
@@ -41,6 +43,14 @@ public final class BlockCoord {
|
||||
double dsq = distanceSquared(other);
|
||||
return (int)Math.ceil(Math.sqrt(dsq));
|
||||
}
|
||||
|
||||
public Block getBlock(World world) {
|
||||
return world.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
public TileEntity getTileEntity(World world) {
|
||||
return world.getTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -78,5 +88,4 @@ public final class BlockCoord {
|
||||
public boolean equals(int xCoord, int yCoord, int zCoord) {
|
||||
return x == xCoord && y == yCoord && z == zCoord;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user