Created
December 17, 2014 18:28
-
-
Save Draco18s/9d5cacd98bb87f01ef04 to your computer and use it in GitHub Desktop.
Gravity effected and distance-support Stone Replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.draco18s.hazards.block; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
import com.draco18s.hardlib.HashUtils; | |
import com.draco18s.hazards.StoneRegistry; | |
import com.draco18s.hazards.block.helper.UnstableStoneHelper; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.client.renderer.texture.IIconRegister; | |
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.IIcon; | |
import net.minecraft.util.StatCollector; | |
import net.minecraft.util.Vec3; | |
import net.minecraft.world.Explosion; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
public class BlockUnstableStone extends Block{ | |
private IIcon[] icons; | |
private IIcon[] ticons; | |
private boolean iconsSet = false; | |
public BlockUnstableStone(String origName, String textureName) { | |
super(Material.rock); | |
setTickRandomly(true); | |
setHardness(2.0F); | |
setHarvestLevel("pickaxe", 0); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setBlockName(origName); | |
setStepSound(soundTypeStone); | |
setBlockTextureName(textureName); | |
} | |
@Override | |
public void registerBlockIcons(IIconRegister iconRegister) { | |
TextureAtlasSprite sprite; | |
this.icons = new IIcon[9]; | |
this.ticons = new IIcon[7]; | |
icons[1] = icons[0] = ((TextureAtlasSprite) iconRegister.registerIcon(this.textureName)); //base, original texture | |
for(int o = 0; o < 7; o++) { | |
ticons[o] = iconRegister.registerIcon("hazards:stone_overlay_"+o); //the common overlay texture | |
icons[o+2] = iconRegister.registerIcon(this.textureName+"_"+"damaged_"+o); //uniquely named, non-existent texture | |
} | |
} | |
@Override | |
public int tickRate(World p_149738_1_) { | |
return 50; | |
} | |
@SideOnly(Side.CLIENT) | |
@Override | |
public void getSubBlocks(Item unknown, CreativeTabs tab, List subItems) | |
{ | |
for (int ix = 0; ix < 4; ix++) { | |
subItems.add(new ItemStack(this, 1, ix)); | |
} | |
} | |
@Override | |
public void updateTick(World world, int x, int y, int z, Random par5Random) { | |
int meta = world.getBlockMetadata(x, y, z); | |
switch(meta) { | |
case 0: | |
UnstableStoneHelper.updateUnstable(world, x, y, z, par5Random, this, meta); | |
break; | |
case 1: | |
UnstableStoneHelper.updateFractured(world, x, y, z, par5Random, this, meta); | |
break; | |
case 2: | |
UnstableStoneHelper.updateBroken(world, x, y, z, par5Random, this, meta); | |
break; | |
case 3: | |
UnstableStoneHelper.updateCobble(world, x, y, z, par5Random, this, meta); | |
break; | |
} | |
} | |
@SideOnly(Side.CLIENT) | |
@Override | |
public IIcon getIcon(IBlockAccess world, int xx, int yy, int zz, int side) { | |
int meta = world.getBlockMetadata(xx, yy, zz); | |
if(meta == 1 && side > 1) { | |
int ch = (xx - yy + zz) % 16; | |
switch(Math.abs(ch)) { | |
case 0: | |
case 11: | |
return this.icons[5]; | |
case 1: | |
case 10: | |
return this.icons[6]; | |
case 2: | |
case 9: | |
return this.icons[7]; | |
case 3: | |
case 8: | |
return this.icons[8]; | |
} | |
return this.icons[4]; | |
} | |
return this.getIcon(side, meta); | |
} | |
@SideOnly(Side.CLIENT) | |
@Override | |
public IIcon getIcon(int side, int metadata) { | |
if(!iconsSet) { | |
TextureAtlasSprite temp; | |
int[][] overlay; | |
int[][] base; | |
int[][] newIconData; | |
int sr, sg, sb; | |
float sa; | |
int dr, dg, db; | |
for(int o = 0; o < 7; o++) { | |
overlay = StoneRegistry.getIconOverlay(o); | |
if(overlay == null) { | |
temp = (TextureAtlasSprite)ticons[o]; | |
overlay = temp.getFrameTextureData(0); | |
StoneRegistry.setIconOverlay(overlay.clone()); | |
} | |
base = ((TextureAtlasSprite)icons[0]).getFrameTextureData(0); | |
//combine { | |
newIconData = base.clone(); | |
for(int x=0; x < newIconData.length; x++) { | |
for(int y=0; y < newIconData[x].length; y++) { | |
sa = (overlay[x][y] >> 24 & 255)/255f; | |
sr = overlay[x][y] >> 16 & 255; | |
sg = overlay[x][y] >> 8 & 255; | |
sb = overlay[x][y] >> 0 & 255; | |
//da = 0xFF; | |
dr = newIconData[x][y] >> 16 & 255; | |
dg = newIconData[x][y] >> 8 & 255; | |
db = newIconData[x][y] >> 0 & 255; | |
dr = (int) (sr*sa + dr*(1-sa)); | |
dg = (int) (sg*sa + dg*(1-sa)); | |
db = (int) (sb*sa + db*(1-sa)); | |
newIconData[x][y] = (dr<<16) + (dg<<8) + (db); | |
} | |
} | |
//} | |
//icons[o+2] = iconRegister.registerIcon("damaged_"+o+"_"+this.textureName); | |
List data = new ArrayList(); | |
data.add(newIconData); | |
((TextureAtlasSprite)icons[o+2]).setFramesTextureData(data); | |
} | |
} | |
if(metadata > 3) { | |
metadata = 3; | |
} | |
return this.icons[metadata]; | |
} | |
@Override | |
public Item getItemDropped(int par1, Random par2Random, int par3) { | |
return Item.getItemFromBlock(Blocks.cobblestone); | |
} | |
@Override | |
public void onBlockAdded(World world, int x, int y, int z) { | |
this.updateTick(world, x, y, z, world.rand); | |
} | |
@Override | |
public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tx, int ty, int tz) { | |
this.updateTick((World)world, x, y, z, ((World)world).rand); | |
} | |
@Override | |
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) { | |
world.scheduleBlockUpdate(x, y, z, this, 6 + new Random().nextInt(6)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment