From b3ca5b716807ddaf267a32f869fc3f631e4fc8a0 Mon Sep 17 00:00:00 2001 From: GotoLink Date: Mon, 20 Apr 2015 17:09:03 +0200 Subject: [PATCH] Update for 1.8 --- build.gradle | 3 +- .../blockstates/SatscapeAlarm.json | 5 + .../assets/satscapealarmcraft/lang/en_US.lang | 2 +- .../models/block/alarm.json | 20 ++ .../models/item/SatscapeAlarm.json | 10 + src/alarmcraft/client/ClientProxy.java | 25 ++- src/alarmcraft/client/GuiAlarmSettings.java | 206 +++++++++--------- src/alarmcraft/common/AlarmSettings.java | 41 ++-- src/alarmcraft/common/BlockAlarm.java | 94 ++++---- src/alarmcraft/common/CommonProxy.java | 13 +- src/alarmcraft/common/ModAlarmcraft.java | 37 ++-- src/alarmcraft/common/PacketHandler.java | 40 ++-- src/alarmcraft/common/SettingPacket.java | 29 ++- 13 files changed, 292 insertions(+), 233 deletions(-) create mode 100644 resources/assets/satscapealarmcraft/blockstates/SatscapeAlarm.json create mode 100644 resources/assets/satscapealarmcraft/models/block/alarm.json create mode 100644 resources/assets/satscapealarmcraft/models/item/SatscapeAlarm.json diff --git a/build.gradle b/build.gradle index 306e48b..a5d8e62 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,9 @@ targetCompatibility = 1.6 version = "1.0" group = "info.satscape.alarmcraft" minecraft { + version = "1.8-11.14.1.1350" runDir = "eclipse" - version = "1.7.10-10.13.2.1230" + mappings = "snapshot_20150401" } archivesBaseName = "Alarmcraft" //Set the workspace diff --git a/resources/assets/satscapealarmcraft/blockstates/SatscapeAlarm.json b/resources/assets/satscapealarmcraft/blockstates/SatscapeAlarm.json new file mode 100644 index 0000000..365c29c --- /dev/null +++ b/resources/assets/satscapealarmcraft/blockstates/SatscapeAlarm.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "satscapealarmcraft:alarm" } + } +} \ No newline at end of file diff --git a/resources/assets/satscapealarmcraft/lang/en_US.lang b/resources/assets/satscapealarmcraft/lang/en_US.lang index 9ded2da..eb9ec79 100644 --- a/resources/assets/satscapealarmcraft/lang/en_US.lang +++ b/resources/assets/satscapealarmcraft/lang/en_US.lang @@ -1,5 +1,5 @@ -tile.SatscapeAlarm.name=Alarm box +tile.alarm.name=Alarm box gui.alarm.fulltext=Press the button below to cycle through the different types of alarms available. When you've found the one you want, click the 'Done' button at the bottom. Supply a redstone pulse (on/off signal) to any side of the box to sound the alarm. gui.alarm.name=Alarm %s gui.alarm.test=Test diff --git a/resources/assets/satscapealarmcraft/models/block/alarm.json b/resources/assets/satscapealarmcraft/models/block/alarm.json new file mode 100644 index 0000000..ac2cb4d --- /dev/null +++ b/resources/assets/satscapealarmcraft/models/block/alarm.json @@ -0,0 +1,20 @@ +{ + "textures": { + "particle": "satscapealarmcraft:blocks/alarmside", + "side": "satscapealarmcraft:blocks/alarmside", + "top": "satscapealarmcraft:blocks/alarmtop" + }, + "elements": [ + { "from": [ 3, 0, 3 ], + "to": [ 13, 4, 13 ], + "faces": { + "down": { "uv": [ 3, 3, 13, 13 ], "texture": "#top" }, + "up": { "uv": [ 3, 3, 13, 13 ], "texture": "#top" }, + "north": { "uv": [ 2, 11, 14, 16 ], "texture": "#side" }, + "south": { "uv": [ 2, 11, 14, 16 ], "texture": "#side" }, + "west": { "uv": [ 2, 11, 14, 16 ], "texture": "#side" }, + "east": { "uv": [ 2, 11, 14, 16 ], "texture": "#side" } + } + } + ] +} \ No newline at end of file diff --git a/resources/assets/satscapealarmcraft/models/item/SatscapeAlarm.json b/resources/assets/satscapealarmcraft/models/item/SatscapeAlarm.json new file mode 100644 index 0000000..b5f4220 --- /dev/null +++ b/resources/assets/satscapealarmcraft/models/item/SatscapeAlarm.json @@ -0,0 +1,10 @@ +{ + "parent": "satscapealarmcraft:block/alarm", + "display": { + "thirdperson": { + "rotation": [ 10, -45, 170 ], + "translation": [ 0, 1.5, -2.75 ], + "scale": [ 0.375, 0.375, 0.375 ] + } + } +} \ No newline at end of file diff --git a/src/alarmcraft/client/ClientProxy.java b/src/alarmcraft/client/ClientProxy.java index 3cb88ea..8f6db33 100644 --- a/src/alarmcraft/client/ClientProxy.java +++ b/src/alarmcraft/client/ClientProxy.java @@ -2,9 +2,17 @@ import alarmcraft.common.AlarmSettings; import alarmcraft.common.CommonProxy; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import com.google.common.collect.Maps; +import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.statemap.DefaultStateMapper; +import net.minecraft.client.renderer.block.statemap.IStateMapper; +import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +import java.util.Map; public final class ClientProxy extends CommonProxy { @@ -14,7 +22,20 @@ public void openAlarmGui(AlarmSettings alarm, EntityPlayer player) { } @Override - public EntityPlayer getPlayer(MessageContext ctx){ + public EntityPlayer getPlayer(MessageContext ctx) { return Minecraft.getMinecraft().thePlayer; } + + @Override + public void registerBlock(final Block block, final String name) { + Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(name, "inventory")); + Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().registerBlockWithStateMapper(block, new IStateMapper(){ + private final Map internal = Maps.newLinkedHashMap(); + @Override + public Map putStateModelLocations(Block block) { + internal.put(block.getDefaultState(), new ModelResourceLocation(name, "normal")); + return internal; + } + }); + } } diff --git a/src/alarmcraft/client/GuiAlarmSettings.java b/src/alarmcraft/client/GuiAlarmSettings.java index ca3cb76..17cafee 100644 --- a/src/alarmcraft/client/GuiAlarmSettings.java +++ b/src/alarmcraft/client/GuiAlarmSettings.java @@ -2,126 +2,126 @@ import alarmcraft.common.AlarmSettings; import alarmcraft.common.PacketHandler; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public final class GuiAlarmSettings extends GuiScreen { - private static final ResourceLocation myBackgroundTexture = new ResourceLocation("satscapealarmcraft","textures/gui/guiBack.png"); - private EntityPlayer thePlayer; - private AlarmSettings alarm; - private int mouseCount=0; - private int tempMeta=0; - private String alertText=""; - - public GuiAlarmSettings(AlarmSettings alarm,EntityPlayer player) { - this.alarm=alarm; - this.thePlayer=player; - } + private static final ResourceLocation myBackgroundTexture = new ResourceLocation("satscapealarmcraft", "textures/gui/guiBack.png"); + private EntityPlayer thePlayer; + private AlarmSettings alarm; + private int mouseCount = 0; + private int tempMeta = 0; + private String alertText = ""; + + public GuiAlarmSettings(AlarmSettings alarm, EntityPlayer player) { + this.alarm = alarm; + this.thePlayer = player; + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } @Override - public boolean doesGuiPauseGame() { - return false; - } - - @Override - public void initGui() { - showPage(); - Mouse.setGrabbed(false); - } - - @Override - public void drawScreen(int i, int j, float f) { - - if (mouseCount<10) { - mouseCount++; - Mouse.setGrabbed(false); - } - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(myBackgroundTexture); - - int posX = (this.width - 256) / 2; - drawTexturedModalRect(posX, 5, 0, 0, 256, 230); - - drawCenteredString(fontRendererObj, "Alarmcraft", width / 2, 10, 0xFF1010); + public void initGui() { + showPage(); + Mouse.setGrabbed(false); + } + + @Override + public void drawScreen(int i, int j, float f) { + + if (mouseCount < 10) { + mouseCount++; + Mouse.setGrabbed(false); + } + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(myBackgroundTexture); + + int posX = (this.width - 256) / 2; + drawTexturedModalRect(posX, 5, 0, 0, 256, 230); + + drawCenteredString(fontRendererObj, "Alarmcraft", width / 2, 10, 0xFF1010); int textBorder = 5; - fontRendererObj.drawSplitString(I18n.format("gui.alarm.fulltext"), posX+textBorder, 30, 256-textBorder*2, 0xFFFFFF); - drawCenteredString(fontRendererObj, I18n.format(alertText), width/2, 150, 0x00FF00); - - super.drawScreen(i, j, f); - } - - private void showPage() { - buttonList.clear(); - buttonList.add(new GuiButton(0, this.width/2-25, 210, 50, 20, I18n.format("gui.done"))); - - tempMeta=alarm.theType; - if (tempMeta<26) { - char ch=(char) (65+tempMeta); - buttonList.add(new GuiButton(1, this.width/2-50,100,100,20,I18n.format("gui.alarm.name", ch))); - }else{ - buttonList.add(new GuiButton(1, this.width/2-50,100,100,20,I18n.format("gui.alert.name"))); + fontRendererObj.drawSplitString(I18n.format("gui.alarm.fulltext"), posX + textBorder, 30, 256 - textBorder * 2, 0xFFFFFF); + drawCenteredString(fontRendererObj, I18n.format(alertText), width / 2, 150, 0x00FF00); + + super.drawScreen(i, j, f); + } + + private void showPage() { + buttonList.clear(); + buttonList.add(new GuiButton(0, this.width / 2 - 25, 210, 50, 20, I18n.format("gui.done"))); + + tempMeta = alarm.theType; + if (tempMeta < 26) { + char ch = (char) (65 + tempMeta); + buttonList.add(new GuiButton(1, this.width / 2 - 50, 100, 100, 20, I18n.format("gui.alarm.name", ch))); + } else { + buttonList.add(new GuiButton(1, this.width / 2 - 50, 100, 100, 20, I18n.format("gui.alert.name"))); + } + buttonList.add(new GuiButton(2, this.width / 2 - 25, 120, 50, 20, I18n.format("gui.alarm.test"))); + } + + @Override + protected void actionPerformed(GuiButton guibutton) { + if (!guibutton.enabled) { + return; } - buttonList.add(new GuiButton(2, this.width/2-25,120,50,20,I18n.format("gui.alarm.test"))); - } - - @Override - protected void actionPerformed(GuiButton guibutton) { - if (!guibutton.enabled) { - return; - } - if (guibutton.id == 0) // SET alarm button - { + if (guibutton.id == 0) // SET alarm button + { this.alarm.theType = tempMeta; this.alarm.isPowered = false; this.alarm.playersUsername = ""; - PacketHandler.sendPacketToServer(this.alarm, "update"); + PacketHandler.sendPacketToServer(this.alarm, "update"); thePlayer.worldObj.playSoundAtEntity(thePlayer, "satscapealarmcraft:carlock", 1f, 1f); - - mc.currentScreen = null; - mc.setIngameFocus(); - - } else if (guibutton.id == 1) { //change alarm type button - tempMeta++; - if (tempMeta>12 && tempMeta<26) { - tempMeta=26; - } else if (tempMeta>26) { - tempMeta=0; - } - if (tempMeta<26) { - char ch=(char) (65+tempMeta); - guibutton.displayString=I18n.format("gui.alarm.name",ch); - alertText=""; - } else { - guibutton.displayString=I18n.format("gui.alert.name"); - alertText="gui.alert.desc"; - } - - } else if (guibutton.id == 2) { //test the alarm button - if (tempMeta <26) { - char ch=(char) (65+tempMeta); - thePlayer.worldObj.playSoundAtEntity(thePlayer, "satscapealarmcraft:alarm" + ch, 1f, 1f); - alertText=""; - } else { - alertText="gui.alert.test"; - } - } - } - - @Override - protected void keyTyped(char c, int i) { - if (i == 1) { // escape and dont save - mc.currentScreen = null; - mc.setIngameFocus(); - } - } + + mc.currentScreen = null; + mc.setIngameFocus(); + + } else if (guibutton.id == 1) { //change alarm type button + tempMeta++; + if (tempMeta > 12 && tempMeta < 26) { + tempMeta = 26; + } else if (tempMeta > 26) { + tempMeta = 0; + } + if (tempMeta < 26) { + char ch = (char) (65 + tempMeta); + guibutton.displayString = I18n.format("gui.alarm.name", ch); + alertText = ""; + } else { + guibutton.displayString = I18n.format("gui.alert.name"); + alertText = "gui.alert.desc"; + } + + } else if (guibutton.id == 2) { //test the alarm button + if (tempMeta < 26) { + char ch = (char) (65 + tempMeta); + thePlayer.worldObj.playSoundAtEntity(thePlayer, "satscapealarmcraft:alarm" + ch, 1f, 1f); + alertText = ""; + } else { + alertText = "gui.alert.test"; + } + } + } + + @Override + protected void keyTyped(char c, int i) { + if (i == 1) { // escape and dont save + mc.currentScreen = null; + mc.setIngameFocus(); + } + } } diff --git a/src/alarmcraft/common/AlarmSettings.java b/src/alarmcraft/common/AlarmSettings.java index ad01687..c1f5c96 100644 --- a/src/alarmcraft/common/AlarmSettings.java +++ b/src/alarmcraft/common/AlarmSettings.java @@ -2,28 +2,26 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; -public final class AlarmSettings extends TileEntity{ +public final class AlarmSettings extends TileEntity { - public int theType=0; - public boolean isPowered=false; - public String playersUsername=""; //this is used to remember who right clicked the box so when the packet arrives it opens the UI on the correct users screen + public int theType = 0; + public boolean isPowered = false; + public String playersUsername = ""; //this is used to remember who right clicked the box so when the packet arrives it opens the UI on the correct users screen - public AlarmSettings() { - } + public AlarmSettings() { + } - public AlarmSettings(int type, boolean power, int x, int y, int z, String user){ + public AlarmSettings(int type, boolean power, int x, int y, int z, String user) { this.theType = type; this.isPowered = power; - this.xCoord = x; - this.yCoord = y; - this.zCoord = z; + this.pos = new BlockPos(x, y, z); this.playersUsername = user; } @Override - public void readFromNBT(NBTTagCompound tagCompound) - { + public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); theType = tagCompound.getInteger("Sound"); isPowered = tagCompound.getBoolean("Power"); @@ -31,18 +29,29 @@ public void readFromNBT(NBTTagCompound tagCompound) } @Override - public void writeToNBT(NBTTagCompound tagCompound) - { + public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setInteger("Sound", theType); tagCompound.setBoolean("Power", isPowered); tagCompound.setString("Owner", playersUsername); } - public SettingPacket toPacket(String type){ - if(type.equals("update")){ + public SettingPacket toPacket(String type) { + if (type.equals("update")) { return new SettingPacket.Update(this); } return new SettingPacket(this, type); } + + public int xCoord() { + return getPos().getX(); + } + + public int yCoord() { + return getPos().getY(); + } + + public int zCoord() { + return getPos().getZ(); + } } diff --git a/src/alarmcraft/common/BlockAlarm.java b/src/alarmcraft/common/BlockAlarm.java index ba17b5c..f5d0acf 100644 --- a/src/alarmcraft/common/BlockAlarm.java +++ b/src/alarmcraft/common/BlockAlarm.java @@ -1,87 +1,67 @@ package alarmcraft.common; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public final class BlockAlarm extends BlockContainer { - private IIcon icons[]; - - public BlockAlarm() { - super(Material.iron); + public BlockAlarm() { + super(Material.iron); this.setCreativeTab(CreativeTabs.tabMisc); - setBlockBounds(0.1875f,0.0f,0.1875f, 0.8125f,0.25f,0.8125f); + setBlockBounds(0.1875f, 0.0f, 0.1875f, 0.8125f, 0.25f, 0.8125f); this.setLightLevel(0.2f); - } + } - @Override - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister iconRegister) { - icons=new IIcon[2]; - icons[0] = iconRegister.registerIcon(this.getTextureName()+"side"); - icons[1] = iconRegister.registerIcon(this.getTextureName()+"top"); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int side, int meta) { - if (side < 2) { - return icons[1]; - } else { - return icons[0]; - } - } + @Override + public void setBlockBoundsForItemRender() { + setBlockBounds(0.1875f, 0.0f, 0.1875f, 0.8125f, 0.25f, 0.8125f); + } - @Override - public void setBlockBoundsForItemRender() - { - setBlockBounds(0.1875f,0.0f,0.1875f, 0.8125f,0.25f,0.8125f); + @Override + public int getRenderType(){ + return 3; } @Override - public boolean renderAsNormalBlock() - { + public boolean isFullCube() { return false; } @Override - public boolean isOpaqueCube() - { + public boolean isOpaqueCube() { return false; } - @Override - public boolean canPlaceBlockAt(World theWorld, int x, int y, int z) { - Block id=theWorld.getBlock(x, y - 1, z); + @Override + public boolean canPlaceBlockAt(World theWorld, BlockPos pos) { + Block id = theWorld.getBlockState(pos.down()).getBlock(); return id != Blocks.air && id != ModAlarmcraft.alarmBlock; - } + } @Override - public void onNeighborBlockChange(World theWorld, int x, int y, int z, Block neighbourBlockId) - { + public void onNeighborBlockChange(World theWorld, BlockPos pos, IBlockState state, Block neighbourBlockId) { if (!theWorld.isRemote) { - AlarmSettings alarm = (AlarmSettings) theWorld.getTileEntity(x,y,z); - if(alarm == null) + AlarmSettings alarm = (AlarmSettings) theWorld.getTileEntity(pos); + if (alarm == null) return; - if (alarm.isPowered && !theWorld.isBlockIndirectlyGettingPowered(x,y,z)) - { - alarm.isPowered=false; - } - else if (!alarm.isPowered && theWorld.isBlockIndirectlyGettingPowered(x,y,z)) - { - alarm.isPowered=true; + if (alarm.isPowered && theWorld.isBlockIndirectlyGettingPowered(pos) == 0) { + alarm.isPowered = false; + } else if (!alarm.isPowered && theWorld.isBlockIndirectlyGettingPowered(pos) > 0) { + alarm.isPowered = true; - if (alarm.theType==26) { // it's a b... *airplane reference :-) - EntityPlayer nplayer=theWorld.getClosestPlayer(x,y,z,-1); + if (alarm.theType == 26) { // it's a b... *airplane reference :-) + double x = pos.getX(); + double y = pos.getY(); + double z = pos.getZ(); + EntityPlayer nplayer = theWorld.getClosestPlayer(x, y, z, -1); theWorld.createExplosion(nplayer, x, y, z, 10, true); //server side explosion } //send packet to client so it can make the sound effects @@ -90,15 +70,15 @@ else if (!alarm.isPowered && theWorld.isBlockIndirectlyGettingPowered(x,y,z)) } } - @Override - public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer thePlayer, int par6, float par7,float par8, float par9) { + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer thePlayer, EnumFacing par6, float par7, float par8, float par9) { - TileEntity tile = world.getTileEntity(i, j, k); - if(tile instanceof AlarmSettings) { + TileEntity tile = world.getTileEntity(pos); + if (tile instanceof AlarmSettings) { ((AlarmSettings) tile).playersUsername = thePlayer.getCommandSenderName(); ModAlarmcraft.proxy.openAlarmGui((AlarmSettings) tile, thePlayer); } - world.playSoundEffect(i,j,k,"satscapealarmcraft:carlock",1f,1f); + world.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "satscapealarmcraft:carlock", 1f, 1f); return true; } diff --git a/src/alarmcraft/common/CommonProxy.java b/src/alarmcraft/common/CommonProxy.java index da51285..00426be 100644 --- a/src/alarmcraft/common/CommonProxy.java +++ b/src/alarmcraft/common/CommonProxy.java @@ -1,15 +1,20 @@ package alarmcraft.common; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class CommonProxy { - public void openAlarmGui(AlarmSettings alarm, EntityPlayer player) { - //nothing on server - } + public void openAlarmGui(AlarmSettings alarm, EntityPlayer player) { + //nothing on server + } public EntityPlayer getPlayer(MessageContext ctx) { return ctx.getServerHandler().playerEntity; } + + public void registerBlock(Block block, String name) { + + } } diff --git a/src/alarmcraft/common/ModAlarmcraft.java b/src/alarmcraft/common/ModAlarmcraft.java index e1550c9..fd644c2 100644 --- a/src/alarmcraft/common/ModAlarmcraft.java +++ b/src/alarmcraft/common/ModAlarmcraft.java @@ -1,34 +1,36 @@ package alarmcraft.common; -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.oredict.ShapedOreRecipe; import org.apache.logging.log4j.Logger; /// Alarmcraft Mod by Scott Hather AKA "Satscape" /// v1.0.0 - 20th June 2013 -@Mod(modid="satscapealarmcraft", name="Alarmcraft") +@Mod(modid = "satscapealarmcraft", name = "Alarmcraft") public final class ModAlarmcraft { - - @SidedProxy(clientSide = "alarmcraft.client.ClientProxy", serverSide = "alarmcraft.common.CommonProxy") - public static CommonProxy proxy; - /** Block instances and IDs */ + + @SidedProxy(clientSide = "alarmcraft.client.ClientProxy", serverSide = "alarmcraft.common.CommonProxy") + public static CommonProxy proxy; + /** + * Block instances and IDs + */ public static Block alarmBlock; public static Logger log; - @EventHandler - public void preInit(FMLPreInitializationEvent evt) { - alarmBlock = new BlockAlarm().setStepSound(Block.soundTypeMetal).setHardness(2F).setResistance(1.0F).setBlockName("SatscapeAlarm").setBlockTextureName("satscapealarmcraft:alarm"); + @EventHandler + public void preInit(FMLPreInitializationEvent evt) { + alarmBlock = new BlockAlarm().setStepSound(Block.soundTypeMetal).setHardness(2F).setResistance(1.0F).setUnlocalizedName("alarm"); log = evt.getModLog(); GameRegistry.registerBlock(alarmBlock, "SatscapeAlarm"); GameRegistry.registerTileEntity(AlarmSettings.class, "SatscapeAlarm"); @@ -36,7 +38,8 @@ public void preInit(FMLPreInitializationEvent evt) { @EventHandler public void init(FMLInitializationEvent evt) { - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(alarmBlock), "III", "IRI", "ILI", + proxy.registerBlock(alarmBlock, "satscapealarmcraft:SatscapeAlarm"); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(alarmBlock), "III", "IRI", "ILI", 'I', "ingotIron", 'R', "dustRedstone", 'L', Blocks.lever)); @@ -44,7 +47,7 @@ public void init(FMLInitializationEvent evt) { PacketHandler.INSTANCE.register(SettingPacket.class, Side.CLIENT); } - public static void log(String text){ + public static void log(String text) { log.debug(text); } } diff --git a/src/alarmcraft/common/PacketHandler.java b/src/alarmcraft/common/PacketHandler.java index 77096a9..59d43f7 100644 --- a/src/alarmcraft/common/PacketHandler.java +++ b/src/alarmcraft/common/PacketHandler.java @@ -1,14 +1,14 @@ package alarmcraft.common; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import cpw.mods.fml.relauncher.Side; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.relauncher.Side; public final class PacketHandler implements IMessageHandler { @@ -18,17 +18,17 @@ public final class PacketHandler implements IMessageHandler clazz, Side side){ + public void register(Class clazz, Side side) { mainChannel.registerMessage(this, clazz, ++discr, side); } - public void onPacketData(SettingPacket packet, EntityPlayer receiver) { + public void onPacketData(SettingPacket packet, EntityPlayer receiver) { if (packet.messageType.equals("update")) { // client > server - if(!receiver.worldObj.isRemote) { - TileEntity tile = receiver.worldObj.getTileEntity(packet.settings.xCoord, packet.settings.yCoord, packet.settings.zCoord); - if(tile instanceof AlarmSettings){ + if (!receiver.worldObj.isRemote) { + TileEntity tile = receiver.worldObj.getTileEntity(packet.settings.getPos()); + if (tile instanceof AlarmSettings) { NBTTagCompound tagCompound = new NBTTagCompound(); packet.settings.writeToNBT(tagCompound); tile.readFromNBT(tagCompound); @@ -36,23 +36,23 @@ public void onPacketData(SettingPacket packet, EntityPlayer receiver) { } } else if (packet.messageType.equals("poweredon")) {// server > client - if(receiver == null || !receiver.worldObj.isRemote) + if (receiver == null || !receiver.worldObj.isRemote) return; - if (packet.settings.theType<26) { - char ch=(char) (65+packet.settings.theType); - receiver.playSound("satscapealarmcraft:alarm"+ch, 1f, 1f); + if (packet.settings.theType < 26) { + char ch = (char) (65 + packet.settings.theType); + receiver.playSound("satscapealarmcraft:alarm" + ch, 1f, 1f); } else { receiver.playSound("random.explode", 4f, 1f); } } - } + } - public static void sendPacketToServer(AlarmSettings alarm, String msgType){ + public static void sendPacketToServer(AlarmSettings alarm, String msgType) { INSTANCE.mainChannel.sendToServer(alarm.toPacket(msgType)); } - public static void sendPacketToAllAround(AlarmSettings alarm, String msgType, int range){ - INSTANCE.mainChannel.sendToAllAround(alarm.toPacket(msgType), new NetworkRegistry.TargetPoint(alarm.getWorldObj().provider.dimensionId, alarm.xCoord, alarm.yCoord, alarm.zCoord, range)); + public static void sendPacketToAllAround(AlarmSettings alarm, String msgType, int range) { + INSTANCE.mainChannel.sendToAllAround(alarm.toPacket(msgType), new NetworkRegistry.TargetPoint(alarm.getWorld().provider.getDimensionId(), alarm.xCoord(), alarm.yCoord(), alarm.zCoord(), range)); } @Override diff --git a/src/alarmcraft/common/SettingPacket.java b/src/alarmcraft/common/SettingPacket.java index 9b4e78e..947b109 100644 --- a/src/alarmcraft/common/SettingPacket.java +++ b/src/alarmcraft/common/SettingPacket.java @@ -1,16 +1,19 @@ package alarmcraft.common; -import cpw.mods.fml.common.network.ByteBufUtils; -import cpw.mods.fml.common.network.simpleimpl.IMessage; import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; /** * Created by Olivier on 28/11/2014. */ -public class SettingPacket implements IMessage{ +public class SettingPacket implements IMessage { public AlarmSettings settings; public String messageType; - public SettingPacket(){} + + public SettingPacket() { + } + public SettingPacket(AlarmSettings alarmSettings, String type) { this.settings = alarmSettings; this.messageType = type; @@ -18,25 +21,27 @@ public SettingPacket(AlarmSettings alarmSettings, String type) { @Override public void fromBytes(ByteBuf buf) { - settings=new AlarmSettings(buf.readInt(),buf.readBoolean(), + settings = new AlarmSettings(buf.readInt(), buf.readBoolean(), buf.readInt(), buf.readInt(), buf.readInt(), ByteBufUtils.readUTF8String(buf)); - messageType=ByteBufUtils.readUTF8String(buf); + messageType = ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(settings.theType); buf.writeBoolean(settings.isPowered); - buf.writeInt(settings.xCoord); - buf.writeInt(settings.yCoord); - buf.writeInt(settings.zCoord); + buf.writeInt(settings.getPos().getX()); + buf.writeInt(settings.getPos().getY()); + buf.writeInt(settings.getPos().getZ()); ByteBufUtils.writeUTF8String(buf, settings.playersUsername); ByteBufUtils.writeUTF8String(buf, messageType); } - public static class Update extends SettingPacket{ - public Update(){} - public Update(AlarmSettings alarmSettings){ + public static class Update extends SettingPacket { + public Update() { + } + + public Update(AlarmSettings alarmSettings) { super(alarmSettings, "update"); } }