use of cavern.miningassist.MiningAssistUnit 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));
}
}
}
use of cavern.miningassist.MiningAssistUnit in project Cavern2 by kegare.
the class MiningAssistEventHooks method onHarvestDrops.
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onHarvestDrops(HarvestDropsEvent event) {
World world = event.getWorld();
if (world.isRemote) {
return;
}
EntityPlayer player = event.getHarvester();
if (player == null || player instanceof FakePlayer) {
return;
}
BlockPos pos = event.getPos();
MiningAssistUnit assist = MiningAssistUnit.get(player);
if (!assist.getCaptureDrops()) {
return;
}
NonNullList<ItemStack> items = NonNullList.create();
List<ItemStack> drops = event.getDrops();
float chance = event.getDropChance();
for (ItemStack stack : drops) {
if (CaveEventHooks.RANDOM.nextFloat() < chance) {
items.add(stack);
}
}
drops.clear();
assist.addDrops(pos, items);
}
use of cavern.miningassist.MiningAssistUnit 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;
}
Aggregations