From 1b97e5a62a33cabc3ed1119cb89e7439f7e58b81 Mon Sep 17 00:00:00 2001 From: Tschipp Date: Mon, 22 Jan 2018 00:20:12 +0100 Subject: [PATCH] Config Options --- src/main/java/tschipp/carryon/CarryOn.java | 2 +- .../carryon/common/config/Configs.java | 6 +++++ .../carryon/common/event/ItemEvents.java | 26 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index b5bdf08..9b935c3 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -34,7 +34,7 @@ public class CarryOn { public static CarryOn instance; public static final String MODID = "carryon"; - public static final String VERSION = "1.7"; + public static final String VERSION = "1.7.1"; public static final String NAME = "Carry On"; public static final String ACCEPTED_VERSIONS = "[1.11,1.12)"; public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 434c811..41f4a24 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -55,6 +55,12 @@ public class Configs { @Comment("Use Whitelist instead of Blacklist for Entities") public boolean useWhitelistEntities=false; + @Comment("Whether the player can break blocks while carrying or not") + public boolean breakBlocksWhileCarrying=false; + + @Comment("Whether the player drops the carried object when hit or not") + public boolean dropCarriedWhenHit=false; + @Config.RequiresMcRestart() @Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will save you some performance") public boolean useScripts=false; diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java index 1edbd99..9222d73 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEvents.java @@ -3,6 +3,7 @@ package tschipp.carryon.common.event; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -20,6 +21,7 @@ import net.minecraft.util.text.event.ClickEvent.Action; import net.minecraft.world.GameRules; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed; import net.minecraftforge.event.entity.player.PlayerEvent.StartTracking; @@ -31,6 +33,7 @@ import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; import tschipp.carryon.CarryOn; import tschipp.carryon.client.keybinds.CarryOnKeybinds; +import tschipp.carryon.common.config.CarryOnConfig; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; @@ -167,7 +170,7 @@ public class ItemEvents public void harvestSpeed(BreakSpeed event) { EntityPlayer player = event.getEntityPlayer(); - if (player != null) + if (player != null && !CarryOnConfig.settings.breakBlocksWhileCarrying) { ItemStack stack = player.getHeldItemMainhand(); if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) @@ -175,6 +178,27 @@ public class ItemEvents } } + @SubscribeEvent + public void playerAttack(LivingAttackEvent event) + { + EntityLivingBase eliving = event.getEntityLiving(); + if (eliving instanceof EntityPlayer && CarryOnConfig.settings.dropCarriedWhenHit) + { + EntityPlayer player = (EntityPlayer) eliving; + ItemStack stack = player.getHeldItemMainhand(); + if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity)) + { + if (!player.world.isRemote) + { + player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); + EntityItem item = new EntityItem(player.world, player.posX, player.posY, player.posZ, stack); + player.world.spawnEntity(item); + } + } + + } + } + @SubscribeEvent public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) throws InstantiationException, IllegalAccessException {