-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
471f47b
commit 0f6b7c4
Showing
15 changed files
with
199 additions
and
1 deletion.
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
7 changes: 7 additions & 0 deletions
7
Common/src/main/java/com/blamejared/clumps/api/events/IEventHandler.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,7 @@ | ||
package com.blamejared.clumps.api.events; | ||
|
||
public interface IEventHandler<T, U> { | ||
|
||
U handle(T event); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
Common/src/main/java/com/blamejared/clumps/api/events/IValueEvent.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,22 @@ | ||
package com.blamejared.clumps.api.events; | ||
|
||
/** | ||
* Used to mutate the value of experience before repairing player's items and giving the rest to the player. | ||
*/ | ||
public interface IValueEvent { | ||
|
||
/** | ||
* Sets the value of the experience orb. | ||
* | ||
* @param value The new value to set. | ||
*/ | ||
void setValue(int value); | ||
|
||
/** | ||
* Gets the value of the experience orb. | ||
* | ||
* @return the value of the experience orb. | ||
*/ | ||
int getValue(); | ||
|
||
} |
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
13 changes: 13 additions & 0 deletions
13
Common/src/main/java/com/blamejared/clumps/platform/IEventHelper.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.blamejared.clumps.platform; | ||
|
||
|
||
import com.blamejared.clumps.api.events.IValueEvent; | ||
import com.mojang.datafixers.util.Either; | ||
|
||
import java.util.Optional; | ||
|
||
public interface IEventHelper { | ||
|
||
Either<IValueEvent, Integer> fireValueEvent(int value); | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
Common/src/main/java/com/blamejared/clumps/platform/Services.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.blamejared.clumps.platform; | ||
|
||
import com.blamejared.clumps.ClumpsCommon; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
public class Services { | ||
|
||
public static final IEventHelper EVENT = load(IEventHelper.class); | ||
|
||
public static <T> T load(Class<T> clazz) { | ||
|
||
final T loadedService = ServiceLoader.load(clazz) | ||
.findFirst() | ||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName())); | ||
ClumpsCommon.LOG.debug("Loaded {} for service {}", loadedService, clazz); | ||
return loadedService; | ||
} | ||
|
||
} |
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
15 changes: 15 additions & 0 deletions
15
Fabric/src/main/java/com/blamejared/clumps/api/events/ClumpsEvents.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,15 @@ | ||
package com.blamejared.clumps.api.events; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
|
||
public class ClumpsEvents { | ||
|
||
public static final Event<IEventHandler<ValueEvent, Void>> VALUE_EVENT = EventFactory.createArrayBacked(IEventHandler.class, listeners -> event -> { | ||
for(IEventHandler<ValueEvent, Void> listener : listeners) { | ||
listener.handle(event); | ||
} | ||
return null; | ||
}); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
Fabric/src/main/java/com/blamejared/clumps/api/events/ValueEvent.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,33 @@ | ||
|
||
package com.blamejared.clumps.api.events; | ||
|
||
/** | ||
* Used to mutate the value of experience before repairing player's items and giving the rest to the player. | ||
*/ | ||
public class ValueEvent implements IValueEvent { | ||
|
||
private int value; | ||
|
||
/** | ||
* Sets the value of the experience orb. | ||
* | ||
* @param value The new value to set. | ||
*/ | ||
@Override | ||
public void setValue(int value) { | ||
|
||
this.value = value; | ||
} | ||
|
||
/** | ||
* Gets the value of the experience orb. | ||
* | ||
* @return the value of the experience orb. | ||
*/ | ||
@Override | ||
public int getValue() { | ||
|
||
return value; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Fabric/src/main/java/com/blamejared/clumps/platform/FabricEventHandler.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,25 @@ | ||
package com.blamejared.clumps.platform; | ||
|
||
import com.blamejared.clumps.api.events.ClumpsEvents; | ||
import com.blamejared.clumps.api.events.IValueEvent; | ||
import com.blamejared.clumps.api.events.ValueEvent; | ||
import com.mojang.datafixers.util.Either; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.util.Optional; | ||
|
||
public class FabricEventHandler implements IEventHelper { | ||
|
||
@Override | ||
public Either<IValueEvent, Integer> fireValueEvent(int value) { | ||
|
||
ValueEvent event = new ValueEvent(); | ||
if(FabricLoader.getInstance().isModLoaded("fabric")) { | ||
ClumpsEvents.VALUE_EVENT.invoker().handle(event); | ||
return Either.right(event.getValue()); | ||
} | ||
|
||
return Either.right(event.getValue()); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
Fabric/src/main/resources/META-INF/services/com.blamejared.clumps.platform.IEventHelper
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 @@ | ||
com.blamejared.clumps.platform.FabricEventHandler |
26 changes: 26 additions & 0 deletions
26
Forge/src/main/java/com/blamejared/clumps/api/events/ValueEvent.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,26 @@ | ||
package com.blamejared.clumps.api.events; | ||
|
||
import net.minecraftforge.eventbus.api.Event; | ||
|
||
public class ValueEvent extends Event implements IValueEvent { | ||
|
||
private int value; | ||
|
||
public ValueEvent(int value) { | ||
|
||
this.value = value; | ||
} | ||
|
||
@Override | ||
public void setValue(int value) { | ||
|
||
this.value = value; | ||
} | ||
|
||
@Override | ||
public int getValue() { | ||
|
||
return value; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
Forge/src/main/java/com/blamejared/clumps/platform/ForgeEventHandler.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.blamejared.clumps.platform; | ||
|
||
import com.blamejared.clumps.api.events.IValueEvent; | ||
import com.blamejared.clumps.api.events.ValueEvent; | ||
import com.mojang.datafixers.util.Either; | ||
import net.minecraftforge.common.MinecraftForge; | ||
|
||
import java.util.Optional; | ||
|
||
public class ForgeEventHandler implements IEventHelper { | ||
|
||
@Override | ||
public Either<IValueEvent, Integer> fireValueEvent(int value) { | ||
|
||
ValueEvent event = new ValueEvent(value); | ||
MinecraftForge.EVENT_BUS.post(event); | ||
return Either.left(event); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
Forge/src/main/resources/META-INF/services/com.blamejared.clumps.platform.IEventHelper
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 @@ | ||
com.blamejared.clumps.platform.ForgeEventHandler |
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