123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- package me.km.effects.passive;
- import me.km.KajetansMod;
- import me.km.api.Module;
- import me.km.api.ModuleListener;
- import me.km.api.Utils;
- import me.km.effects.Effect;
- import me.km.effects.EffectUtils;
- import me.km.utils.ItemStackBuilder;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockCrops;
- import net.minecraft.block.BlockFalling;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Enchantments;
- import net.minecraft.init.Items;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraftforge.event.entity.player.PlayerEvent;
- import net.minecraftforge.event.world.BlockEvent;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- public class BlockBreakEffects extends ModuleListener
- {
- public BlockBreakEffects(Module m)
- {
- super(m);
- }
-
- @SubscribeEvent(receiveCanceled = false)
- public void onBlockBreakSkills(BlockEvent.BreakEvent e)
- {
- if(!KajetansMod.worldManager.getWorldPreferences(e.getWorld()).skills)
- {
- return;
- }
- EntityPlayer p = e.getPlayer();
- BlockPos pos = e.getPos();
- World w = e.getWorld();
- IBlockState state = w.getBlockState(pos);
- Block b = state.getBlock();
- ItemStack hand = p.getHeldItemMainhand();
- // ---------------------------------------------------------------------
- // Gravel-Sand-Digger
- // ---------------------------------------------------------------------
-
- if(b instanceof BlockFalling)
- {
- int level = EffectUtils.getEffectLevel(p, Effect.GRAVEL_SAND_DIGGER);
- if(level >= 1)
- {
- BlockPos dig;
- for(int i = 0; i < level; i++)
- {
- dig = pos.add(0, i, 0);
- state = w.getBlockState(dig);
- if(state.getBlock() instanceof BlockFalling)
- {
- Utils.breakBlock(w, dig, p);
- continue;
- }
- break;
- }
- }
- return;
- }
-
- // ---------------------------------------------------------------------
- // More Minerals
- // ---------------------------------------------------------------------
-
-
- if(EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, hand) >= 1)
- {
- if(b == Blocks.DIAMOND_ORE || b == Blocks.REDSTONE_ORE ||
- b == Blocks.LAPIS_ORE || b == Blocks.COAL_ORE)
- {
- if(Utils.randomBoolean() && EffectUtils.getEffectLevel(p, Effect.MORE_MINERALS) >= 1)
- {
- b.dropBlockAsItem(w, pos, state, 0);
- }
- }
- }
-
- // ---------------------------------------------------------------------
- // More Crops
- // ---------------------------------------------------------------------
-
- if(b instanceof BlockCrops && state.getValue(BlockCrops.AGE) == 7)
- {
- int moreCrops = EffectUtils.getEffectLevel(p, Effect.MORE_CROPS);
- if(moreCrops >= 1)
- {
- b.getDrops(w, pos, state, 0).stream().filter(s -> Utils.randomBoolean()).forEach((stack) ->
- {
- new ItemStackBuilder(stack, Utils.randomInt(1, moreCrops)).drop(w, pos);
- });
- }
- }
-
- // ---------------------------------------------------------------------
- // Tree Picker und More Saplings
- // ---------------------------------------------------------------------
-
- if((b == Blocks.LEAVES || b == Blocks.LEAVES2) && hand.getItem() != Items.SHEARS)
- {
- if(Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.TREE_PICKER))
- {
- Utils.dropRandomTreeItem(w, pos, state);
- }
- if(Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.MORE_SAPLINGS))
- {
- if(b == Blocks.LEAVES)
- {
- new ItemStackBuilder(Blocks.SAPLING, 1, b.getMetaFromState(state) % 4).drop(w, pos);
- }
- else
- {
- new ItemStackBuilder(Blocks.SAPLING, 1, (b.getMetaFromState(state) % 4) + 4).drop(w, pos);
- }
- }
- }
- }
-
- @SubscribeEvent(receiveCanceled = false)
- public void onBlockDamage(PlayerEvent.BreakSpeed e)
- {
- EntityPlayer p = e.getEntityPlayer();
- if(KajetansMod.worldManager.getWorldPreferences(p.world).skills &&
- KajetansMod.jobs.isPreferedMaterial(p, e.getState().getBlock()))
- {
- // Speed up with prefered blocks of current job
- int digging = EffectUtils.getEffectLevel(p, Effect.FAST_DIGGING);
- if(digging >= 1)
- {
- e.setNewSpeed(e.getOriginalSpeed() * (1 + (digging / 5)));
- }
- }
- }
- }
|