Skip to content

Commit

Permalink
Broke the barrier for making Occult Tomes in a ritual, now it's mostl…
Browse files Browse the repository at this point in the history
…y working. Additionally, paves a bit of way for the Warlock tome's recipe.
  • Loading branch information
starluneaux committed Apr 16, 2021
1 parent f54732e commit 4f10987
Show file tree
Hide file tree
Showing 25 changed files with 684 additions and 70 deletions.
38 changes: 30 additions & 8 deletions src/main/java/com/minttea/tomeofblood/TomeOfBloodMod.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
package com.minttea.tomeofblood;

import com.hollingsworth.arsnouveau.client.ClientHandler;
import com.minttea.tomeofblood.common.capabilities.WarlockPowerCapability;
import com.minttea.tomeofblood.common.events.LivingArmorManaBonus;
import com.minttea.tomeofblood.setup.LivingUpgradeRegistry;
import com.minttea.tomeofblood.setup.Registry;
import com.minttea.tomeofblood.common.network.Networking;
import com.minttea.tomeofblood.setup.*;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(TomeOfBloodMod.MODID)
@Mod.EventBusSubscriber(modid = TomeOfBloodMod.MODID)
public class TomeOfBloodMod
{




/**
* TODO: Robes of the Blood Mage
* TODO: Consider Blood Gems and their implications
* TODO: Consider the implications of Self-Sacrifice as a spell
* TODO: Debate multi-tiered Tomes of Blood
* TODO: Consider what mobs are possible
* TODO: Find a better Blood Scroll method
* TODO: Implement Botanic Tome
* TODO: Finish Recipe for Natural Tome
* TODO: Add Astral Sorcery into the Dev Environment and work on the Astral Tome
* TODO: Finish adding Occultism Recipes
* TODO: Add Warlock Tome Recipes and Empowering Prayers
* TODO: Update Blood Tome Recipes preserving NBT data
* TODO: Don't forget to add in a Tome of Blood carry over for those who update
* TODO: Option Registering of items in case mods aren't present.
*/
public static final String MODID = "tomeofblood";
// Directly reference a log4j logger.
public static final Logger LOGGER = LogManager.getLogger();

public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), ()-> ()-> new ServerProxy());

public static ItemGroup itemGroup = new ItemGroup(MODID) {
@Override
Expand All @@ -45,11 +55,23 @@ public TomeOfBloodMod() {
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(LivingArmorManaBonus.class);
Registry.RegistrationHandler.registerSpells();
WarlockPowerCapability.register();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
LivingUpgradeRegistry.register();

}

public void setup(final FMLCommonSetupEvent event)
{
WarlockPowerCapability.register();
Networking.register();
}
public void clientSetup(final FMLClientSetupEvent event){
proxy.init();
//FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientHandler::init);
}



// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static ScrollContainer fromNetwork(int windowId, PlayerInventory inv, Pac
private final ItemStack scroll;
public final IInventory scrollInv;
public ScrollContainer(int id, PlayerInventory playerInventory, ItemStack scroll) {
super(Registry.container, id);
super(Registry.RegistrationHandler.container, id);
this.scroll = scroll;

int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

public interface IWarlockPower {

double getCurrentPower();
int getCurrentPower();

int getMaxPower();

void setMaxPower(int max);

double setPower(final double power);
int setPower(final int power);

double addPower(final double powerToAdd);
int addPower(final int powerToAdd);

double refreshPower();
int refreshPower();

double spendPower(final double powerToSpend);
int spendPower(final int powerToSpend);


}
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);
}

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import net.minecraft.entity.LivingEntity;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class WarlockPower implements IWarlockPower{

private final LivingEntity entity;

private double power;
private int power;

private int maxPower;

Expand All @@ -20,7 +19,7 @@ public WarlockPower(@Nullable final LivingEntity entity)
}

@Override
public double getCurrentPower() {
public int getCurrentPower() {
return power;
}

Expand All @@ -35,7 +34,7 @@ public void setMaxPower(int max) {
}

@Override
public double setPower(double newPower) {
public int setPower(int newPower) {
if( newPower > getMaxPower())
this.power = getMaxPower();
else if(newPower<0)
Expand All @@ -46,17 +45,17 @@ else if(newPower<0)
}

@Override
public double addPower(double powerToAdd) {
public int addPower(int powerToAdd) {
return this.setPower(this.getCurrentPower() + powerToAdd);
}

@Override
public double refreshPower() {
public int refreshPower() {
return this.setPower(this.getMaxPower());
}

@Override
public double spendPower(double powerToSpend) {
public int spendPower(int powerToSpend) {
if(powerToSpend < 0)
powerToSpend = 0;
return this.setPower(this.getCurrentPower()-powerToSpend);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.minttea.tomeofblood.common.capabilities;

import com.hollingsworth.arsnouveau.common.capability.SerializableCapabilityProvider;

import com.minttea.tomeofblood.TomeOfBloodMod;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand All @@ -15,6 +15,7 @@
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.lwjgl.system.CallbackI;
Expand All @@ -27,35 +28,15 @@ public class WarlockPowerCapability {


@CapabilityInject(IWarlockPower.class)
public static Capability<IWarlockPower> WARLOCK_POWER = null;
public static final Capability<IWarlockPower> WARLOCK_POWER = Null();

public static final Direction DEFAULT_FACING = null;

public static final ResourceLocation ID = new ResourceLocation(TomeOfBloodMod.MODID, "warlock_power");

public static void register()
{
CapabilityManager.INSTANCE.register(IWarlockPower.class, new Capability.IStorage<IWarlockPower>()
{
@Nullable
@Override
public INBT writeNBT(Capability<IWarlockPower> capability, IWarlockPower instance, Direction side) {
CompoundNBT tag = new CompoundNBT();
tag.putDouble("current", instance.getCurrentPower());
tag.putInt("max", instance.getMaxPower());
return tag;
}

@Override
public void readNBT(Capability<IWarlockPower> capability, IWarlockPower instance, Direction side, INBT nbt) {
if(!(nbt instanceof CompoundNBT))
return;
CompoundNBT tag = (CompoundNBT) nbt;
instance.setMaxPower(tag.getInt("max"));
instance.setPower(tag.getInt("current"));

}
}, () -> new WarlockPower(null));
CapabilityManager.INSTANCE.register(IWarlockPower.class, new WarlockPowerStorage(), () -> new WarlockPower(null));
}


Expand Down Expand Up @@ -84,4 +65,18 @@ public static void attachCapabilities(final AttachCapabilitiesEvent<Entity> even
}

}

@SubscribeEvent
public static void playerClone(final PlayerEvent.Clone event)
{
getPower(event.getOriginal()).ifPresent(oldMaxPower -> {
getPower(event.getPlayer()).ifPresent(newMaxPower ->
{
newMaxPower.setMaxPower(oldMaxPower.getMaxPower());
newMaxPower.setPower(oldMaxPower.getCurrentPower());
}
);
}
);
}
}
Loading

0 comments on commit 4f10987

Please sign in to comment.