-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broke the barrier for making Occult Tomes in a ritual, now it's mostl…
…y working. Additionally, paves a bit of way for the Warlock tome's recipe.
- Loading branch information
1 parent
f54732e
commit 4f10987
Showing
25 changed files
with
684 additions
and
70 deletions.
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
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
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
58 changes: 58 additions & 0 deletions
58
...main/java/com/minttea/tomeofblood/common/capabilities/SerializableCapabilityProvider.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,58 @@ | ||
package com.minttea.tomeofblood.common.capabilities; | ||
|
||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.nbt.INBT; | ||
import net.minecraft.util.Direction; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class SerializableCapabilityProvider<HANDLER> extends SimpleCapabilityProvider<HANDLER> implements INBTSerializable<INBT> { | ||
|
||
/** | ||
* Create a provider for the default handler instance. | ||
* | ||
* @param capability The Capability instance to provide the handler for | ||
* @param facing The Direction to provide the handler for | ||
*/ | ||
public SerializableCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction facing) { | ||
this(capability, facing, capability.getDefaultInstance()); | ||
} | ||
|
||
/** | ||
* Create a provider for the specified handler instance. | ||
* | ||
* @param capability The Capability instance to provide the handler for | ||
* @param facing The Direction to provide the handler for | ||
* @param instance The handler instance to provide | ||
*/ | ||
public SerializableCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction facing, @Nullable final HANDLER instance) { | ||
super(capability, facing, instance); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public INBT serializeNBT() { | ||
final HANDLER instance = getInstance(); | ||
|
||
if (instance == null) { | ||
return null; | ||
} | ||
if(getCapability() == null) | ||
return new CompoundNBT(); | ||
return getCapability().writeNBT(instance, getFacing()); | ||
} | ||
|
||
@Override | ||
public void deserializeNBT(final INBT nbt) { | ||
final HANDLER instance = getInstance(); | ||
|
||
if (instance == null) { | ||
return; | ||
} | ||
|
||
getCapability().readNBT(instance, getFacing(), nbt); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/minttea/tomeofblood/common/capabilities/SimpleCapabilityProvider.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,95 @@ | ||
package com.minttea.tomeofblood.common.capabilities; | ||
|
||
import net.minecraft.util.Direction; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* A simple implementation of {@link ICapabilityProvider} that supports a single {@link Capability} handler instance. | ||
* | ||
* @author Choonster | ||
*/ | ||
public class SimpleCapabilityProvider<HANDLER> implements ICapabilityProvider { | ||
|
||
/** | ||
* The {@link Capability} instance to provide the handler for. | ||
*/ | ||
protected final Capability<HANDLER> capability; | ||
|
||
/** | ||
* The {@link Direction} to provide the handler for. | ||
*/ | ||
protected final Direction facing; | ||
|
||
/** | ||
* The handler instance to provide. | ||
*/ | ||
protected final HANDLER instance; | ||
|
||
/** | ||
* A lazy optional containing handler instance to provide. | ||
*/ | ||
protected final LazyOptional<HANDLER> lazyOptional; | ||
|
||
public SimpleCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction facing, @Nullable final HANDLER instance) { | ||
this.capability = capability; | ||
this.facing = facing; | ||
|
||
this.instance = instance; | ||
|
||
if (this.instance != null) { | ||
lazyOptional = LazyOptional.of(() -> this.instance); | ||
} else { | ||
lazyOptional = LazyOptional.empty(); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the handler for the capability requested on the specific side. | ||
* The return value CAN be null if the object does not support the capability. | ||
* The return value CAN be the same for multiple faces. | ||
* | ||
* @param capability The capability to check | ||
* @param facing The Side to check from: | ||
* CAN BE NULL. Null is defined to represent 'internal' or 'self' | ||
* @return A lazy optional containing the handler, if this object supports the capability. | ||
*/ | ||
@Override | ||
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction facing) { | ||
if(getCapability() == null) | ||
return LazyOptional.empty(); | ||
return getCapability().orEmpty(capability, lazyOptional); | ||
} | ||
|
||
/** | ||
* Get the {@link Capability} instance to provide the handler for. | ||
* | ||
* @return The Capability instance | ||
*/ | ||
public final Capability<HANDLER> getCapability() { | ||
return capability; | ||
} | ||
|
||
/** | ||
* Get the {@link Direction} to provide the handler for. | ||
* | ||
* @return The Direction to provide the handler for | ||
*/ | ||
@Nullable | ||
public Direction getFacing() { | ||
return facing; | ||
} | ||
|
||
/** | ||
* Get the handler instance. | ||
* | ||
* @return A lazy optional containing the handler instance | ||
*/ | ||
@Nullable | ||
public final HANDLER getInstance() { | ||
return instance; | ||
} | ||
} |
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
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
Oops, something went wrong.