Skip to content

Commit

Permalink
Patched lazy colors on BossDisplayAdapter and added CraftTweaker(Mine…
Browse files Browse the repository at this point in the history
…Tweaker) support.
  • Loading branch information
brunoxkk0 committed Aug 8, 2023
1 parent 6f6c19f commit b991784
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/staging-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: echo "::set-output name=sha::$(expr substr ${{ github.sha }} 1 7)"

- name: Set version based on generated hash
run: echo "VERSION=dev-${{ steps.short_sha.outputs.sha }}" >> $GITHUB_ENV
run: git tag dev-${{ steps.short_sha.outputs.sha }}

- name: Setup NecroTempus
run: ./gradlew clean setupDecompWorkspace --refresh-dependencies
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {
implementation deobfCurse('botania-225643:2283837')
implementation deobfCurse('baubles-227083:2224857')
implementation deobfCurse('customnpc-plus-480951:4606060')
implementation deobfCurse('crafttweaker-239197:2838720')
implementation 'com.github.CrucibleMC:Crucible:PR132-SNAPSHOT'
implementation 'org.avaje.ebeanorm:avaje-ebeanorm:8.1.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import io.github.cruciblemc.necrotempus.modules.features.title.network.TitlePacket;
import io.github.cruciblemc.necrotempus.modules.features.title.network.TitlePacketHandler;
import io.github.cruciblemc.necrotempus.proxy.CommonProxy;
import lombok.Getter;
import org.apache.logging.log4j.Logger;


@Mod(modid = Tags.MODID, name = Tags.MODNAME, version = Tags.VERSION)
public class NecroTempus {
Expand All @@ -37,8 +40,12 @@ public static NecroTempus getInstance() {

public static SimpleNetworkWrapper DISPATCHER;

@Getter
public Logger logger;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){
logger = event.getModLog();
proxy.preInit(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ private BossDisplayAdapterListener(){

private static final LinkedList<BossDisplayAdapter> CUSTOM_ADAPTERS = new LinkedList<>(BossDisplayAdapter.defaultList());


public void addCustomDisplayAdapter(BossDisplayAdapter adapter){
CUSTOM_ADAPTERS.add(adapter);
public static LinkedList<BossDisplayAdapter> getCustomAdapters() {
return CUSTOM_ADAPTERS;
}

@SubscribeEvent
Expand All @@ -53,7 +52,13 @@ public void onRenderLiving(RenderLivingEvent.Pre event) {

for (BossDisplayAdapter adapter : CUSTOM_ADAPTERS) {
if (adapter.getTargetClass().equals(event.entity.getClass().getName())) {

bossBar.setColor(adapter.getColor());

if(adapter.getLazyColor() != -1){
bossBar.setLazyColor(adapter.getLazyColor());
}

bossBar.setType(adapter.getType());
customized = true;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.github.cruciblemc.necrotempus.modules.features.bossbar.compat;

import cpw.mods.fml.common.FMLCommonHandler;
import io.github.cruciblemc.necrotempus.api.bossbar.BossBarColor;
import io.github.cruciblemc.necrotempus.api.bossbar.BossBarType;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.client.render.BossDisplayAdapterListener;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.component.BossDisplayAdapter;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

@ZenClass(value = "mods.necrotempus.BossBar")
public class CraftTweakerBossBar {

@ZenMethod
public static void customize(String entity, int color, String type){
MineTweakerAPI.apply(new BossBarCustomizeAction(entity, color, type));
}

public static class BossBarCustomizeAction implements IUndoableAction{

private final String entity;
private final BossBarColor color;
private final BossBarType type;

public BossBarCustomizeAction(String entity, int color, String type) {
this.entity = entity;
this.color = BossBarColor.valueOfString("$" + color);
this.type = BossBarType.valueOfString(type);
}

@Override
public boolean canUndo() {
return true;
}

@Override
public void apply() {
if(FMLCommonHandler.instance().getEffectiveSide().isClient()){
BossDisplayAdapter bossDisplayAdapter = new BossDisplayAdapter(entity, color, type);
BossDisplayAdapterListener.getCustomAdapters().add(bossDisplayAdapter);
}
}

@Override
public void undo() {
if(FMLCommonHandler.instance().getEffectiveSide().isClient()){
BossDisplayAdapterListener.getCustomAdapters().removeIf( el -> el.getTargetClass().equalsIgnoreCase(entity) );
}
}

@Override
public String describe() {
return String.format("Registering CustomBossBarAdapter for entity %s. (Color: RGB(%s), Type: %s)", entity, color.intValue(), type.getType());
}

@Override
public String describeUndo() {
return String.format("Removing CustomBossBarAdapter for entity %s. (Color: RGB(%s), Type: %s)", entity, color.intValue(), type.getType());
}

@Override
public Object getOverrideKey() {
return null;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.cruciblemc.necrotempus.modules.features.bossbar.compat;

import minetweaker.MineTweakerAPI;

public class ZenRegister {
public static void register() {
MineTweakerAPI.registerClass(CraftTweakerBossBar.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@

import io.github.cruciblemc.necrotempus.api.bossbar.BossBarColor;
import io.github.cruciblemc.necrotempus.api.bossbar.BossBarType;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Arrays;
import java.util.List;

@Data
@AllArgsConstructor
public class BossDisplayAdapter {

private String targetClass;
private final String targetClass;

private BossBarColor color;
private final BossBarColor color;

private BossBarType type;
private final BossBarType type;

private int lazyColor = -1;

public BossDisplayAdapter(String targetClass, BossBarColor color, BossBarType type){
this.targetClass = targetClass;
this.color = color;
this.type = type;

if(color == BossBarColor.LAZY){
lazyColor = color.intValue();
}

}

public static List<BossDisplayAdapter> defaultList(){
return Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import io.github.cruciblemc.necrotempus.NecroTempus;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.compat.ZenRegister;

public abstract class CommonProxy {

public void preInit(FMLPreInitializationEvent event){}

public void init(FMLInitializationEvent event){}
public void init(FMLInitializationEvent event){
try {
ZenRegister.register();
} catch (NoClassDefFoundError e) {
NecroTempus.getInstance().getLogger().warn("CraftTweaker is not available.");
}
}

public void postInit(FMLPostInitializationEvent event){}

Expand Down

0 comments on commit b991784

Please sign in to comment.