#564 Added inverted powered lights and non-powered lights.

This commit is contained in:
CrazyPants committed 2014-06-12 20:44:47 +08:00
1 parent 40f4b1fb57
commit bb3e0b3026
9 files changed
+195 -53

No files matched your search

@@ -58,8 +58,4 @@ public abstract class BlockEio extends Block {
blockIcon = iIconRegister.registerIcon("enderio:" + name);
}
public String getUnlocalizedNameForTooltip(ItemStack stack) {
return getUnlocalizedName();
}
}
@@ -50,6 +50,7 @@ public enum ModObject {
blockElectricLight,
blockLightNode,
blockLight,
// Painter
blockPainter,
@@ -177,16 +177,23 @@ public class MachineRecipes {
GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "mcm", "crc", "mcm", 'm', metal, 'c', activatedCapacitor, 'r', Blocks.redstone_block));
}
//light
//powered light
ItemStack poweredLamp = new ItemStack(EnderIO.blockElectricLight, 1, 0);
ItemStack glowstone = new ItemStack(Items.glowstone_dust);
if(Config.useHardRecipes) {
GameRegistry.addRecipe(new ShapedOreRecipe(poweredLamp, "ggg", "sds", "scs", 'g', fusedQuartz, 'd', glowstone, 's', "itemSilicon", 'c', capacitor));
} else {
GameRegistry.addRecipe(new ShapedOreRecipe(poweredLamp, "ggg", "sds", "scs", 'g', "glass", 'd', glowstone, 's', "itemSilicon", 'c', capacitor));
}
}
ItemStack invPoweredLamp = new ItemStack(EnderIO.blockElectricLight, 1, 1);
GameRegistry.addShapelessRecipe(invPoweredLamp, poweredLamp, Blocks.redstone_torch);
//light
ItemStack lamp = new ItemStack(EnderIO.blockElectricLight, 1, 2);
GameRegistry.addRecipe(new ShapedOreRecipe(lamp, " ", "ggg", "isi", 'g', "glass", 's', Blocks.glowstone, 'i', Items.iron_ingot));
ItemStack invLamp = new ItemStack(EnderIO.blockElectricLight, 1, 3);
GameRegistry.addShapelessRecipe(invLamp, lamp, Blocks.redstone_torch);
//MJ Reader
ItemStack mJReader = new ItemStack(EnderIO.itemConduitProbe, 1, 0);
@@ -17,13 +17,13 @@ import crazypants.enderio.ModObject;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.vecmath.Vector3f;
public class BlockElectricLight extends BlockEio implements IResourceTooltipProvider {
public class BlockElectricLight extends BlockEio {
private static final float BLOCK_HEIGHT = 0.05f;
private static final float BLOCK_WIDTH = 0.3f;
static final float BLOCK_HEIGHT = 0.05f;
static final float BLOCK_WIDTH = 0.3f;
private static final float BLOCK_EDGE_MAX = 0.5f + (BLOCK_WIDTH / 2);
private static final float BLOCK_EDGE_MIN = 0.5f - (BLOCK_WIDTH / 2);
static final float BLOCK_EDGE_MAX = 0.5f + (BLOCK_WIDTH / 2);
static final float BLOCK_EDGE_MIN = 0.5f - (BLOCK_WIDTH / 2);
public static int renderId;
@@ -38,15 +38,13 @@ public class BlockElectricLight extends BlockEio implements IResourceTooltipProv
public BlockElectricLight() {
super(ModObject.blockElectricLight.unlocalisedName, TileElectricLight.class);
setLightOpacity(0);
setLightOpacity(0);
setBlockBounds(BLOCK_EDGE_MIN, 0.0F, BLOCK_EDGE_MIN, BLOCK_EDGE_MAX, BLOCK_HEIGHT, BLOCK_EDGE_MAX);
}
@Override
protected void init() {
GameRegistry.registerBlock(this, ModObject.blockElectricLight.unlocalisedName);
GameRegistry.registerBlock(this, BlockItemElectricLight.class, ModObject.blockElectricLight.unlocalisedName);
GameRegistry.registerTileEntity(TileElectricLight.class, ModObject.blockElectricLight.unlocalisedName + "TileEntity");
}
@@ -156,21 +154,6 @@ public class BlockElectricLight extends BlockEio implements IResourceTooltipProv
setBlockBounds(BLOCK_EDGE_MIN, 0.0F, BLOCK_EDGE_MIN, BLOCK_EDGE_MAX, BLOCK_HEIGHT, BLOCK_EDGE_MAX);
}
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
return side;
}
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int meta) {
ForgeDirection onFace = ForgeDirection.values()[meta].getOpposite();
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileElectricLight) {
((TileElectricLight) te).setFace(onFace);
}
world.setBlockMetadataWithNotify(x, y, z, 0, 0);
}
@Override
public boolean isOpaqueCube() {
return false;
@@ -199,9 +182,4 @@ public class BlockElectricLight extends BlockEio implements IResourceTooltipProv
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack stack) {
return getUnlocalizedName();
}
}
@@ -0,0 +1,88 @@
package crazypants.enderio.machine.light;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlockWithMetadata;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.material.BlockFusedQuartz;
import crazypants.util.Lang;
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);
final String unlocName;
final boolean isInverted;
final boolean isPowered;
private Type(String unlocName, boolean isInverted, boolean isPowered) {
this.unlocName = unlocName;
this.isInverted = isInverted;
this.isPowered = isPowered;
}
}
public BlockItemElectricLight(Block block) {
super(block, block);
setCreativeTab(EnderIOTab.tabEnderIO);
}
@Override
public String getUnlocalizedName(ItemStack par1ItemStack) {
int meta = par1ItemStack.getItemDamage();
meta = MathHelper.clamp_int(meta, 0, Type.values().length);
return Type.values()[meta].unlocName;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
for(Type type : Type.values()) {
par3List.add(new ItemStack(this,1,type.ordinal()));
}
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
if(!world.setBlock(x, y, z, field_150939_a, 0, 3)) {
return false;
}
if(world.getBlock(x, y, z) == field_150939_a) {
ForgeDirection onFace = ForgeDirection.values()[side].getOpposite();
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileElectricLight) {
TileElectricLight el = ((TileElectricLight) te);
el.setFace(onFace);
Type t= Type.values()[metadata];
el.setInverted(t.isInverted);
el.setRequiresPower(t.isPowered);
}
}
return true;
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName(itemStack);
}
}
@@ -39,6 +39,10 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
private boolean lastActive = false;
private boolean isInvereted;
private boolean requiresPower = true;
public TileElectricLight() {
powerHandler = PowerHandlerUtil.createHandler(Capacitors.BASIC_CAPACITOR.capacitor, this, Type.MACHINE);
}
@@ -65,6 +69,14 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
this.face = face;
}
public void setInverted(boolean inverted) {
isInvereted = inverted;
}
public void setRequiresPower(boolean isPowered) {
requiresPower = isPowered;
}
@Override
public void updateEntity() {
if(worldObj.isRemote) {
@@ -72,26 +84,34 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
}
boolean hasRedstone = hasRedstoneSignal();
double stored = powerHandler.getEnergyStored();
powerHandler.update();
powerHandler.setEnergy(stored);
if(hasRedstone) {
powerHandler.setEnergy(Math.max(0, powerHandler.getEnergyStored() - MJ_USE_PER_TICK));
if(requiresPower) {
double stored = powerHandler.getEnergyStored();
powerHandler.update();
powerHandler.setEnergy(stored);
}
boolean isActivated = hasPower() && hasRedstone;
if(init) {
boolean isActivated = (requiresPower ? hasPower() : true) && (hasRedstone && !isInvereted || !hasRedstone && isInvereted);
if(isActivated && requiresPower) {
powerHandler.setEnergy(Math.max(0, powerHandler.getEnergyStored() - MJ_USE_PER_TICK));
}
if(!hasPower() && requiresPower) {
isActivated = false;
}
if(init && requiresPower) {
updateLightNodes();
}
if(isActivated != lastActive || init) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActivated ? 1 : 0, 2);
for (TileLightNode ln : lightNodes) {
if(ln != null) {
worldObj.setBlockMetadataWithNotify(ln.xCoord, ln.yCoord, ln.zCoord, isActivated ? 1 : 0, 2);
worldObj.markBlockForUpdate(ln.xCoord, ln.yCoord, ln.zCoord);
worldObj.updateLightByType(EnumSkyBlock.Block, ln.xCoord, ln.yCoord, ln.zCoord);
if(requiresPower) {
for (TileLightNode ln : lightNodes) {
if(ln != null) {
worldObj.setBlockMetadataWithNotify(ln.xCoord, ln.yCoord, ln.zCoord, isActivated ? 1 : 0, 2);
worldObj.markBlockForUpdate(ln.xCoord, ln.yCoord, ln.zCoord);
worldObj.updateLightByType(EnumSkyBlock.Block, ln.xCoord, ln.yCoord, ln.zCoord);
}
}
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
@@ -102,6 +122,9 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
}
public void onBlockRemoved() {
if(!requiresPower) {
return;
}
updatingLightNodes = true;
try {
clearLightNodes();
@@ -111,6 +134,9 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
}
private void updateLightNodes() {
if(!requiresPower) {
return;
}
updatingLightNodes = true;
List<NodeEntry> before = new ArrayList<NodeEntry>(17);
if(lightNodes != null) {
@@ -296,6 +322,8 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
public void readCustomNBT(NBTTagCompound root) {
face = ForgeDirection.values()[root.getShort("face")];
isInvereted = root.getBoolean("isInverted");
requiresPower = root.getBoolean("requiresPower");
float storedEnergy = root.getFloat("storedEnergy");
powerHandler.setEnergy(storedEnergy);
@@ -307,6 +335,8 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
root.setShort("face", (short) face.ordinal());
root.setFloat("storedEnergy", (float) powerHandler.getEnergyStored());
root.setBoolean("isInverted", isInvereted);
root.setBoolean("requiresPower", requiresPower);
if(lightNodes != null) {
int[] lnLoc = new int[lightNodes.size() * 3];
@@ -330,6 +360,9 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
if(!requiresPower) {
return null;
}
return powerHandler.getPowerReceiver();
}
@@ -346,6 +379,9 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
if(!requiresPower) {
return 0;
}
return PowerHandlerUtil.recieveRedstoneFlux(from, powerHandler, maxReceive, simulate);
}
@@ -356,16 +392,25 @@ public class TileElectricLight extends TileEntityEio implements IInternalPowerRe
@Override
public boolean canConnectEnergy(ForgeDirection from) {
if(!requiresPower) {
return false;
}
return true;
}
@Override
public int getEnergyStored(ForgeDirection from) {
if(!requiresPower) {
return 0;
}
return (int) (powerHandler.getEnergyStored() * 10);
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
if(!requiresPower) {
return 0;
}
return (int) (powerHandler.getMaxEnergyStored() * 10);
}
@@ -137,4 +137,11 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
world.removeTileEntity(x, y, z);
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName();
}
}
@@ -137,4 +137,11 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
world.removeTileEntity(x, y, z);
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName();
}
}