Rewrite IBindable to provide an object instead of storing 2 strings
This commit is contained in:
parent
941173dbf4
commit
2a43e53842
47 changed files with 416 additions and 510 deletions
|
@ -30,18 +30,19 @@ import net.minecraftforge.registries.RegistryBuilder;
|
|||
@GameRegistry.ObjectHolder(BloodMagic.MODID)
|
||||
public class RegistrarBloodMagic {
|
||||
|
||||
private static final BloodOrb ORB_DEF = new BloodOrb("", 0, 0, 0);
|
||||
@GameRegistry.ObjectHolder("weak")
|
||||
public static final BloodOrb ORB_WEAK = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_WEAK = ORB_DEF;
|
||||
@GameRegistry.ObjectHolder("apprentice")
|
||||
public static final BloodOrb ORB_APPRENTICE = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_APPRENTICE = ORB_DEF;
|
||||
@GameRegistry.ObjectHolder("magician")
|
||||
public static final BloodOrb ORB_MAGICIAN = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_MAGICIAN = ORB_DEF;
|
||||
@GameRegistry.ObjectHolder("master")
|
||||
public static final BloodOrb ORB_MASTER = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_MASTER = ORB_DEF;
|
||||
@GameRegistry.ObjectHolder("archmage")
|
||||
public static final BloodOrb ORB_ARCHMAGE = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_ARCHMAGE = ORB_DEF;
|
||||
@GameRegistry.ObjectHolder("transcendent")
|
||||
public static final BloodOrb ORB_TRANSCENDENT = new BloodOrb("", 0, 0);
|
||||
public static final BloodOrb ORB_TRANSCENDENT = ORB_DEF;
|
||||
|
||||
public static final Potion BOOST = MobEffects.HASTE;
|
||||
public static final Potion WHIRLWIND = MobEffects.HASTE;
|
||||
|
@ -62,12 +63,12 @@ public class RegistrarBloodMagic {
|
|||
public static void registerBloodOrbs(RegistryEvent.Register<BloodOrb> event) {
|
||||
ResourceLocation orb = RegistrarBloodMagicItems.BLOOD_ORB.getRegistryName();
|
||||
event.getRegistry().registerAll(
|
||||
new BloodOrb("weak", 1, 5000).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"),
|
||||
new BloodOrb("apprentice", 2, 25000).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"),
|
||||
new BloodOrb("magician", 3, 150000).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"),
|
||||
new BloodOrb("master", 4, 1000000).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"),
|
||||
new BloodOrb("archmage", 5, 10000000).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"),
|
||||
new BloodOrb("transcendent", 6, 30000000).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent")
|
||||
new BloodOrb("weak", 1, 5000, 2).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"),
|
||||
new BloodOrb("apprentice", 2, 25000, 5).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"),
|
||||
new BloodOrb("magician", 3, 150000, 15).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"),
|
||||
new BloodOrb("master", 4, 1000000, 25).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"),
|
||||
new BloodOrb("archmage", 5, 10000000, 50).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"),
|
||||
new BloodOrb("transcendent", 6, 30000000, 50).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
71
src/main/java/WayofTime/bloodmagic/core/data/Binding.java
Normal file
71
src/main/java/WayofTime/bloodmagic/core/data/Binding.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package WayofTime.bloodmagic.core.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Binding implements INBTSerializable<NBTTagCompound> {
|
||||
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
public Binding(UUID uuid, String name) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private Binding() {
|
||||
// No-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag("id", NBTUtil.createUUIDTag(uuid));
|
||||
tag.setString("name", name);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound nbt) {
|
||||
this.uuid = NBTUtil.getUUIDFromTag(nbt.getCompoundTag("id"));
|
||||
this.name = nbt.getString("name");
|
||||
}
|
||||
|
||||
public UUID getOwnerId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Binding setOwnerId(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOwnerName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Binding setOwnerName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Binding fromStack(ItemStack stack) {
|
||||
if (!stack.hasTagCompound()) // Definitely hasn't been bound yet.
|
||||
return null;
|
||||
|
||||
NBTBase bindingTag = stack.getTagCompound().getTag("binding");
|
||||
if (bindingTag == null || bindingTag.getId() != 10 || bindingTag.hasNoTags()) // Make sure it's both a tag compound and that it has actual data.
|
||||
return null;
|
||||
|
||||
Binding binding = new Binding();
|
||||
binding.deserializeNBT((NBTTagCompound) bindingTag);
|
||||
return binding;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package WayofTime.bloodmagic.core.data;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.util.BMLog;
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
import WayofTime.bloodmagic.event.AddToNetworkEvent;
|
||||
|
@ -74,7 +73,7 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
|
|||
return false;
|
||||
|
||||
if (!Strings.isNullOrEmpty(playerId.toString())) {
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId.toString(), null, toSyphon);
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId, null, toSyphon);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue