Add some missing code comments
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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 {
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
@@ -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)
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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)
|
||||||
|
@@ -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)) {
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -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()));
|
||||||
|
@@ -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()));
|
||||||
|
Reference in New Issue
Block a user