Search in sources :

Example 1 with MiningSnapshot

use of cavern.miningassist.MiningSnapshot in project Cavern2 by kegare.

the class MiningAssistEventHooks method onBlockBreak.

@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    EntityPlayer player = event.getPlayer();
    if (player == null || player instanceof FakePlayer) {
        return;
    }
    BlockPos pos = event.getPos();
    MiningAssistUnit assist = MiningAssistUnit.get(player);
    if (assist.addExperience(pos, event.getExpToDrop())) {
        event.setExpToDrop(0);
    }
    if (breaking) {
        return;
    }
    if (!(player instanceof EntityPlayerMP)) {
        return;
    }
    IBlockState state = event.getState();
    if (!isActive(player, state)) {
        return;
    }
    MiningAssist type = MiningAssist.byPlayer(player);
    MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
    if (snapshot.isEmpty()) {
        return;
    }
    PlayerInteractionManager im = ((EntityPlayerMP) player).interactionManager;
    assist.captureDrops(MiningAssistConfig.collectDrops);
    assist.captureExperiences(MiningAssistConfig.collectExps);
    breaking = true;
    for (BlockPos target : snapshot.getTargets()) {
        if (snapshot.validTarget(target) && !harvestBlock(im, target)) {
            break;
        }
    }
    breaking = false;
    Map<BlockPos, NonNullList<ItemStack>> drops = assist.captureDrops(false);
    if (drops != null && !drops.isEmpty()) {
        for (NonNullList<ItemStack> items : drops.values()) {
            for (ItemStack stack : items) {
                Block.spawnAsEntity(world, pos, stack);
            }
        }
    }
    Map<BlockPos, Integer> experiences = assist.captureExperiences(false);
    if (experiences != null && !experiences.isEmpty() && !im.isCreative() && world.getGameRules().getBoolean("doTileDrops")) {
        int exp = experiences.values().stream().mapToInt(Integer::intValue).sum();
        while (exp > 0) {
            int i = EntityXPOrb.getXPSplit(exp);
            exp -= i;
            world.spawnEntity(new EntityXPOrb(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, i));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) MiningAssist(cavern.miningassist.MiningAssist) FakePlayer(net.minecraftforge.common.util.FakePlayer) MiningSnapshot(cavern.miningassist.MiningSnapshot) NonNullList(net.minecraft.util.NonNullList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) ItemStack(net.minecraft.item.ItemStack) MiningAssistUnit(cavern.miningassist.MiningAssistUnit) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with MiningSnapshot

use of cavern.miningassist.MiningSnapshot in project Cavern2 by kegare.

the class MiningAssistEventHooks method onBreakSpeed.

@SubscribeEvent
public void onBreakSpeed(BreakSpeed event) {
    if (!MiningAssistConfig.modifiedHardness || !Cavern.proxy.isSinglePlayer()) {
        return;
    }
    if (checking) {
        return;
    }
    EntityPlayer player = event.getEntityPlayer();
    IBlockState state = event.getState();
    if (!isActive(player, state)) {
        return;
    }
    MiningAssistUnit assist = MiningAssistUnit.get(player);
    MiningAssist type = MiningAssist.byPlayer(player);
    BlockPos pos = event.getPos();
    checking = true;
    MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
    if (!snapshot.isEmpty()) {
        event.setNewSpeed(assist.getBreakSpeed(snapshot));
    }
    checking = false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MiningSnapshot(cavern.miningassist.MiningSnapshot) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) MiningAssist(cavern.miningassist.MiningAssist) MiningAssistUnit(cavern.miningassist.MiningAssistUnit) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

MiningAssist (cavern.miningassist.MiningAssist)2 MiningAssistUnit (cavern.miningassist.MiningAssistUnit)2 MiningSnapshot (cavern.miningassist.MiningSnapshot)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 PlayerInteractionManager (net.minecraft.server.management.PlayerInteractionManager)1 NonNullList (net.minecraft.util.NonNullList)1 World (net.minecraft.world.World)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1