You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.7 KiB
Java

package net.brokenmoon.afloydwiremod.tile;
import net.brokenmoon.afloydwiremod.WireMod;
import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity;
import net.minecraft.src.*;
import java.util.Random;
public class RedstoneLinkTile extends ChipTile {
public RedstoneLinkTile(int i, Material material, boolean isActive) {
super(i, material);
this.isActive = isActive;
this.setTickOnLoad(true);
}
boolean isActive;
@Override
public boolean renderAsNormalBlock(){
return false;
}
public static void updateLinkBlockState(boolean flag, World world, int x, int y, int z) {
if (flag) {
world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileActive.blockID, 1);
System.out.println("activating");
}
if (!flag) {
world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileInactive.blockID, 1);
System.out.println("deactivating");
}
}
@Override
public int tickRate() {
return 2;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
if(world.getBlockMetadata(x, y, z) == 0){
world.setBlockTileEntity(x, y, z, new RedstoneLinkTileEntity());
}
}
@Override
public void onBlockRemoval(World world, int x, int y, int z) {
if(world.getBlockTileEntity(x, y, z) != null && !((RedstoneLinkTileEntity)world.getBlockTileEntity(x, y, z)).shouldnotremove)
super.onBlockRemoval(world, x, y, z);
}
@Override
public void updateTick(World world, int i, int j, int k, Random random) {
RedstoneLinkTileEntity link = (RedstoneLinkTileEntity)world.getBlockTileEntity(i, j, k);
if (world.isBlockGettingPowered(i, j, k)) {
link.outputs[0].floatvalue = 1.0f;
} else {
link.outputs[0].floatvalue = 0.0f;
}
}
@Override
public boolean canProvidePower() {
return true;
}
@Override
public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l) {
return this.isActive;
}
@Override
public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l) {
return this.isPoweringTo(world, i, j, k, l);
}
@Override
protected TileEntity getBlockEntity() {
return new RedstoneLinkTileEntity();
}
@Override
public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
world.scheduleBlockUpdate(i, j, k, this.blockID, this.tickRate());
}
@Override
public int idDropped(int i, Random random) {
return WireMod.LinkTileInactive.blockID;
}
@Override
protected int damageDropped(int i) {
return i;
}
}