use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class SkillAreaMiner method activate.
@Override
public boolean activate(ItemStack tool, EntityPlayer player, BlockPos pos) {
World world = player.world;
IBlockState state = world.getBlockState(pos);
Item item = tool.getItem();
if (state == null || state.getBlock() == null) {
return false;
}
// Must be super tool with special enabled.
if (ToolHelper.getToolTier(tool).ordinal() < EnumMaterialTier.SUPER.ordinal() || !ToolHelper.isSpecialAbilityEnabled(tool)) {
return false;
}
// Tool must be effective on block!
if (!isToolEffective(tool, world, pos, state)) {
return false;
}
// Does player have enough chaos?
PlayerData data = PlayerDataHandler.get(player);
int cost = getCost(tool, player, pos);
if (data.chaos >= cost) {
data.drainChaos(cost);
} else {
String msg = SilentGems.localizationHelper.getLocalizedString("skill", "all.insufficientChaos");
ChatHelper.sendStatusMessage(player, msg, true);
return false;
}
RayTraceResult mop = raytraceFromEntity(world, player, false, 4.5);
if (mop == null) {
return false;
}
int sideHit = mop.sideHit.getIndex();
int xRange = 1;
int yRange = 1;
int zRange = 0;
switch(sideHit) {
case 0:
case 1:
yRange = 0;
zRange = 1;
break;
case 2:
case 3:
xRange = 1;
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
zRange = 1;
break;
}
int blocksBroken = 0;
final int x = pos.getX();
final int y = pos.getY();
final int z = pos.getZ();
for (int xPos = x - xRange; xPos <= x + xRange; xPos++) {
for (int yPos = y - yRange; yPos <= y + yRange; yPos++) {
for (int zPos = z - zRange; zPos <= z + zRange; zPos++) {
if (xPos == x && yPos == y && zPos == z) {
continue;
}
if (breakExtraBlock(tool, player.world, new BlockPos(xPos, yPos, zPos), player, pos)) {
++blocksBroken;
}
}
}
}
ToolHelper.incrementStatBlocksMined(tool, blocksBroken);
return true;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class SkillLumberjack method onGetBreakSpeed.
@Override
public void onGetBreakSpeed(PlayerEvent.BreakSpeed event) {
if (!event.getState().getBlock().isWood(event.getEntityPlayer().world, event.getPos())) {
return;
}
PlayerData data = PlayerDataHandler.get(event.getEntityPlayer());
int cost = event.getEntityPlayer().capabilities.isCreativeMode ? 0 : CHAOS_COST;
if (data.chaos >= cost) {
event.setNewSpeed(event.getNewSpeed() * DIG_SPEED_MULTIPLIER);
}
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ChaosUtil method canPlayerAcceptFullAmount.
// Use getAmountPlayerCanAccept instead
@Deprecated
public static boolean canPlayerAcceptFullAmount(EntityPlayer player, int amount) {
PlayerData data = PlayerDataHandler.get(player);
amount -= data.getMaxChaos() - data.getCurrentChaos();
for (ItemStack stack : getChaosStorageItems(player)) {
if (stack.getItem() instanceof IChaosStorage) {
amount -= ((IChaosStorage) stack.getItem()).receiveCharge(stack, amount, true);
}
}
return amount <= 0;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ItemGemSword method onItemLeftClickSL.
// ==============
// Item overrides
// ==============
@Override
public ActionResult<ItemStack> onItemLeftClickSL(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!player.isSneaking() || ToolHelper.getToolTier(stack).ordinal() < EnumMaterialTier.SUPER.ordinal()) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
if (world.isRemote) {
GuiChaosBar.INSTANCE.show();
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
int costToCast = getShotCost(player, stack);
int cooldown = getShotCooldown(player, stack);
PlayerData data = PlayerDataHandler.get(player);
if (data.chaos >= costToCast && data.magicCooldown <= 0) {
if (!player.capabilities.isCreativeMode) {
data.drainChaos(costToCast);
data.magicCooldown = cooldown;
stack.damageItem(1, player);
}
ToolHelper.incrementStatShotsFired(stack, 1);
if (!world.isRemote) {
for (EntityChaosProjectile shot : getShots(player, stack)) {
EntityHelper.safeSpawn(shot);
}
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ChaosBuff method applyToPlayer.
public void applyToPlayer(EntityPlayer player, int level, ItemStack stack) {
if (potion != null) {
int duration = getApplyDuration(player, level);
if (duration > 0) {
player.addPotionEffect(new PotionEffect(potion, duration, level - 1, false, false));
// (Tough As Nails) Remove hyper/hypothermia when using heat/cold resistance.
if (this == HEAT_RESISTANCE)
player.removeActivePotionEffect(hyperthermia);
else if (this == COLD_RESISTANCE)
player.removeActivePotionEffect(hypothermia);
}
}
if (this == FLIGHT) {
player.capabilities.allowFlying = true;
PlayerData data = PlayerDataHandler.get(player);
if (data != null)
data.flightTime = 100;
if (!player.world.isRemote && player.world.getTotalWorldTime() % 20 == 0) {
NetworkHandler.INSTANCE.sendTo(new MessageSetFlight(true), (EntityPlayerMP) player);
}
}
}
Aggregations