package net.fourbytes.shadow.blocks;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
import net.fourbytes.shadow.*;
import net.fourbytes.shadow.entities.Player;

import java.util.Random;

public class BlockTorch extends BlockType {
	
	int subframe = 0;
	int frame = 0;
	
	int wall = 0;
	
	public BlockTorch() {
	}
	
	public static Random rand = new Random();
	
	@Override 
	public void tick() {
		subframe += rand.nextInt(5);
		block.solid = false;
		block.passSunlight = true;
		block.light.set(0.75f, 0.5f, 0.25f, 1f);
		if (subframe > 12) {
			frame++;
			subframe = 0;
			imgupdate = true;
		}
		if (frame >= 4) {
			frame = 0;
			block.pixdur = rand.nextInt(20)+20;
		}
		
		wall = 0;
		block.renderoffs.width = 0f;
		block.renderoffs.x = 0f;
		Array<Block> al = block.layer.get(Coord.get(block.pos.x+1f, block.pos.y));
		if (al != null && al.size != 0) {
			for (Block bb : al) {
				if (bb.solid) {
					wall = 1;
					block.renderoffs.width = -2f;
					block.renderoffs.x = 1f;
					break;
				}
			}
		}
		al = block.layer.get(Coord.get(block.pos.x-1f, block.pos.y));
		if (al != null && al.size != 0) {
			for (Block bb : al) {
				if (bb.solid) {
					wall = -1;
					break;
				}
			}
		}
		
	}
	
	@Override
	public TextureRegion getTexture() {
		TextureRegion[][] regs = Images.split("block_torch", 16, 16);
		TextureRegion reg = null;
		reg = regs[frame][wall==0?0:1];
		return reg;
	}
	
	@Override
	public void collide(Entity e) {
		super.collide(e);
		if (e instanceof Player) {
			Sounds.getSound("hurt").play(1f, Sounds.calcPitch(1f, 0.2f), 0f);
			Player p = (Player) e;
			p.hurt(block, 0.05f);
			p.hit(block);
		}
	}
	
}

@@ -267,18 +267,17 @@
 kType %7B%0A
-%09
 %0A
+
 %09int sub
@@ -303,18 +303,17 @@
 me = 0;%0A
-%09
 %0A
+
 %09int wal
@@ -319,18 +319,17 @@
 ll = 0;%0A
-%09
 %0A
+
 %09public 
@@ -346,18 +346,17 @@
 () %7B%0A%09%7D%0A
-%09
 %0A
+
 %09public 
@@ -390,17 +390,16 @@
 ndom();%0A
-%09
 %0A%09@Overr
@@ -401,17 +401,16 @@
 Override
- 
 %0A%09public
@@ -699,17 +699,19 @@
 (20)
-+
+ + 
 20;%0A%09%09%7D%0A
 %09%09%0A%09
@@ -706,19 +706,17 @@
 20;%0A%09%09%7D%0A
-%09%09
 %0A
+
 %09%09wall =
@@ -834,17 +834,19 @@
 ck.pos.x
-+
+ + 
 1f, bloc
@@ -1088,17 +1088,19 @@
 ck.pos.x
--
+ - 
 1f, bloc
@@ -1238,16 +1238,13 @@
 %09%09%7D%0A
-%09%09
 %0A
+
 %09%7D%0A
-%09
 %0A
+
 %09@Ov
@@ -1407,14 +1407,20 @@
 wall
+ 
 ==
-0?0:
+ 0 ? 0 : 
 1%5D;%0A
@@ -1436,18 +1436,17 @@
 reg;%0A%09%7D%0A
-%09
 %0A
+
 %09@Overri
@@ -1562,17 +1562,19 @@
 %22).play(
-1
+0.6
 f, Sound
@@ -1676,12 +1676,11 @@
 %0A%09%09%7D%0A%09%7D%0A
-%09
 %0A%7D%0A

Test commit via IntelliJ. I only wanted to decrease the hurt volume...