Jump to content

Recommended Posts

Posted

updating mod from 1.6.4 to 1.7.10. The lanterns will not change faces when redstone is emitted and the sounds won't play upon redstone signal. Have an error on return type.sound, but cant figure out how to do it another way. Thanks.

 

package com.gellegbs.lanterns.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import com.gellegbs.lanterns.Lanterns;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockMobLantern extends BlockDirectional {

private BlockType type;
private CreativeTabs displayOnCreativeTab;

public BlockMobLantern(BlockType type) {
	super(Material.gourd);
	this.type = type;
	this.setCreativeTab(Lanterns.tabMobLanterns);
	this.setLightLevel(1F);
	this.setBlockName(this.type.unlocalizedName);
}

// icon junk


@SideOnly(Side.CLIENT)
private IIcon topIcon;
@SideOnly(Side.CLIENT)
private IIcon faceIcon;
@SideOnly(Side.CLIENT)
private IIcon blockIcon;
@SideOnly(Side.CLIENT)
private IIcon activeFaceIcon;


@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister register) {
	topIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":"
			+ type.textureTop);
	faceIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":"
			+ type.textureFront);
	blockIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":"
			+ type.textureSide);
	activeFaceIcon = register.registerIcon(BlockIds.TEXTURE_LOCATION + ":"
			+ type.textureSideActive);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int metadata) {

	if (side == 0 || side == 1) {
		return this.topIcon;
	}

	// metadata holds the block side with the face on in the lower 3 bits (0xxx),
	// and if its active or not in the highest bit. (x000)
	if ((metadata & 7) == side) {
		boolean isActive = (metadata &  > 0;
		return (isActive) ? this.activeFaceIcon : this.faceIcon;
	}

	return this.blockIcon;
}


@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
		EntityLivingBase entity, ItemStack itemstack) {
	int whichDirectionFacing = MathHelper
			.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;

	// map the facing to the block side with the face and store it as metadata.
	// mapping is as follows: Facing -> BlockSideWithFace
	//                             0 -> 3
	//                             1 -> 4
	//                             2 -> 2
	//                             3 -> 5
	//
	// we just check against 0,1 and 3 as 2 would be fine by itself.
	int blockSideWithFace = whichDirectionFacing;
	if (whichDirectionFacing == 0) blockSideWithFace = 3;
	else if (whichDirectionFacing == 1) blockSideWithFace = 4;
	else if (whichDirectionFacing == 3) blockSideWithFace = 5;

	world.setBlockMetadataWithNotify(x, y, z, blockSideWithFace, 2);
	this.updateBlock(world, x, y, z, blockSideWithFace);
}


public void onNeighborBlockChange(World world, int x, int y, int z, int par5) {
	if (!world.isRemote) {
		this.updateBlock(world, x, y, z, world.getBlockMetadata(x, y, z));
	}
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	if (!world.isRemote) {
		this.updateBlock(world, x, y, z, world.getBlockMetadata(x, y, z));
	}
}


public void updateBlock(World world, int x, int y, int z, int currentMeta) {
	if (!world.isRemote) {
		boolean isActive = (currentMeta &  > 0;
		boolean redstoneSignal = world.isBlockIndirectlyGettingPowered(x, y, z);

		if (redstoneSignal) {
			if (!isActive) {
				if (type.sound != null) {
					return (type.sound);

				}
				currentMeta = (currentMeta & 7) + 8;
				world.setBlockMetadataWithNotify(x, y, z, currentMeta, 2);
			}
		} else {
			if (isActive) {
				world.setBlockMetadataWithNotify(x, y, z, (currentMeta & 7), 2);
			}
		}
	}
}
}

 

more relevant classes

 

package com.gellegbs.lanterns.blocks;

public enum BlockType {

    // lanterns
    BLAZE(BlockIds.BLAZE_BLOCK_NAME, "mob.blaze.breathe", BlockIds.BLAZETOP, BlockIds.BLAZEFRONT,
            BlockIds.BLAZESIDE, BlockIds.BLAZESIDEACTIVE, 0),

    CREEPER(BlockIds.CREEPER_BLOCK_NAME, "random.fuse", BlockIds.CREEPERTOP, BlockIds.CREEPERFRONT,
            BlockIds.CREEPERSIDE, BlockIds.CREEPERSIDEACTIVE, 0),

    ENDERMEN(BlockIds.ENDERMEN_BLOCK_NAME, "mob.endermen.stare", BlockIds.ENDERMENTOP, BlockIds.ENDERMENFRONT,
            BlockIds.ENDERMENSIDE, BlockIds.ENDERMENSIDEACTIVE, 0),

    GHAST(BlockIds.GHAST_BLOCK_NAME, "mob.ghast.scream", BlockIds.GHASTTOP, BlockIds.GHASTFRONT,
            BlockIds.GHASTSIDE, BlockIds.GHASTSIDEACTIVE, 0),

    JACKO(BlockIds.JACKOLANTERN_BLOCK_NAME, null, BlockIds.JACKOLANTERNTOP, BlockIds.JACKOLANTERNFRONT,
            BlockIds.JACKOLANTERNSIDE, BlockIds.JACKOLANTERNFRONT, 0),

    MAGMA_CUBE(BlockIds.MAGMA_BLOCK_NAME, "mob.slime.attack", BlockIds.MAGMATOP, BlockIds.MAGMAFRONT,
            BlockIds.MAGMASIDE, BlockIds.MAGMASIDEACTIVE, 0),

    PIGMEN(BlockIds.PIGMEN_BLOCK_NAME, "mob.zombiepig.zpigangry", BlockIds.PIGMENTOP, BlockIds.PIGMENFRONT,
            BlockIds.PIGMENSIDE, BlockIds.PIGMENSIDEACTIVE, 0),

    SKELETON(BlockIds.SKELETON_BLOCK_NAME, "mob.skeleton.say", BlockIds.SKELETONTOP, BlockIds.SKELETONFRONT,
            BlockIds.SKELETONSIDE, BlockIds.SKELETONSIDEACTIVE, 0),

    SLIME(BlockIds.SLIME_BLOCK_NAME, "mob.slime.big", BlockIds.SLIMETOP, BlockIds.SLIMEFRONT, BlockIds.SLIMESIDE,
            BlockIds.SLIMESIDEACTIVE, 0),

    SPIDER(BlockIds.SPIDER_BLOCK_NAME, "mob.spider.say", BlockIds.SPIDERTOP, BlockIds.SPIDERFRONT,
            BlockIds.SPIDERSIDE, BlockIds.SPIDERSIDEACTIVE, 0),

    WITHER_SKELETON(BlockIds.WITHERSKELE_BLOCK_NAME, "mob.skeleton.step", BlockIds.WITHERSKELETOP,
            BlockIds.WITHERSKELEFRONT, BlockIds.WITHERSKELESIDE, BlockIds.WITHERSKELESIDEACTIVE, 0),

    ZOMBIE(BlockIds.ZOMBIE_BLOCK_NAME, "mob.zombie.say", BlockIds.ZOMBIETOP, BlockIds.ZOMBIEFRONT,
            BlockIds.ZOMBIESIDE, BlockIds.ZOMBIESIDEACTIVE, 0),

    // spawners

    BLAZESPAWN(BlockIds.BLAZESPAWN_BLOCK_NAME, null, BlockIds.BLAZESPAWNTOP, BlockIds.BLAZESPAWNSIDE,
            BlockIds.BLAZESPAWNSIDE, BlockIds.BLAZESPAWNSIDE, 61),

    CREEPERSPAWN(BlockIds.CREEPERSPAWN_BLOCK_NAME, null, BlockIds.CREEPERSPAWNTOP, BlockIds.CREEPERSIDESPAWN,
            BlockIds.CREEPERSIDESPAWN, BlockIds.CREEPERSIDESPAWN, 50),

    ENDERMENSPAWN(BlockIds.ENDERMENSPAWN_BLOCK_NAME, null, BlockIds.ENDERMENSPAWNTOP, BlockIds.ENDERMENSPAWNSIDE,
            BlockIds.ENDERMENSPAWNSIDE, BlockIds.ENDERMENSPAWNSIDE, 58),

    GHASTSPAWN(BlockIds.GHASTSPAWN_BLOCK_NAME, null, BlockIds.GHASTSPAWNTOP, BlockIds.GHASTSPAWNSIDE,
            BlockIds.GHASTSPAWNSIDE, BlockIds.GHASTSPAWNSIDE, 56),

    MAGMASPAWN(BlockIds.MAGMASPAWN_BLOCK_NAME, null, BlockIds.MAGMASPAWNTOP, BlockIds.MAGMASPAWNSIDE,
            BlockIds.MAGMASPAWNSIDE, BlockIds.MAGMASPAWNSIDE, 62),

    PIGMENSPAWN(BlockIds.PIGMENSPAWN_BLOCK_NAME, null, BlockIds.PIGMENSPAWNTOP, BlockIds.PIGMENSPAWNSIDE,
            BlockIds.PIGMENSPAWNSIDE, BlockIds.PIGMENSPAWNSIDE, 57),

    SKELETONSPAWN(BlockIds.SKELETONSPAWN_BLOCK_NAME, null, BlockIds.SKELETONSPAWNTOP, BlockIds.SKELETONSPAWNSIDE,
            BlockIds.SKELETONSPAWNSIDE, BlockIds.SKELETONSPAWNSIDE, 51),

    SLIMESPAWN(BlockIds.SLIMESPAWN_BLOCK_NAME, null, BlockIds.SLIMESPAWNTOP, BlockIds.SLIMESPAWNSIDE,
            BlockIds.SLIMESPAWNSIDE, BlockIds.SLIMESPAWNSIDE, 55),

    SPIDERSPAWN(BlockIds.SPIDERSPAWN_BLOCK_NAME, null, BlockIds.SPIDERSPAWNTOP, BlockIds.SLIMESPAWNSIDE,
            BlockIds.SPIDERSPAWNSIDE, BlockIds.SPIDERSPAWNSIDE, 52),

    WITHERSKELESPAWN(BlockIds.WITHERSKELESPAWN_BLOCK_NAME, null, BlockIds.WITHERSKELESPAWNTOP,
            BlockIds.WITHERSKELESPAWNSIDE, BlockIds.WITHERSKELESPAWNSIDE, BlockIds.WITHERSKELESPAWNSIDE, 51),

    ZOMBIESPAWN(BlockIds.ZSPAWN_BLOCK_NAME, null, BlockIds.ZSPAWNTOP, BlockIds.ZSPAWNSIDE, BlockIds.ZSPAWNSIDE,
            BlockIds.ZSPAWNSIDE, 54),

    WITCHSPAWN(BlockIds.WITCHSPAWN_BLOCK_NAME, null, BlockIds.WITCHSPAWN_TOP, BlockIds.WITCHSPAWN_SIDE,
            BlockIds.WITCHSPAWN_SIDE, BlockIds.WITCHSPAWN_SIDE, 66),

    GIANTSPAWN(BlockIds.GIANTSPAWN_BLOCK_NAME, null, BlockIds.GIANTSPAWN_TOP, BlockIds.GIANTSPAWN_SIDE,
            BlockIds.GIANTSPAWN_SIDE, BlockIds.GIANTSPAWN_SIDE, 53);
    

    

    public final String unlocalizedName, sound, textureTop, textureFront, textureSide, textureSideActive;
    public int spawnerid;

    BlockType(String unlocalizedName, String sound, String textureTop, String textureFront, String textureSide,
            String textureSideActive, int spawnerid) {
        this.unlocalizedName = unlocalizedName;
        this.sound = sound;
        this.textureTop = textureTop;
        this.textureFront = textureFront;
        this.textureSide = textureSide;
        this.textureSideActive = textureSideActive;
        this.spawnerid = spawnerid;

    }
    
    
}

Posted

Changed things up a bit but sound will not work. I do not know how to use the playSound method from Entity.class in this instance that extends BlockDirectional.class and Block.class. Anyone know how to do this?

 

here is the method giving me grief the line errored is "this.playSound(type.sound);":

public void updateBlock(World world, int x, int y, int z, int currentMeta) {
	if (!world.isRemote) {
		boolean isActive = (currentMeta &  > 0;
		boolean redstoneSignal = world.isBlockIndirectlyGettingPowered(x, y, z);

		if (redstoneSignal) {
			if (!isActive) {
				if (type.sound != null) {
					this.playSound(type.sound);

				}
				currentMeta = (currentMeta & 7) + 8;
				world.setBlockMetadataWithNotify(x, y, z, currentMeta, 2);
			}
		} else {
			if (isActive) {
				world.setBlockMetadataWithNotify(x, y, z, (currentMeta & 7), 2);
			}
		}
	}

Posted

do I use that even if I am using existing vanilla mob sounds?

No, you can use the vanilla sounds provided you have the right sound name (which it looks like you do).

 

Your problem is you are misunderstanding the various playSound methods; using the ones in the World class, you have World#playSoundAtEntity and World#playSoundEffect, both of which should be used on the server and will notify nearby clients of the sound to play, and then you have the Entity playSound methods, which should be used on the client and are only heard by that client.

 

A typical example of playing a sound on the server, so everyone can here it:

world.playSoundEffect(x, y, z, sound, volume, pitch);

// with arguments:
world.playSoundEffect(x, y, z, "random.fuse", 1.0F, 1.0F);

Posted

Thank you that was extremely helpful. I was not aware of the different playSound methods and you really cleared it up for me. I appreciate the help!

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.