Added multiside texture
- Method name different but is registerIcons() instead of registerBlockIcons() - Prepare sounds implementation
This commit is contained in:
parent
c37172feaf
commit
c4053e0595
@ -17,7 +17,7 @@ buildscript {
|
|||||||
|
|
||||||
apply plugin: 'forge'
|
apply plugin: 'forge'
|
||||||
|
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
group = "fr.jcs.bigalarm"
|
group = "fr.jcs.bigalarm"
|
||||||
archivesBaseName = "BigAlarm"
|
archivesBaseName = "BigAlarm"
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ sourceCompatibility = 1.7
|
|||||||
targetCompatibility = 1.7
|
targetCompatibility = 1.7
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "1.7.10-10.13.4.1558-1.7.10"
|
version = "1.7.10-10.13.4.1566-1.7.10"
|
||||||
replace '${version}', project.version
|
replace '${version}', project.version
|
||||||
mappings = 'stable_12'
|
mappings = 'stable_12'
|
||||||
runDir = "eclipse"
|
runDir = "eclipse"
|
||||||
|
@ -5,18 +5,22 @@ import cpw.mods.fml.common.SidedProxy;
|
|||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
import cpw.mods.fml.common.Mod.Instance;
|
import cpw.mods.fml.common.Mod.Instance;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import fr.jcs.bigalarm.blocks.AlarmBlock;
|
import fr.jcs.bigalarm.blocks.AlarmBlock;
|
||||||
import fr.jcs.bigalarm.proxy.CommonProxy;
|
import fr.jcs.bigalarm.proxy.CommonProxy;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
@Mod(modid = BigAlarmRefs.MOD_ID, name = BigAlarmRefs.MOD_NAME, version = "@VERSION@", canBeDeactivated = false, dependencies = "")
|
@Mod(modid = BigAlarmRefs.MOD_ID, name = BigAlarmRefs.MOD_NAME, version = "@VERSION@", canBeDeactivated = false, dependencies = "")
|
||||||
public class BigAlarm {
|
public class BigAlarm {
|
||||||
@Instance
|
@Instance(BigAlarmRefs.MOD_ID)
|
||||||
public static BigAlarm instance;
|
public static BigAlarm instance;
|
||||||
|
|
||||||
@SidedProxy(clientSide = BigAlarmRefs.PROXY_CLIENT, serverSide = BigAlarmRefs.PROXY_SERVER)
|
@SidedProxy(clientSide = BigAlarmRefs.PROXY_CLIENT, serverSide = BigAlarmRefs.PROXY_SERVER)
|
||||||
public static CommonProxy proxy;
|
public static CommonProxy proxy;
|
||||||
|
public static final SimpleNetworkWrapper netWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(BigAlarmRefs.MOD_ID);
|
||||||
|
|
||||||
public static AlarmBlock alarmBlock;
|
public static AlarmBlock alarmBlock;
|
||||||
|
|
||||||
@ -32,6 +36,7 @@ public class BigAlarm {
|
|||||||
System.out.println("[BigAlarm]: Connecting speakers...");
|
System.out.println("[BigAlarm]: Connecting speakers...");
|
||||||
alarmBlock = new AlarmBlock();
|
alarmBlock = new AlarmBlock();
|
||||||
GameRegistry.registerBlock(alarmBlock, "alarmBlock");
|
GameRegistry.registerBlock(alarmBlock, "alarmBlock");
|
||||||
|
//netWrapper.registerMessage(messageHandler, requestMessageType, 0, Side.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -1,33 +1,64 @@
|
|||||||
package fr.jcs.bigalarm.blocks;
|
package fr.jcs.bigalarm.blocks;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import fr.jcs.bigalarm.BigAlarmRefs;
|
import fr.jcs.bigalarm.BigAlarmRefs;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class AlarmBlock extends BlockContainer {
|
public class AlarmBlock extends BlockContainer {
|
||||||
|
private IIcon iconAlarm;
|
||||||
|
|
||||||
public AlarmBlock() {
|
public AlarmBlock() {
|
||||||
super(Material.iron);
|
super(Material.iron);
|
||||||
this.setHardness(5.0F);
|
setHardness(5.0F);
|
||||||
this.setResistance(4.0F);
|
setResistance(20.0F);
|
||||||
this.setStepSound(soundTypeMetal);
|
this.setStepSound(soundTypeMetal);
|
||||||
this.setUnlocalizedName(BigAlarmRefs.MOD_ID + ":alarmBlock");
|
this.setUnlocalizedName(BigAlarmRefs.MOD_ID + ":alarmBlock");
|
||||||
this.setTextureName(BigAlarmRefs.MOD_ID + ":alarmBlock/front");
|
this.setTextureName(BigAlarmRefs.MOD_ID + ":default");
|
||||||
this.setCreativeTab(CreativeTabs.tabDecorations);
|
this.setCreativeTab(CreativeTabs.tabDecorations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void registerIcons(IIconRegister iconRegister) { //Method name different but is registerBlockIcons()
|
||||||
|
this.blockIcon = iconRegister.registerIcon(BigAlarmRefs.MOD_ID + ":alarmBlock/side");
|
||||||
|
this.iconAlarm = iconRegister.registerIcon(BigAlarmRefs.MOD_ID + ":alarmBlock/top");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public IIcon getIcon(int side, int meta)
|
||||||
|
{
|
||||||
|
/*if (side == 1) { //Simplified sentence below
|
||||||
|
return this.iconAlarm;
|
||||||
|
} else {
|
||||||
|
return this.blockIcon;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return side == 1 ? this.iconAlarm : this.blockIcon;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
|
return side == 1 ? this.iconAlarm : this.blockIcon;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFullBlock()
|
public boolean isFullBlock()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBlockNormalCube() {
|
public boolean isBlockNormalCube() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package fr.jcs.bigalarm.tileentitys;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import fr.jcs.bigalarm.BigAlarmRefs;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
|
public class TileEntityAlarm extends TileEntity {
|
||||||
|
private static final String DEFAULT_SOUND_NAME = "default";
|
||||||
|
private static final float BASE_SOUND_RANGE = 16F;
|
||||||
|
private static final String SOUND_PREFIX = BigAlarmRefs.MOD_ID + ":alarm-";
|
||||||
|
|
||||||
|
public int range;
|
||||||
|
private int prevRange;
|
||||||
|
public String soundName;
|
||||||
|
private String prevSoundName;
|
||||||
|
|
||||||
|
private int updateTicker;
|
||||||
|
protected int tickRate;
|
||||||
|
private TileEntitySound sound;
|
||||||
|
|
||||||
|
public TileEntityAlarm() {
|
||||||
|
soundName = "";
|
||||||
|
//range = IC2NuclearControl.instance.alarmRange;
|
||||||
|
range = 0;
|
||||||
|
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||||
|
sound = new TileEntitySound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRange() {
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRange(int r) {
|
||||||
|
range = r;
|
||||||
|
if (prevRange != r) {
|
||||||
|
//IC2.network.get().updateTileEntityField(this, "range");
|
||||||
|
}
|
||||||
|
prevRange = range;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSoundName() {
|
||||||
|
return soundName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoundName(String name) {
|
||||||
|
soundName = name;
|
||||||
|
if (prevSoundName != name){
|
||||||
|
//IC2.network.get().updateTileEntityField(this, "soundName");
|
||||||
|
}
|
||||||
|
prevSoundName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
super.readFromNBT(nbttagcompound);
|
||||||
|
if (nbttagcompound.hasKey("soundName")) {
|
||||||
|
prevSoundName = soundName = nbttagcompound.getString("soundName");
|
||||||
|
prevRange = range = nbttagcompound.getInteger("range");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
super.writeToNBT(nbttagcompound);
|
||||||
|
nbttagcompound.setString("soundName", soundName);
|
||||||
|
nbttagcompound.setInteger("range", range);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package fr.jcs.bigalarm.tileentitys;
|
||||||
|
|
||||||
|
import fr.jcs.bigalarm.utils.SoundHelper;
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
|
||||||
|
public class TileEntitySound {
|
||||||
|
private PositionedSoundRecord sound;
|
||||||
|
|
||||||
|
public TileEntitySound() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopAlarm() {
|
||||||
|
if (sound != null) {
|
||||||
|
SoundHelper.stopAlarm(sound);
|
||||||
|
sound = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playAlarm(double x, double y, double z, String soundName,
|
||||||
|
float range, boolean skipCheck) {
|
||||||
|
if (sound == null || skipCheck) {
|
||||||
|
sound = SoundHelper.playAlarm(x, y, z, soundName, range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlaying() {
|
||||||
|
if (sound == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return SoundHelper.isPlaying(sound);
|
||||||
|
}
|
||||||
|
}
|
24
src/main/java/fr/jcs/bigalarm/utils/LogHelper.java
Normal file
24
src/main/java/fr/jcs/bigalarm/utils/LogHelper.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package fr.jcs.bigalarm.utils;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLLog;
|
||||||
|
import fr.jcs.bigalarm.BigAlarmRefs;
|
||||||
|
|
||||||
|
public class LogHelper {
|
||||||
|
public static void log(Level logLevel, Object object) {
|
||||||
|
FMLLog.log(BigAlarmRefs.MOD_ID, logLevel, String.valueOf(object), new Object[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(Object object) {
|
||||||
|
log(Level.ERROR, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(Object object) {
|
||||||
|
log(Level.INFO, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(Object object) {
|
||||||
|
log(Level.WARN, object);
|
||||||
|
}
|
||||||
|
}
|
44
src/main/java/fr/jcs/bigalarm/utils/SoundHelper.java
Normal file
44
src/main/java/fr/jcs/bigalarm/utils/SoundHelper.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package fr.jcs.bigalarm.utils;
|
||||||
|
|
||||||
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public class SoundHelper {
|
||||||
|
private static final float DEFAULT_RANGE = 16F;
|
||||||
|
|
||||||
|
private static void playSound(PositionedSoundRecord sound) {
|
||||||
|
Minecraft.getMinecraft().getSoundHandler().playSound(sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PositionedSoundRecord playAlarm(double x, double y, double z,
|
||||||
|
String name, float volume) {
|
||||||
|
float range = DEFAULT_RANGE;
|
||||||
|
|
||||||
|
if (volume > 1.0F) {
|
||||||
|
range *= volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity person = FMLClientHandler.instance().getClient().renderViewEntity;
|
||||||
|
|
||||||
|
if (person != null && volume > 0
|
||||||
|
&& person.getDistanceSq(x, y, z) < range * range) {
|
||||||
|
PositionedSoundRecord sound = new PositionedSoundRecord(
|
||||||
|
new ResourceLocation(name), volume, 1.0F, (float) x,
|
||||||
|
(float) y, (float) z);
|
||||||
|
playSound(sound);
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isPlaying(PositionedSoundRecord sound) {
|
||||||
|
return Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopAlarm(PositionedSoundRecord sound) {
|
||||||
|
Minecraft.getMinecraft().getSoundHandler().stopSound(sound);
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 340 B |
Binary file not shown.
After Width: | Height: | Size: 305 B |
BIN
src/main/resources/assets/bigalarm/textures/blocks/default.png
Normal file
BIN
src/main/resources/assets/bigalarm/textures/blocks/default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 316 B |
Loading…
x
Reference in New Issue
Block a user