Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Finish food stats changes - Fixed sync issues, Minor start to balanci…
…ng nutrition and thirst. Fixes #108
- Loading branch information
1 parent
e7bf066
commit c32cd1f
Showing
8 changed files
with
224 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/net/dries007/tfc/network/PacketFoodStatsReplace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
*/ | ||
|
||
package net.dries007.tfc.network; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.util.FoodStats; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.dries007.tfc.TerraFirmaCraft; | ||
import net.dries007.tfc.api.capability.food.CapabilityFood; | ||
import net.dries007.tfc.api.capability.food.FoodStatsTFC; | ||
import net.dries007.tfc.api.capability.food.IFoodStatsTFC; | ||
|
||
/** | ||
* This packet is send to client to signal that it may need to replace the vanilla FoodStats with a TFC version | ||
* Since all the relevant events where this is listened for are server only | ||
* {@link CapabilityFood} | ||
*/ | ||
public class PacketFoodStatsReplace implements IMessage | ||
{ | ||
public PacketFoodStatsReplace() {} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) {} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) {} | ||
|
||
public static final class Handler implements IMessageHandler<PacketFoodStatsReplace, IMessage> | ||
{ | ||
@Override | ||
public IMessage onMessage(PacketFoodStatsReplace message, MessageContext ctx) | ||
{ | ||
TerraFirmaCraft.getProxy().getThreadListener(ctx).addScheduledTask(() -> { | ||
EntityPlayer player = TerraFirmaCraft.getProxy().getPlayer(ctx); | ||
if (player != null) | ||
{ | ||
FoodStats stats = player.getFoodStats(); | ||
if (!(stats instanceof IFoodStatsTFC)) | ||
{ | ||
player.foodStats = new FoodStatsTFC(player, stats); | ||
} | ||
} | ||
}); | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.