Skip to content

Commit

Permalink
Fix many errors in API files
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitteh6660 committed Jun 7, 2024
1 parent 64c6d5e commit 9f80c32
Show file tree
Hide file tree
Showing 78 changed files with 665 additions and 599 deletions.
34 changes: 5 additions & 29 deletions src/main/java/thebetweenlands/api/IBetweenlandsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import java.util.List;
import java.util.function.Predicate;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import thebetweenlands.api.aspect.IAspectType;
import thebetweenlands.api.entity.IEntityMusic;
import thebetweenlands.api.entity.IEntityMusicProvider;
import thebetweenlands.api.recipes.IAnimatorRecipe;
import thebetweenlands.api.recipes.ICompostBinRecipe;
import thebetweenlands.api.recipes.IDruidAltarRecipe;
Expand Down Expand Up @@ -110,13 +105,13 @@ public interface IBetweenlandsAPI {
* Registers an entity to be equippable with amulets
* @param entity
*/
public void registerAmuletSupportingEntity(Class<? extends EntityLivingBase> entity);
public void registerAmuletSupportingEntity(Class<? extends LivingEntity> entity);

/**
* Unregisters an entity from being equippable with amulets
* @param entity
*/
public void unregisterAmuletSupportingEntity(Class<? extends EntityLivingBase> entity);
public void unregisterAmuletSupportingEntity(Class<? extends LivingEntity> entity);

/**
* Adds an item to the overworld item whitelist
Expand Down Expand Up @@ -154,23 +149,4 @@ public interface IBetweenlandsAPI {
* @param aspectCount
*/
public void addStaticAspectsToItem(ItemStack item, IItemStackMatcher matcher, int tier, int group, float amountMultiplier, float amountVariation, int aspectCount);

/**
* Registers an entity music provider which allows playing music around an entity or to change
* the music of a mob implementing {@link IEntityMusic}
* @param entityCls
* @param musicProvider
* @return ture if successful. May be false if a music provider has already been registered for the specified entity class
*/
@SideOnly(Side.CLIENT)
public boolean registerEntityMusicProvider(Class<? extends Entity> entityCls, IEntityMusicProvider musicProvider);

/**
* Unregisters an entity music provider
* @param entityCls
* @param musicProvider
* @return
*/
@SideOnly(Side.CLIENT)
public boolean unregisterEntityMusicProvider(Class<? extends Entity> entityCls, IEntityMusicProvider musicProvider);
}
23 changes: 12 additions & 11 deletions src/main/java/thebetweenlands/api/aspect/Aspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import java.math.RoundingMode;
import java.text.DecimalFormat;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundTag;
import thebetweenlands.common.registries.AspectRegistry;

public final class Aspect implements Comparable<Aspect> {
public static final DecimalFormat ASPECT_AMOUNT_FORMAT = new DecimalFormat("#.##");

public static final DecimalFormat ASPECT_AMOUNT_FORMAT = new DecimalFormat("#.##");

static {
ASPECT_AMOUNT_FORMAT.setRoundingMode(RoundingMode.CEILING);
}

/**
* The type of this aspect
*/
Expand All @@ -28,24 +29,24 @@ public Aspect(IAspectType aspect, int amount) {
this.type = aspect;
this.amount = amount;
}

public float getDisplayAmount() {
return this.amount / 1000.0F;
}

public String getRoundedDisplayAmount() {
return ASPECT_AMOUNT_FORMAT.format(this.getDisplayAmount());
return ASPECT_AMOUNT_FORMAT.format(this.getDisplayAmount() - 0.00001f);
}

public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setString("aspect", this.type.getName());
nbt.setInteger("amount", this.amount);
public CompoundTag save(CompoundTag nbt) {
nbt.putString("aspect", this.type.getName());
nbt.putInt("amount", this.amount);
return nbt;
}

public static Aspect readFromNBT(NBTTagCompound nbt) {
public static Aspect load(CompoundTag nbt) {
String aspectName = nbt.getString("aspect");
int amount = nbt.getInteger("amount");
int amount = nbt.getInt("amount");
IAspectType aspectType = AspectRegistry.getAspectTypeFromName(aspectName);
if(aspectType != null) {
return new Aspect(aspectType, amount);
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/thebetweenlands/api/aspect/AspectContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import thebetweenlands.common.registries.AspectRegistry;

/**
Expand Down Expand Up @@ -45,10 +45,10 @@ private Storage(IAspectType type, AspectContainer container) {
* @param nbt
* @return
*/
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("dynamic", this.dynamicAmount);
nbt.setInteger("storedStatic", this.storedStaticAmount);
nbt.setBoolean("hasStoredStatic", this.hasStoredStaticAmount);
public CompoundTag save(CompoundTag nbt) {
nbt.putInt("dynamic", this.dynamicAmount);
nbt.putInt("storedStatic", this.storedStaticAmount);
nbt.putBoolean("hasStoredStatic", this.hasStoredStaticAmount);
return nbt;
}

Expand All @@ -57,9 +57,9 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
* @param nbt
* @return
*/
public Storage readFromNBT(NBTTagCompound nbt) {
this.dynamicAmount = nbt.getInteger("dynamic");
this.storedStaticAmount = nbt.getInteger("storedStatic");
public Storage load(CompoundTag nbt) {
this.dynamicAmount = nbt.getInt("dynamic");
this.storedStaticAmount = nbt.getInt("storedStatic");
this.hasStoredStaticAmount = nbt.getBoolean("hasStoredStatic");
return this;
}
Expand Down Expand Up @@ -263,8 +263,8 @@ public final boolean isEmpty() {
* @param nbt
* @return
*/
public NBTTagCompound save(NBTTagCompound nbt) {
NBTTagList typesList = new NBTTagList();
public CompoundTag save(CompoundTag nbt) {
ListTag typesList = new ListTag();
for(Entry<IAspectType, Storage> entry : this.storage.entrySet()) {
IAspectType type = entry.getKey();
Storage storage = entry.getValue();
Expand All @@ -274,13 +274,13 @@ public NBTTagCompound save(NBTTagCompound nbt) {
continue;
}

NBTTagCompound storageNbt = new NBTTagCompound();
storageNbt.setTag("aspect", type.writeToNBT(new NBTTagCompound()));
storageNbt.setTag("storage", storage.writeToNBT(new NBTTagCompound()));
CompoundTag storageNbt = new CompoundTag();
storageNbt.put("aspect", type.save(new CompoundTag()));
storageNbt.put("storage", storage.save(new CompoundTag()));

typesList.appendTag(storageNbt);
typesList.add(storageNbt);
}
nbt.setTag("container", typesList);
nbt.put("container", typesList);
return nbt;
}

Expand All @@ -290,15 +290,15 @@ public NBTTagCompound save(NBTTagCompound nbt) {
* @param staticAspects
* @return
*/
public AspectContainer read(NBTTagCompound nbt) {
NBTTagList typesList = nbt.getTagList("container", Constants.NBT.TAG_COMPOUND);
for(int i = 0; i < typesList.tagCount(); i++) {
NBTTagCompound storageNbt = typesList.getCompoundTagAt(i);
IAspectType type = IAspectType.readFromNBT(storageNbt.getCompoundTag("aspect"));
public AspectContainer read(CompoundTag nbt) {
ListTag typesList = nbt.getList("container", Tag.TAG_COMPOUND);
for(int i = 0; i < typesList.size(); i++) {
CompoundTag storageNbt = typesList.getCompound(i);
IAspectType type = IAspectType.load(storageNbt.getCompound("aspect"));
if(type == null)
continue;
Storage storage = this.getStorage(type);
storage.readFromNBT(storageNbt.getCompoundTag("storage"));
storage.load(storageNbt.getCompound("storage"));
}
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/thebetweenlands/api/aspect/AspectItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package thebetweenlands.api.aspect;

import net.minecraft.item.ItemStack;
import net.minecraft.world.item.ItemStack;
import thebetweenlands.common.herblore.aspect.AspectManager;
import thebetweenlands.common.herblore.aspect.IItemStackMatcher;

Expand Down
67 changes: 34 additions & 33 deletions src/main/java/thebetweenlands/api/aspect/DiscoveryContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import java.util.Map;
import java.util.Map.Entry;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import thebetweenlands.api.aspect.DiscoveryContainer.AspectDiscovery.EnumDiscoveryResult;
import thebetweenlands.api.item.IDiscoveryProvider;
import thebetweenlands.common.herblore.aspect.AspectManager;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static DiscoveryContainer<?> empty() {
* @param nbt
* @return
*/
public static DiscoveryContainer<?> readFromNBT(NBTTagCompound nbt) {
public static DiscoveryContainer<?> load(BlockState state, CompoundTag nbt) {
DiscoveryContainer<?> container = empty();
container.updateFromNBT(nbt, false);
return container;
Expand Down Expand Up @@ -162,25 +163,25 @@ private Aspect getUndiscoveredAspect(List<Aspect> all, List<IAspectType> discove
* Writes this discovery container to an NBT
* @param nbt
*/
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
NBTTagList discoveryList = new NBTTagList();
public CompoundTag save(CompoundTag nbt) {
ListTag discoveryList = new ListTag();
Iterator<Entry<AspectItem, List<IAspectType>>> discoveryIT = this.discoveredStaticAspects.entrySet().iterator();
while(discoveryIT.hasNext()) {
Entry<AspectItem, List<IAspectType>> e = discoveryIT.next();
if(e.getKey() == null || e.getValue() == null || e.getValue().size() == 0) {
discoveryIT.remove();
continue;
}
NBTTagCompound discoveryEntry = new NBTTagCompound();
CompoundTag discoveryEntry = new CompoundTag();
AspectManager.writeAspectItemToNbt(e.getKey(), discoveryEntry);
NBTTagList aspectListCompound = new NBTTagList();
ListTag aspectListCompound = new ListTag();
for(IAspectType type : e.getValue()) {
aspectListCompound.appendTag(type.writeToNBT(new NBTTagCompound()));
aspectListCompound.add(type.save(new CompoundTag()));
}
discoveryEntry.setTag("aspects", aspectListCompound);
discoveryList.appendTag(discoveryEntry);
discoveryEntry.put("aspects", aspectListCompound);
discoveryList.add(discoveryEntry);
}
nbt.setTag("discoveries", discoveryList);
nbt.put("discoveries", discoveryList);
return nbt;
}

Expand All @@ -189,18 +190,18 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
* @param nbt
* @return
*/
public DiscoveryContainer<T> updateFromNBT(NBTTagCompound nbt, boolean save) {
public DiscoveryContainer<T> updateFromNBT(CompoundTag nbt, boolean save) {
this.discoveredStaticAspects.clear();
NBTTagList discoveryList = nbt.getTagList("discoveries", Constants.NBT.TAG_COMPOUND);
int discoveryEntries = discoveryList.tagCount();
ListTag discoveryList = nbt.getList("discoveries", Tag.TAG_COMPOUND);
int discoveryEntries = discoveryList.size();
for (int i = 0; i < discoveryEntries; i++) {
NBTTagCompound discoveryEntry = discoveryList.getCompoundTagAt(i);
CompoundTag discoveryEntry = discoveryList.getCompound(i);
AspectItem item = AspectManager.readAspectItemFromNBT(discoveryEntry);
List<IAspectType> aspectTypeList = new ArrayList<IAspectType>();
NBTTagList aspectListCompound = discoveryEntry.getTagList("aspects", Constants.NBT.TAG_COMPOUND);
for (int c = 0; c < aspectListCompound.tagCount(); c++) {
NBTTagCompound aspectTypeCompound = aspectListCompound.getCompoundTagAt(c);
aspectTypeList.add(IAspectType.readFromNBT(aspectTypeCompound));
ListTag aspectListCompound = discoveryEntry.getList("aspects", Tag.TAG_COMPOUND);
for (int c = 0; c < aspectListCompound.size(); c++) {
CompoundTag aspectTypeCompound = aspectListCompound.getCompound(c);
aspectTypeList.add(IAspectType.load(aspectTypeCompound));
}
this.discoveredStaticAspects.put(item, aspectTypeList);
}
Expand Down Expand Up @@ -277,10 +278,10 @@ public static enum EnumDiscoveryResult {
* @param player
* @return
*/
public static boolean hasDiscoveryProvider(EntityPlayer player) {
InventoryPlayer inventory = player.inventory;
for(int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
public static boolean hasDiscoveryProvider(Player player) {
Inventory inventory = player.getInventory();
for(int i = 0; i < inventory.getContainerSize(); i++) {
ItemStack stack = inventory.getItem(i);
if(!stack.isEmpty() && stack.getItem() instanceof IDiscoveryProvider)
return true;
}
Expand All @@ -292,11 +293,11 @@ public static boolean hasDiscoveryProvider(EntityPlayer player) {
* @param player
* @return
*/
public static List<DiscoveryContainer<?>> getWritableDiscoveryContainers(EntityPlayer player) {
public static List<DiscoveryContainer<?>> getWritableDiscoveryContainers(Player player) {
List<DiscoveryContainer<?>> containerList = new ArrayList<DiscoveryContainer<?>>();
InventoryPlayer inventory = player.inventory;
for(int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
Inventory inventory = player.getInventory();
for(int i = 0; i < inventory.getContainerSize(); i++) {
ItemStack stack = inventory.getItem(i);
if(!stack.isEmpty() && stack.getItem() instanceof IDiscoveryProvider) {
@SuppressWarnings("unchecked")
IDiscoveryProvider<ItemStack> provider = (IDiscoveryProvider<ItemStack>) stack.getItem();
Expand All @@ -314,7 +315,7 @@ public static List<DiscoveryContainer<?>> getWritableDiscoveryContainers(EntityP
* @param player
* @return
*/
public static DiscoveryContainer<?> getMergedDiscoveryContainer(EntityPlayer player) {
public static DiscoveryContainer<?> getMergedDiscoveryContainer(Player player) {
List<DiscoveryContainer<?>> containerList = getWritableDiscoveryContainers(player);
DiscoveryContainer<?> merged = DiscoveryContainer.empty();
for(DiscoveryContainer<?> container : containerList) {
Expand All @@ -330,7 +331,7 @@ public static DiscoveryContainer<?> getMergedDiscoveryContainer(EntityPlayer pla
* @param item
* @param type
*/
public static void addDiscoveryToContainers(EntityPlayer player, AspectItem item, IAspectType type) {
public static void addDiscoveryToContainers(Player player, AspectItem item, IAspectType type) {
List<DiscoveryContainer<?>> discoveryContainers = getWritableDiscoveryContainers(player);
for(DiscoveryContainer<?> container : discoveryContainers)
container.addDiscovery(item, type);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/thebetweenlands/api/aspect/IAspectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import javax.annotation.Nullable;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import thebetweenlands.common.registries.AspectRegistry;

public interface IAspectType {
Expand Down Expand Up @@ -42,8 +42,8 @@ public interface IAspectType {
* @param nbt
* @return
*/
public default NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setString("type", this.getName());
public default CompoundTag save(CompoundTag nbt) {
nbt.putString("type", this.getName());
return nbt;
}

Expand All @@ -53,7 +53,7 @@ public default NBTTagCompound writeToNBT(NBTTagCompound nbt) {
* @return
*/
@Nullable
public static IAspectType readFromNBT(NBTTagCompound nbt) {
public static IAspectType load(CompoundTag nbt) {
return AspectRegistry.getAspectTypeFromName(nbt.getString("type"));
}
}
Loading

0 comments on commit 9f80c32

Please sign in to comment.