-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
14 changed files
with
359 additions
and
17 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/pancake/surviving_the_aftermath/api/IStageData.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,20 @@ | ||
package com.pancake.surviving_the_aftermath.api; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
|
||
import java.util.Collection; | ||
|
||
public interface IStageData extends IIdentifier, INBTSerializable<CompoundTag> { | ||
Collection<String> getStages(); | ||
|
||
boolean hasStage(String stage); | ||
|
||
void addStage(String stage); | ||
|
||
void removeStage(String stage); | ||
|
||
void clear(); | ||
|
||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/pancake/surviving_the_aftermath/api/module/IConditionModule.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,14 @@ | ||
package com.pancake.surviving_the_aftermath.api.module; | ||
|
||
import com.pancake.surviving_the_aftermath.api.IIdentifier; | ||
import com.pancake.surviving_the_aftermath.api.IJSONSerializable; | ||
import com.pancake.surviving_the_aftermath.api.stage.LevelStageData; | ||
import com.pancake.surviving_the_aftermath.api.stage.PlayerStageData; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
|
||
public interface IConditionModule extends IIdentifier, IJSONSerializable, INBTSerializable<CompoundTag> { | ||
// boolean checkCondition(Player player, PlayerStageData stageData); | ||
} |
18 changes: 11 additions & 7 deletions
18
src/main/java/com/pancake/surviving_the_aftermath/api/module/IWeightedListModule.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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package com.pancake.surviving_the_aftermath.api.module; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.pancake.surviving_the_aftermath.api.IIdentifier; | ||
import com.pancake.surviving_the_aftermath.api.IJSONSerializable; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.util.random.SimpleWeightedRandomList; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public interface IWeightedListModule<E> extends IJSONSerializable, INBTSerializable<CompoundTag>, IIdentifier { | ||
SimpleWeightedRandomList<E> getWeightedList(); | ||
public interface IWeightedListModule<T> extends IJSONSerializable, INBTSerializable<CompoundTag>, IIdentifier { | ||
SimpleWeightedRandomList<T> getWeightedList(); | ||
|
||
void setWeightedList(Supplier<SimpleWeightedRandomList<E>> weightedList); | ||
void add(E e, int weight); | ||
void remove(E e); | ||
void setWeightedList(Supplier<SimpleWeightedRandomList<T>> weightedList); | ||
void add(T t, int weight); | ||
void remove(T t); | ||
|
||
List<T> getList(); | ||
} |
89 changes: 89 additions & 0 deletions
89
...a/com/pancake/surviving_the_aftermath/api/module/impl/condition/StageConditionModule.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,89 @@ | ||
package com.pancake.surviving_the_aftermath.api.module.impl.condition; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.pancake.surviving_the_aftermath.api.Constant; | ||
import com.pancake.surviving_the_aftermath.api.module.IConditionModule; | ||
import com.pancake.surviving_the_aftermath.common.capability.StageDataCap; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
|
||
public abstract class StageConditionModule implements IConditionModule { | ||
protected String stageName; | ||
|
||
public StageConditionModule(String stageName) { | ||
this.stageName = stageName; | ||
} | ||
|
||
public boolean checkCondition(Level level){ | ||
return false; | ||
} | ||
|
||
public boolean checkCondition(Player player){ | ||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public CompoundTag serializeNBT() { | ||
CompoundTag compoundTag = new CompoundTag(); | ||
compoundTag.putString("stageName", stageName); | ||
return compoundTag; | ||
} | ||
|
||
@Override | ||
public void deserializeNBT(CompoundTag nbt) { | ||
this.stageName = nbt.getString("stageName"); | ||
} | ||
|
||
@Override | ||
public void deserializeJson(JsonElement jsonElement) { | ||
this.stageName = jsonElement.getAsString(); | ||
} | ||
|
||
@Override | ||
public JsonElement serializeJson() { | ||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.addProperty("stageName", stageName); | ||
return jsonObject; | ||
} | ||
|
||
public static class LevelStageConditionModule extends StageConditionModule { | ||
public static final String IDENTIFIER = Constant.LEVEL_STAGES; | ||
public LevelStageConditionModule(String stageName) { | ||
super(stageName); | ||
} | ||
|
||
@Override | ||
public boolean checkCondition(Level level) { | ||
StageDataCap stageDataCap = StageDataCap.get(level).orElse(null); | ||
return stageDataCap.getStageData().hasStage(stageName); | ||
} | ||
|
||
@Override | ||
public String getUniqueIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
} | ||
|
||
public static class PlayerStageConditionModule extends StageConditionModule { | ||
public static final String IDENTIFIER = Constant.PLAYER_STAGES; | ||
public PlayerStageConditionModule(String stageName) { | ||
super(stageName); | ||
} | ||
|
||
@Override | ||
public boolean checkCondition(Player player) { | ||
StageDataCap stageDataCap = StageDataCap.get(player).orElse(null); | ||
return stageDataCap.getStageData().hasStage(stageName); | ||
} | ||
|
||
@Override | ||
public String getUniqueIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
} | ||
|
||
|
||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/pancake/surviving_the_aftermath/api/stage/LevelStageData.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,19 @@ | ||
package com.pancake.surviving_the_aftermath.api.stage; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.pancake.surviving_the_aftermath.api.Constant; | ||
import com.pancake.surviving_the_aftermath.api.IStageData; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.nbt.StringTag; | ||
import net.minecraft.nbt.Tag; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class LevelStageData extends StageData { | ||
public LevelStageData() { | ||
super(Constant.LEVEL_STAGES); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/pancake/surviving_the_aftermath/api/stage/PlayerStageData.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,13 @@ | ||
package com.pancake.surviving_the_aftermath.api.stage; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.pancake.surviving_the_aftermath.api.Constant; | ||
import com.pancake.surviving_the_aftermath.api.IStageData; | ||
|
||
import java.util.Set; | ||
|
||
public class PlayerStageData extends StageData{ | ||
public PlayerStageData() { | ||
super(Constant.PLAYER_STAGES); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/pancake/surviving_the_aftermath/api/stage/StageData.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,82 @@ | ||
package com.pancake.surviving_the_aftermath.api.stage; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.pancake.surviving_the_aftermath.api.Constant; | ||
import com.pancake.surviving_the_aftermath.api.IStageData; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.nbt.StringTag; | ||
import net.minecraft.nbt.Tag; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public abstract class StageData implements IStageData { | ||
private final Set<String> unlockedStages = Sets.newHashSet(); | ||
private final String identifier; | ||
|
||
public StageData(String identifier) { | ||
this.identifier = identifier; | ||
} | ||
@Override | ||
public Collection<String> getStages() { | ||
|
||
return Collections.unmodifiableCollection(this.unlockedStages); | ||
} | ||
|
||
@Override | ||
public boolean hasStage(String stage) { | ||
|
||
return this.unlockedStages.contains(stage.toLowerCase()); | ||
} | ||
|
||
@Override | ||
public void addStage(String stage) { | ||
|
||
this.unlockedStages.add(stage.toLowerCase()); | ||
} | ||
|
||
@Override | ||
public void removeStage(String stage) { | ||
|
||
this.unlockedStages.remove(stage.toLowerCase()); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
|
||
this.unlockedStages.clear(); | ||
} | ||
|
||
|
||
@Override | ||
public String toString () { | ||
|
||
return "StageData [unlockedStages=" + this.unlockedStages + "]"; | ||
} | ||
|
||
@Override | ||
public String getUniqueIdentifier() { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public CompoundTag serializeNBT() { | ||
final CompoundTag tag = new CompoundTag(); | ||
final ListTag list = new ListTag(); | ||
for (final String stage : this.unlockedStages) { | ||
list.add(StringTag.valueOf(stage)); | ||
} | ||
tag.put(identifier, list); | ||
return tag; | ||
} | ||
|
||
@Override | ||
public void deserializeNBT(CompoundTag nbt) { | ||
final ListTag list = nbt.getList(identifier, Tag.TAG_STRING); | ||
for (int tagIndex = 0; tagIndex < list.size(); tagIndex++) { | ||
this.addStage(list.getString(tagIndex)); | ||
} | ||
} | ||
} |
Oops, something went wrong.