use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ChaosUtil method getAmountPlayerCanAccept.
/**
* Gets the amount of chaos the player could receive, include available capacity in items that store chaos.
*/
public static int getAmountPlayerCanAccept(EntityPlayer player, int maxToSend) {
PlayerData data = PlayerDataHandler.get(player);
int amount = data.getMaxChaos() - data.getCurrentChaos();
for (ItemStack stack : getChaosStorageItems(player)) {
amount += ((IChaosStorage) stack.getItem()).receiveCharge(stack, maxToSend - amount, true);
if (amount >= maxToSend)
return maxToSend;
}
return amount;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ChaosUtil method getTotalChaosAvailable.
/**
* Gets the total amount of chaos the player has available, including chaos stored in items.
*/
public static int getTotalChaosAvailable(EntityPlayer player) {
PlayerData data = PlayerDataHandler.get(player);
int amount = data.getCurrentChaos();
for (ItemStack stack : getChaosStorageItems(player)) {
if (stack.getItem() instanceof IChaosStorage) {
amount += ((IChaosStorage) stack.getItem()).getCharge(stack);
}
}
return amount;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class ItemGemHoe method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (ToolHelper.isBroken(stack)) {
return EnumActionResult.PASS;
}
int tilledCount = 0;
EnumActionResult result;
// Till the target block first.
result = super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
if (result == EnumActionResult.SUCCESS) {
++tilledCount;
} else {
return EnumActionResult.FAIL;
}
// Do we have super till and can it be used?
ToolSkill skill = ToolHelper.getSuperSkill(stack);
boolean skillEnabled = skill instanceof SkillAreaTill && ToolHelper.isSpecialAbilityEnabled(stack);
int skillCost = skill != null ? skill.getCost(stack, player, pos) : 0;
PlayerData data = PlayerDataHandler.get(player);
// Must have tilled first block, has skill and is enabled, player has enough chaos.
if (tilledCount > 0 && skillEnabled && data.getCurrentChaos() >= skillCost) {
EnumFacing playerFacing = player.getHorizontalFacing();
// Tilling up to 8 extra blocks in the direction the player is facing.
for (int i = 0, yOffset = 0; i < 8; ++i) {
BlockPos blockpos = pos.offset(playerFacing, i + 1).up(yOffset);
if (super.onItemUse(player, world, blockpos, hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Same height.
++tilledCount;
} else if (super.onItemUse(player, world, blockpos.up(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Go up one block.
++tilledCount;
++yOffset;
} else if (super.onItemUse(player, world, blockpos.down(1), hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
// Go down one block.
++tilledCount;
--yOffset;
} else {
// Hit a cliff or wall.
break;
}
}
if (tilledCount > 1) {
if (data != null) {
data.drainChaos(skillCost);
}
}
}
// Sound, XP, damage, stats
if (tilledCount > 0) {
world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1f, 1f);
if (!world.isRemote) {
ToolSoul soul = SoulManager.getSoul(stack);
if (soul != null) {
soul.addXp((int) (ToolSoul.XP_FACTOR_TILLING * tilledCount), stack, player);
}
ToolHelper.incrementStatBlocksTilled(stack, tilledCount);
ToolHelper.attemptDamageTool(stack, tilledCount, player);
}
}
return EnumActionResult.SUCCESS;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class MessageDataSync method handleMessage.
@Override
@SideOnly(Side.CLIENT)
public IMessage handleMessage(MessageContext context) {
ClientTickHandler.scheduledActions.add(() -> {
PlayerData data = PlayerDataHandler.get(SilentGems.proxy.getClientPlayer());
data.readFromNBT(tags);
GuiChaosBar.INSTANCE.update(data.chaos, data.maxChaos);
});
return null;
}
use of net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onLivingDeath.
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
Entity entitySource = event.getSource().getTrueSource();
EntityPlayer player = null;
if (event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer deadPlayer = (EntityPlayer) event.getEntityLiving();
PlayerData data = PlayerDataHandler.get(deadPlayer);
data.haloTime = data.HALO_TIME_DEFAULT;
}
if (entitySource instanceof EntityPlayer) {
player = (EntityPlayer) entitySource;
} else if (entitySource instanceof EntityChaosProjectile) {
EntityChaosProjectile projectile = (EntityChaosProjectile) entitySource;
EntityLivingBase shooter = projectile.getShooter();
if (shooter instanceof EntityPlayer)
player = (EntityPlayer) shooter;
}
if (player != null) {
ItemStack weapon = player.getHeldItem(EnumHand.MAIN_HAND);
if (StackHelper.isValid(weapon) && weapon.getItem() instanceof ITool)
ToolHelper.incrementStatKillCount(weapon, 1);
}
}
Aggregations