-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
058b0f3
commit 939cb58
Showing
11 changed files
with
155 additions
and
46 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
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
91 changes: 91 additions & 0 deletions
91
...n/java/com/github/tartaricacid/touhoulittlemaid/entity/passive/MaidGameRecordManager.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,91 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.entity.passive; | ||
|
||
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntitySit; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.Tag; | ||
|
||
import static com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid.GAME_SKILL; | ||
import static com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid.GAME_STATUE; | ||
|
||
public class MaidGameRecordManager { | ||
private static final String GAME_SKILL_TAG = "MaidGameSkillData"; | ||
private static final String GOMOKU = "Gomoku"; | ||
private static final byte NONE = 0, WIN = 1, LOSE = 2; | ||
|
||
private final EntityMaid maid; | ||
|
||
public MaidGameRecordManager(EntityMaid maid) { | ||
this.maid = maid; | ||
} | ||
|
||
void defineSynchedData() { | ||
maid.getEntityData().define(GAME_SKILL, new CompoundTag()); | ||
maid.getEntityData().define(GAME_STATUE, (byte) 0); | ||
} | ||
|
||
void addAdditionalSaveData(CompoundTag compound) { | ||
compound.put(GAME_SKILL_TAG, getGameSkill()); | ||
} | ||
|
||
void readAdditionalSaveData(CompoundTag compound) { | ||
if (compound.contains(GAME_SKILL_TAG, Tag.TAG_COMPOUND)) { | ||
setGameSkill(compound.getCompound(GAME_SKILL_TAG)); | ||
} | ||
} | ||
|
||
void tick() { | ||
if (!(this.maid.getVehicle() instanceof EntitySit) && getGameStatue() != NONE) { | ||
resetStatue(); | ||
} | ||
} | ||
|
||
private CompoundTag getGameSkill() { | ||
return maid.getEntityData().get(GAME_SKILL); | ||
} | ||
|
||
private void setGameSkill(CompoundTag gameSkill) { | ||
maid.getEntityData().set(GAME_SKILL, gameSkill, true); | ||
} | ||
|
||
private byte getGameStatue() { | ||
return maid.getEntityData().get(GAME_STATUE); | ||
} | ||
|
||
private void setGameStatue(byte gameStatue) { | ||
maid.getEntityData().set(GAME_STATUE, gameStatue); | ||
} | ||
|
||
public int getGomokuWinCount() { | ||
CompoundTag gameSkill = this.getGameSkill(); | ||
if (gameSkill.contains(GOMOKU, Tag.TAG_INT)) { | ||
return gameSkill.getInt(GOMOKU); | ||
} | ||
return 0; | ||
} | ||
|
||
public void increaseGomokuWinCount() { | ||
CompoundTag gameSkill = this.getGameSkill(); | ||
if (gameSkill.contains(GOMOKU, Tag.TAG_INT)) { | ||
gameSkill.putInt(GOMOKU, gameSkill.getInt(GOMOKU) + 1); | ||
} else { | ||
gameSkill.putInt(GOMOKU, 1); | ||
} | ||
this.setGameSkill(gameSkill); | ||
} | ||
|
||
public boolean isWin() { | ||
return this.getGameStatue() == WIN; | ||
} | ||
|
||
public boolean isLost() { | ||
return this.getGameStatue() == LOSE; | ||
} | ||
|
||
public void markStatue(boolean isWin) { | ||
this.setGameStatue(isWin ? WIN : LOSE); | ||
} | ||
|
||
public void resetStatue() { | ||
this.setGameStatue(NONE); | ||
} | ||
} |
Oops, something went wrong.