From 718c999f70784ddbc584fd0dbd23245534f17dcd Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 15 Jun 2016 17:42:55 +0200 Subject: [PATCH] Added laser wrench mode switch. Closes #119 --- .../mod/booklet/InitBooklet.java | 2 +- .../mod/config/values/ConfigBoolValues.java | 1 - .../mod/items/ItemLaserWrench.java | 51 ++++++++++++++++--- .../mod/tile/TileEntityLaserRelay.java | 20 +++++--- .../assets/actuallyadditions/lang/en_US.lang | 1 + 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java index caa398885..fa334c9ad 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java @@ -110,7 +110,7 @@ public class InitBooklet{ //RF Using Blocks new BookletChapter("fireworkBox", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFireworkBox), new PageTextOnly(1).addTextReplacement("", TileEntityFireworkBox.USE_PER_SHOT), new PageCrafting(2, BlockCrafting.recipeFireworkBox)).setSpecial(); - new BookletChapter("laserRelays", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockLaserRelay), new PageTextOnly(1).addTextReplacement("", TileEntityLaserRelay.MAX_DISTANCE).addTextReplacement("", ConfigIntValues.LASER_RELAY_LOSS.getValue()), new PagePicture(2, "pageLaserRelay", 0).setNoText(), new PageCrafting(3, BlockCrafting.recipeLaserRelay).setNoText().setPageStacksWildcard(), new PageCrafting(4, ItemCrafting.recipeLaserWrench).setNoText()).setImportant(); + new BookletChapter("laserRelays", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockLaserRelay), new PageTextOnly(1).addTextReplacement("", TileEntityLaserRelay.MAX_DISTANCE).addTextReplacement("", ConfigIntValues.LASER_RELAY_LOSS.getValue()), new PagePicture(2, "pageLaserRelay", 0).setNoText(), new PageCrafting(3, BlockCrafting.recipeLaserRelay).setNoText().setPageStacksWildcard(), new PageCrafting(4, ItemCrafting.recipeLaserWrench)).setImportant(); new BookletChapter("miner", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockMiner), new PageTextOnly(1).addTextReplacement("", TileEntityMiner.ENERGY_USE_PER_BLOCK).addTextReplacement("", TileEntityMiner.DEFAULT_RANGE), new PageCrafting(2, BlockCrafting.recipeMiner)).setSpecial(); new BookletChapterCoffee("coffeeMachine", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockCoffeeMachine), new PageTextOnly(1).setStack(new ItemStack(InitItems.itemCoffeeBean)).addTextReplacement("", TileEntityCoffeeMachine.ENERGY_USED).addTextReplacement("", TileEntityCoffeeMachine.CACHE_USE).addTextReplacement("", TileEntityCoffeeMachine.WATER_USE), new PageTextOnly(2).setStack(new ItemStack(InitItems.itemCoffee)), new PagePicture(3, "pageCoffeeMachine", 115), new PageCrafting(4, BlockCrafting.recipeCoffeeMachine).setNoText().setPageStacksWildcard(), new PageCrafting(5, ItemCrafting.recipeCup).setNoText()).setImportant(); new BookletChapterCrusher("crusher", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockGrinderDouble), new PageTextOnly(1).addTextReplacement("", TileEntityGrinder.ENERGY_USE), new PageCrafting(2, BlockCrafting.recipeCrusher).setNoText().setPageStacksWildcard(), new PageCrafting(3, BlockCrafting.recipeDoubleCrusher).setNoText().setPageStacksWildcard(), new PageCrusherRecipe(4, CrusherCrafting.recipeIronHorseArmor).setNoText(), new PageCrusherRecipe(5, CrusherCrafting.recipeGoldHorseArmor).setNoText(), new PageCrusherRecipe(6, CrusherCrafting.recipeDiamondHorseArmor).setNoText()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index c5097b173..f0f2f6798 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -52,7 +52,6 @@ public enum ConfigBoolValues{ BOOKLET_TEXT_TO_FILE("Booklet Text to File", ConfigCategories.OTHER, false, "Should the entire text of the booklet be put into a new file in the Minecraft Folder on startup or resource reload. This is for debug purposes only and shouldn't really ever be needed."), WATER_BOWL("Water Bowl", ConfigCategories.OTHER, true, "If right-clicking a bowl on water should create a water bowl"), - LASER_WRENCH_HOLDING_PARTICLES("Laser Wrench Holding Particles", ConfigCategories.OTHER, false, "If particles of laser devices should only render when holding a Laser Wrench"), LESS_SOUND("Less Sound", ConfigCategories.PERFORMANCE, false, "If blocks in Actually Additions should have less sounds"), LESS_PARTICLES("Less Particles", ConfigCategories.PERFORMANCE, false, "If blocks in Actually Additions should have less particles"), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java index ee1412518..dff7de1e5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java @@ -10,20 +10,26 @@ package de.ellpeck.actuallyadditions.mod.items; +import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; @@ -39,12 +45,11 @@ public class ItemLaserWrench extends ItemBase{ this.setMaxStackSize(1); } - @Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing par7, float par8, float par9, float par10){ - if(!world.isRemote){ - TileEntity tile = world.getTileEntity(pos); - if(tile instanceof TileEntityLaserRelay){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityLaserRelay){ + if(!world.isRemote){ if(ItemPhantomConnector.getStoredPosition(stack) == null){ ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world); player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.stored.desc")); @@ -67,12 +72,35 @@ public class ItemLaserWrench extends ItemBase{ } } } - return EnumActionResult.SUCCESS; } + return EnumActionResult.SUCCESS; } return EnumActionResult.FAIL; } + @Override + public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){ + if(!world.isRemote && player.isSneaking()){ + PlayerData.PlayerSave save = PlayerData.getDataFromPlayer(player); + + int currMode = save.theCompound.getInteger("LaserWrenchMode"); + if(currMode+1 >= WrenchMode.values().length){ + currMode = 0; + } + else{ + currMode++; + } + save.theCompound.setInteger("LaserWrenchMode", currMode); + + if(player instanceof EntityPlayerMP){ + PacketHandler.theNetwork.sendTo(new PacketServerToClient(save.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); + } + + player.addChatComponentMessage(new TextComponentString("Mode changed to "+WrenchMode.values()[currMode].name+"!")); + } + return new ActionResult(EnumActionResult.SUCCESS, stack); + } + @Override public boolean getShareTag(){ return true; @@ -98,9 +126,20 @@ public class ItemLaserWrench extends ItemBase{ } } - @Override public EnumRarity getRarity(ItemStack stack){ return EnumRarity.EPIC; } + + public enum WrenchMode{ + ALWAYS_PARTICLES("always show particles"), + NO_PARTICLES("never show particles"), + HOLDING_PARTICLES("show particles when holding a Laser Wrench"); + + public String name; + + WrenchMode(String name){ + this.name = name; + } + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index 6e39b9810..680b3c5e5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -11,7 +11,9 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; +import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench; +import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench.WrenchMode; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.ConnectionPair; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -98,13 +100,17 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ if(Util.RANDOM.nextInt(ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 16 : 8) == 0){ EntityPlayer player = Minecraft.getMinecraft().thePlayer; if(player != null){ - ItemStack stack = player.getHeldItemMainhand(); - if(!ConfigBoolValues.LASER_WRENCH_HOLDING_PARTICLES.isEnabled() || (stack != null && stack.getItem() instanceof ItemLaserWrench)){ - LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj); - if(network != null){ - for(ConnectionPair aPair : network.connections){ - if(aPair.contains(this.pos) && PosUtil.areSamePos(this.pos, aPair.positions[0])){ - AssetUtil.renderParticlesFromAToB(aPair.positions[0].getX(), aPair.positions[0].getY(), aPair.positions[0].getZ(), aPair.positions[1].getX(), aPair.positions[1].getY(), aPair.positions[1].getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.isItem ? COLOR_ITEM : COLOR, 1F); + PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); + WrenchMode mode = WrenchMode.values()[data.theCompound.getInteger("LaserWrenchMode")]; + if(mode != WrenchMode.NO_PARTICLES){ + ItemStack stack = player.getHeldItemMainhand(); + if(mode == WrenchMode.ALWAYS_PARTICLES || (stack != null && stack.getItem() instanceof ItemLaserWrench)){ + LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj); + if(network != null){ + for(ConnectionPair aPair : network.connections){ + if(aPair.contains(this.pos) && PosUtil.areSamePos(this.pos, aPair.positions[0])){ + AssetUtil.renderParticlesFromAToB(aPair.positions[0].getX(), aPair.positions[0].getY(), aPair.positions[0].getZ(), aPair.positions[1].getX(), aPair.positions[1].getY(), aPair.positions[1].getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.isItem ? COLOR_ITEM : COLOR, 1F); + } } } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 264ee9924..877db55f2 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -822,6 +822,7 @@ booklet.actuallyadditions.chapter.hairBalls.text.2=Balls of Fur are an booklet.actuallyadditions.chapter.laserRelays.name=Laser Relays booklet.actuallyadditions.chapter.laserRelays.text.1=The Laser Relay is a block that can wirelessly transfer RF just by being connected with a Laser Wrench, generating a network. When placing a Power Generator or Receiver next to the relay, it can receive Power from any other relay in the network. Two relays can be at most blocks apart. During an energy transfer, they have an Energy Loss of %. +booklet.actuallyadditions.chapter.laserRelays.text.4=The Laser Wrench's mode can be switched by sneak-right-clicking it anywhere. Possible modes are to always show lasers, never show lasers or only show lasers when holding the wrench. booklet.actuallyadditions.chapter.blackLotus.name=Black Lotus booklet.actuallyadditions.chapter.blackLotus.text.1=Think of this: You need to craft black wool, black clay or anything else that needs black dye but you are just guilty about killing so many innocent squids? Well, the Black Lotus is exactly the thing you need! Just look around in the wild a bit, and you will find one, then being able to craft some Black Dye that can be used instead of Ink Sacs so that you don't need to kill poor squids and L any longer.