Add some missing code comments

This commit is contained in:
2022-11-30 22:15:30 +02:00
parent 4ce90ca8bd
commit 48c0dff0dd
10 changed files with 46 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package me.hypherionmc.craterlib.api.blockentities.caps;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 24/09/2022 * @date 24/09/2022
* Wrapper Class for Forge Capabilities to remove duplicate code from Modules
*/ */
public enum ForgeCapability { public enum ForgeCapability {
ENERGY, ENERGY,

View File

@@ -15,6 +15,7 @@ import java.util.Optional;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 24/09/2022 * @date 24/09/2022
* A Wrapped Block Entity to incorporate CraterLib's universal capability provider
*/ */
public class CraterBlockEntity extends BlockEntity implements IForgeCapProvider { public class CraterBlockEntity extends BlockEntity implements IForgeCapProvider {

View File

@@ -9,7 +9,7 @@ import java.util.HashMap;
/** /**
* Controls Config File Reloads and Events * Controls Config File Reloads and Events
*/ */
public class ConfigController implements Serializable { public final class ConfigController implements Serializable {
/** /**
* Cache of registered configs * Cache of registered configs

View File

@@ -8,6 +8,7 @@ import java.lang.annotation.Target;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 03/07/2022 * @date 03/07/2022
* Used to determine if a Config section should be rendered as a separate screen
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)

View File

@@ -5,6 +5,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/**
* //TODO Currently unused, but to be used with Config Syncing in the future
*/
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface Syncable { public @interface Syncable {

View File

@@ -8,6 +8,7 @@ import java.lang.annotation.Target;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 03/07/2022 * @date 03/07/2022
* Provides tooltips to the config GUI
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)

View File

@@ -7,15 +7,29 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 21/06/2022 * @date 21/06/2022
* Event Bus handler for CraterLib Events
*/ */
public class CraterEventBus { public class CraterEventBus {
private static final ConcurrentHashMap<Class<? extends Event>, List<IEventExecutor<?>>> map = new ConcurrentHashMap();
/** List of registered events **/
private static final ConcurrentHashMap<Class<? extends Event>, List<IEventExecutor<?>>> map = new ConcurrentHashMap<>();
/**
* Register an event to be processed
* @param clazz a Class implementing @link{Event}
* @param handler - The callback for when the Event is Fired
* @param <T>
*/
public static <T extends Event> void register(Class<T> clazz, IEventExecutor<T> handler) { public static <T extends Event> void register(Class<T> clazz, IEventExecutor<T> handler) {
if (!map.containsKey(clazz)) map.put(clazz, new ArrayList<>()); if (!map.containsKey(clazz)) map.put(clazz, new ArrayList<>());
map.get(clazz).add(handler); map.get(clazz).add(handler);
} }
/**
* Used internally to fire events
* @param event The type of event that will be fired
* @return True or False based on if the event is cancelled or not
*/
public static boolean post(Event event) { public static boolean post(Event event) {
Class<? extends Event> clazz = event.getClass(); Class<? extends Event> clazz = event.getClass();
if (map.containsKey(clazz)) { if (map.containsKey(clazz)) {

View File

@@ -3,14 +3,23 @@ package me.hypherionmc.craterlib.events;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 21/06/2022 * @date 21/06/2022
* CraterLib universal event
*/ */
public class Event { public class Event {
private boolean cancelled; private boolean cancelled;
/**
* Can the event be cancelled. Override this method to control the behaviour
* @return
*/
public boolean isCancellable() { public boolean isCancellable() {
return false; return false;
} }
/**
* Cancel the event
* @param canceled True to cancel the event
*/
public void setCancelled(boolean canceled) { public void setCancelled(boolean canceled) {
if (!this.isCancellable()) { if (!this.isCancellable()) {
throw new RuntimeException("Cannot cancel event " + this); throw new RuntimeException("Cannot cancel event " + this);
@@ -18,7 +27,10 @@ public class Event {
this.cancelled = canceled; this.cancelled = canceled;
} }
/**
* Used Internally to check if the event is cancelled
* @return
*/
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

View File

@@ -11,10 +11,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 17/06/2022 * @date 17/06/2022
* Mixin to accommodate Block Color Registration across multiple Modloaders
*/ */
@Mixin(BlockColors.class) @Mixin(BlockColors.class)
public class BlockColorsMixin { public class BlockColorsMixin {
/**
* Inject into Vanilla code to fire off our event
* @param cir
*/
@Inject(method = "createDefault", at = @At("RETURN")) @Inject(method = "createDefault", at = @At("RETURN"))
private static void injectBlockColors(CallbackInfoReturnable<BlockColors> cir) { private static void injectBlockColors(CallbackInfoReturnable<BlockColors> cir) {
CraterEventBus.post(new ColorRegistrationEvent.BLOCKS(cir.getReturnValue())); CraterEventBus.post(new ColorRegistrationEvent.BLOCKS(cir.getReturnValue()));

View File

@@ -12,10 +12,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
/** /**
* @author HypherionSA * @author HypherionSA
* @date 17/06/2022 * @date 17/06/2022
* Mixin to accommodate Item Color Registration across multiple Modloaders
*/ */
@Mixin(ItemColors.class) @Mixin(ItemColors.class)
public class ItemColorsMixin { public class ItemColorsMixin {
/**
* Inject into Vanilla code to fire off our event
* @param cir
*/
@Inject(method = "createDefault", at = @At("RETURN")) @Inject(method = "createDefault", at = @At("RETURN"))
private static void injectItemColors(BlockColors $$0, CallbackInfoReturnable<ItemColors> cir) { private static void injectItemColors(BlockColors $$0, CallbackInfoReturnable<ItemColors> cir) {
CraterEventBus.post(new ColorRegistrationEvent.ITEMS(cir.getReturnValue())); CraterEventBus.post(new ColorRegistrationEvent.ITEMS(cir.getReturnValue()));