Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoHuNao committed Jan 20, 2024
1 parent 6844039 commit 6bd9ee9
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 44 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"


// compileOnly fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
// compileOnly fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
// compileOnly fg.deobf("dev.architectury:architectury-forge:${architectury_version}")
compileOnly fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
compileOnly fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
compileOnly fg.deobf("dev.architectury:architectury-forge:${architectury_version}")

//仅运行
implementation fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
implementation fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
implementation fg.deobf("dev.architectury:architectury-forge:${architectury_version}")
// implementation fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
// implementation fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
// implementation fg.deobf("dev.architectury:architectury-forge:${architectury_version}")

// runtimeOnly fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
// runtimeOnly fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.pancake.surviving_the_aftermath.common.data.datagen.EventSubscriber;
import com.pancake.surviving_the_aftermath.common.data.pack.AftermathModuleLoader;
import com.pancake.surviving_the_aftermath.common.init.ModAftermathModule;
import com.pancake.surviving_the_aftermath.common.init.ModStructurePieceTypes;
import com.pancake.surviving_the_aftermath.common.init.ModStructureTypes;
import com.pancake.surviving_the_aftermath.common.init.ModuleRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public interface IAftermath extends IModule<IAftermath> {
Supplier<Codec<IAftermath>> CODEC = () -> ModuleRegistry.AFTERMATH_REGISTRY.get().getCodec()
.dispatch("aftermath", IAftermath::type, IAftermath::codec);
ResourceLocation getRegistryName();
ResourceLocation getBarsResource();

int[] getBarsOffset();

boolean isCreate(Level level, BlockPos pos, @Nullable Player player);
void createRewards();
Expand All @@ -37,4 +40,6 @@ public interface IAftermath extends IModule<IAftermath> {
void setLevel(ServerLevel level);

AftermathState getState();

void setState(AftermathState state);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pancake.surviving_the_aftermath.api;

import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraftforge.eventbus.api.Event;

public interface IAftermathEvent {
Event getForge();
EventJS getKubeJS();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.pancake.surviving_the_aftermath.api.module.IAftermathModule;
import com.pancake.surviving_the_aftermath.common.data.pack.AftermathModuleLoader;
import com.pancake.surviving_the_aftermath.common.raid.module.BaseRaidModule;
import com.pancake.surviving_the_aftermath.compat.kubejs.util.AftermathEventJsUtil;
import com.pancake.surviving_the_aftermath.util.AftermathEventUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerBossEvent;
Expand Down Expand Up @@ -41,19 +43,20 @@ public BaseAftermath(AftermathState state,IAftermathModule module, Set<UUID> pla
public BaseAftermath(ServerLevel level) {
this.level = level;
this.module = getRandomAftermathModule();
this.state = AftermathState.START;
AftermathEventUtil.start(this,players,level);
}
public BaseAftermath(BaseRaidModule module, ServerLevel level) {
this.level = level;
this.module = module;
this.state = AftermathState.START;
AftermathEventUtil.start(this,players,level);
}


public BaseAftermath() {
}

protected abstract void init();

@Override
public void tick() {
if (isEnd()) return;
Expand All @@ -62,7 +65,7 @@ public void tick() {

if (state == AftermathState.VICTORY){
this.progressPercent = 0;
state = AftermathState.CELEBRATING;
AftermathEventUtil.celebrating(this,players,level);
}
}

Expand Down Expand Up @@ -125,6 +128,11 @@ public void setLevel(ServerLevel level) {
this.level = level;
}

@Override
public void setState(AftermathState state) {
this.state = state;
}

@Override
public boolean isEnd() {
return state == AftermathState.END;
Expand All @@ -136,7 +144,11 @@ public IAftermathModule getRandomAftermathModule() {
}

public void end(){
state = AftermathState.END;
AftermathEventUtil.end(this,players,level);
progress.removeAllPlayers();
}
public void lose(){
AftermathEventUtil.lose(this,players,level);
progress.removeAllPlayers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import com.mojang.serialization.JsonOps;
import com.pancake.surviving_the_aftermath.SurvivingTheAftermath;
import com.pancake.surviving_the_aftermath.api.AftermathManager;
import com.pancake.surviving_the_aftermath.api.Constant;
import com.pancake.surviving_the_aftermath.api.module.IAftermathModule;
import com.pancake.surviving_the_aftermath.common.init.ModuleRegistry;
import com.pancake.surviving_the_aftermath.compat.kubejs.event.AftermathEvents;
import com.pancake.surviving_the_aftermath.compat.kubejs.event.AftermathModifyEventJS;
import com.pancake.surviving_the_aftermath.compat.kubejs.util.AftermathEventJsUtil;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.GsonHelper;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.fml.ModList;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
Expand Down Expand Up @@ -48,9 +47,10 @@ protected void apply(Map<ResourceLocation, JsonElement> jsonElementMap, @NotNull
});
});

AFTERMATH_MODULE_MAP.asMap().forEach((resourceLocation, aftermathModules) -> {
AftermathEvents.MODIFY.post(new AftermathModifyEventJS(resourceLocation, aftermathModules)).pass();
});

if (ModList.get().isLoaded("kubejs")) {
AFTERMATH_MODULE_MAP.asMap().forEach(AftermathEventJsUtil::modify);
}

AftermathManager.getInstance().fillAftermathModuleMap(AFTERMATH_MODULE_MAP);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.pancake.surviving_the_aftermath.common.event;

import com.pancake.surviving_the_aftermath.api.IAftermath;
import com.pancake.surviving_the_aftermath.api.IAftermathEvent;
import com.pancake.surviving_the_aftermath.api.base.BaseAftermath;
import com.pancake.surviving_the_aftermath.api.base.BaseAftermathModule;
import com.pancake.surviving_the_aftermath.api.module.IAftermathModule;
import dev.latvian.mods.kubejs.event.EventJS;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;

import java.util.Set;
import java.util.UUID;

public abstract class AftermathEvent extends Event implements IAftermathEvent {
private final IAftermath aftermath;
private final IAftermathModule module;
private final Set<UUID> players;
private final ServerLevel level;

public AftermathEvent(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
this.aftermath = aftermath;
this.module = aftermath.getModule();
this.players = players;
this.level = level;
}

@Override
public Event getForge() {
return this;
}

@Override
public EventJS getKubeJS() {
return null;
}

@Cancelable
public static class Start extends AftermathEvent {
public Start(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath,players, level);
}
}
public static class End extends AftermathEvent {

public End(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
@Cancelable
public static class Ready extends AftermathEvent {

public Ready(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}

public static class Ongoing extends AftermathEvent {

public Ongoing(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
public static class Victory extends AftermathEvent {

public Victory(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
public static class Lose extends AftermathEvent {

public Lose(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}
@Cancelable
public static class Celebrating extends AftermathEvent {
public Celebrating(IAftermath aftermath, Set<UUID> players, ServerLevel level) {
super(aftermath, players, level);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.pancake.surviving_the_aftermath.common.event.subscriber;

import com.pancake.surviving_the_aftermath.SurvivingTheAftermath;
import com.pancake.surviving_the_aftermath.api.AftermathManager;
import net.minecraft.client.gui.components.LerpingBossEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;

@Mod.EventBusSubscriber(modid = SurvivingTheAftermath.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ClientForgeEvent {
@SubscribeEvent
public static void netherRaidProgress(CustomizeGuiOverlayEvent.BossEventProgress event) {
LerpingBossEvent bossEvent = event.getBossEvent();
AftermathManager manager = AftermathManager.getInstance();
manager.getAftermath(bossEvent.getId()).ifPresent(aftermath -> {
event.setCanceled(true);
var graphics = event.getGuiGraphics();
ResourceLocation resource = aftermath.getBarsResource();
int[] offset = aftermath.getBarsOffset();

if (resource == null || offset == null) {
return;
}

int frameWidth = offset[0];
int frameHeight = offset[1];
int barWidth = offset[2];
int barHeight = offset[3];
int frameOffset = offset[4];
int barOffset = offset[5];

//渲染进度条框
graphics.blit(resource, (graphics.guiWidth() - frameWidth) / 2, event.getY() - 10,
0, frameOffset, frameWidth, frameHeight);
//渲染进度条
graphics.blit(resource, (graphics.guiWidth() - barWidth) / 2, event.getY() - 10 + barOffset,
0, 0, (int) (barWidth * event.getBossEvent().getProgress()), barHeight);
event.setIncrement(frameHeight);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.pancake.surviving_the_aftermath.common.module.entity_info.EntityInfoWithPredicateModule;
import com.pancake.surviving_the_aftermath.common.raid.api.IRaid;
import com.pancake.surviving_the_aftermath.common.raid.module.BaseRaidModule;
import com.pancake.surviving_the_aftermath.util.AftermathEventUtil;
import com.pancake.surviving_the_aftermath.util.CodecUtils;
import com.pancake.surviving_the_aftermath.util.RandomUtils;
import com.pancake.surviving_the_aftermath.util.StructureUtils;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void tick() {
super.tick();

if (state == AftermathState.START){
state = AftermathState.READY;
AftermathEventUtil.ready(this,players,level);
}

if (state == AftermathState.ONGOING){
Expand Down Expand Up @@ -197,7 +198,7 @@ public boolean join(Entity entity) {
protected void checkNextWave(){
if (enemies.isEmpty()){
if(this.currentWave >= getModule().getWaves().size() - 1) {
state = AftermathState.VICTORY;
AftermathEventUtil.victory(this,players,level);
} else {
currentWave++;
totalEnemy = 0;
Expand All @@ -222,8 +223,8 @@ private void defaultSetSpawnPos(Level level,BlockPos startPos) {
if (level instanceof ServerLevel serverLevel){
List<IConditionModule> conditions = getModule().getConditions();
if (conditions == null){
startPos = startPos;
spawnPos.add(startPos);
this.startPos = startPos;
this.spawnPos.add(startPos);
return;
}
Optional<StructureConditionModule> module = conditions.stream()
Expand All @@ -237,8 +238,8 @@ private void defaultSetSpawnPos(Level level,BlockPos startPos) {
setMobSpawnPos(serverLevel1,metadata,startPos1,metaPos);
});
}else {
startPos = startPos;
spawnPos.add(startPos);
this.startPos = startPos;
this.spawnPos.add(startPos);
}
}
}
Expand All @@ -259,7 +260,7 @@ public void updateProgress() {

public void ready(){
if (readyTime <= 0){
state = AftermathState.ONGOING;
AftermathEventUtil.ongoing(this,players,level);
return;
}
this.progressPercent = 1 - (float) readyTime / getModule().getReadyTime();
Expand Down Expand Up @@ -293,6 +294,16 @@ public ResourceLocation getRegistryName() {
return SurvivingTheAftermath.asResource(IDENTIFIER);
}

@Override
public ResourceLocation getBarsResource() {
return null;
}

@Override
public int[] getBarsOffset() {
return null;
}

@Override
public BlockPos getStartPos() {
return startPos;
Expand Down
Loading

0 comments on commit 6bd9ee9

Please sign in to comment.