use of de.siphalor.spiceoffabric.util.IHungerManager in project spiceoffabric by Siphalor.
the class MixinCakeBlock method eat.
@Redirect(method = "tryEat", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/HungerManager;add(IF)V"))
private static void eat(HungerManager hungerManager, int baseHunger, float baseSaturation, WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) {
ItemStack stack = new ItemStack(Items.CAKE);
FoodHistory foodHistory = ((IHungerManager) hungerManager).spiceOfFabric_getFoodHistory();
Config.setHungerExpressionValues(foodHistory.getTimesEaten(stack), baseHunger, baseSaturation, stack.getMaxUseTime());
hungerManager.add(Config.getHungerValue(), Config.getSaturationValue());
if (!world.isClient() && player instanceof ServerPlayerEntity) {
SpiceOfFabric.onEaten((ServerPlayerEntity) player, foodHistory, stack);
}
}
use of de.siphalor.spiceoffabric.util.IHungerManager in project spiceoffabric by Siphalor.
the class SoFClient method onInitializeClient.
@Override
public void onInitializeClient() {
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
if (lastSyncPacket != null) {
((IHungerManager) client.player.getHungerManager()).spiceOfFabric_getFoodHistory().read(lastSyncPacket);
lastSyncPacket.release();
lastSyncPacket = null;
}
});
ClientPlayNetworking.registerGlobalReceiver(SpiceOfFabric.SYNC_FOOD_HISTORY_S2C_PACKET, (client, handler, buf, responseSender) -> {
if (client.player != null && client.player.getHungerManager() != null) {
((IHungerManager) client.player.getHungerManager()).spiceOfFabric_getFoodHistory().read(buf);
} else {
lastSyncPacket = new PacketByteBuf(buf.copy());
lastSyncPacket.retain();
}
});
ClientPlayNetworking.registerGlobalReceiver(SpiceOfFabric.ADD_FOOD_S2C_PACKET, (client, handler, buf, responseSender) -> ((IHungerManager) client.player.getHungerManager()).spiceOfFabric_getFoodHistory().addFood(FoodHistoryEntry.from(buf)));
ClientPlayNetworking.registerGlobalReceiver(SpiceOfFabric.CLEAR_FOODS_S2C_PACKET, (client, handler, buf, responseSender) -> ((IHungerManager) client.player.getHungerManager()).spiceOfFabric_clearHistory());
}
use of de.siphalor.spiceoffabric.util.IHungerManager in project spiceoffabric by Siphalor.
the class AppleSkinPlugin method registerEvents.
@Override
public void registerEvents() {
FoodValuesEvent.EVENT.register(event -> {
if (event.player != null) {
Config.setHungerExpressionValues(((IHungerManager) event.player.getHungerManager()).spiceOfFabric_getFoodHistory().getTimesEaten(event.itemStack), event.modifiedFoodValues.hunger, event.modifiedFoodValues.saturationModifier, event.itemStack.getMaxUseTime());
event.modifiedFoodValues = new FoodValues(Config.getHungerValue(), Config.getSaturationValue());
}
});
}
use of de.siphalor.spiceoffabric.util.IHungerManager in project spiceoffabric by Siphalor.
the class SpiceOfFabric method updateMaxHealth.
public static void updateMaxHealth(ServerPlayerEntity player, boolean sync, boolean announce) {
EntityAttributeInstance maxHealthAttr = player.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
double oldValue = maxHealthAttr.getValue();
maxHealthAttr.removeModifier(PLAYER_HEALTH_MODIFIER_UUID);
FoodHistory foodHistory = ((IHungerManager) player.getHungerManager()).spiceOfFabric_getFoodHistory();
maxHealthAttr.addPersistentModifier(createHealthModifier(foodHistory.getCarrotHealthOffset(player)));
if (sync) {
player.networkHandler.sendPacket(new EntityAttributesS2CPacket(player.getId(), Collections.singleton(maxHealthAttr)));
player.networkHandler.sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel()));
}
if (announce && maxHealthAttr.getValue() > oldValue) {
player.world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1F, 1F);
}
}
use of de.siphalor.spiceoffabric.util.IHungerManager in project spiceoffabric by Siphalor.
the class MixinServerPlayerEntity method onPlayerCopied.
@Inject(method = "copyFrom", at = @At("RETURN"))
public void onPlayerCopied(ServerPlayerEntity reference, boolean exact, CallbackInfo callbackInfo) {
if (!exact) {
Pair<Double, Double> respawnHunger = Config.getRespawnHunger(reference.getHungerManager().getFoodLevel(), reference.getHungerManager().getSaturationLevel());
hungerManager.setFoodLevel((int) Math.max(respawnHunger.getFirst(), reference.getHungerManager().getFoodLevel()));
((IHungerManager) hungerManager).spiceOfFabric_setSaturationLevel((float) (double) respawnHunger.getSecond());
FoodHistory foodHistory = ((IHungerManager) reference.getHungerManager()).spiceOfFabric_getFoodHistory();
if (Config.respawn.resetHistory) {
foodHistory.resetHistory();
}
if (Config.respawn.resetCarrotMode) {
foodHistory.resetCarrotHistory();
EntityAttributeInstance maxHealthAttr = getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
maxHealthAttr.removeModifier(SpiceOfFabric.PLAYER_HEALTH_MODIFIER_UUID);
maxHealthAttr.addPersistentModifier(SpiceOfFabric.createHealthModifier(foodHistory.getCarrotHealthOffset(((ServerPlayerEntity) (Object) this))));
}
((IHungerManager) hungerManager).spiceOfFabric_setFoodHistory(foodHistory);
SpiceOfFabric.syncFoodHistory((ServerPlayerEntity) (Object) this);
}
}
Aggregations