Added baubles support

This commit is contained in:
Sollace 2019-02-18 19:48:06 +02:00
parent 900f5e6de0
commit 7d4c6f512c
12 changed files with 214 additions and 16 deletions

View file

@ -0,0 +1,14 @@
package baubles.api;
import org.apache.commons.lang3.NotImplementedException;
/*
* stub
*/
public enum BaubleType {
AMULET, RING, BELT, TRINKET, HEAD, BODY, CHARM;
public int[] getValidSlots() {
throw new NotImplementedException("getValidSlots");
}
}

View file

@ -0,0 +1,20 @@
package baubles.api;
import org.apache.commons.lang3.NotImplementedException;
import baubles.api.cap.IBaublesItemHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
/*
* stub
*/
public class BaublesApi {
public static IBaublesItemHandler getBaublesHandler(EntityPlayer player) {
throw new NotImplementedException("getBaublesHandler");
}
public static int isBaubleEquipped(EntityPlayer player, Item bauble) {
throw new NotImplementedException("isBaubleEquipped");
}
}

View file

@ -0,0 +1,60 @@
package baubles.api;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
/**
*
* This interface should be extended by items that can be worn in bauble slots
*
* @author Azanor
*/
public interface IBauble {
/**
* This method return the type of bauble this is.
* Type is used to determine the slots it can go into.
*/
public BaubleType getBaubleType(ItemStack itemstack);
/**
* This method is called once per tick if the bauble is being worn by a player
*/
public default void onWornTick(ItemStack itemstack, EntityLivingBase player) {
}
/**
* This method is called when the bauble is equipped by a player
*/
public default void onEquipped(ItemStack itemstack, EntityLivingBase player) {
}
/**
* This method is called when the bauble is unequipped by a player
*/
public default void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
}
/**
* can this bauble be placed in a bauble slot
*/
public default boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
/**
* Can this bauble be removed from a bauble slot
*/
public default boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
/**
* Will bauble automatically sync to client if a change is detected in its NBT or damage values?
* Default is off, so override and set to true if you want to auto sync.
* This sync is not instant, but occurs every 10 ticks (.5 seconds).
*/
public default boolean willAutoSync(ItemStack itemstack, EntityLivingBase player) {
return false;
}
}

View file

@ -0,0 +1,12 @@
package baubles.api.cap;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
/*
* stub
*/
public interface IBaublesItemHandler extends IItemHandlerModifiable {
boolean isItemValidForSlot(int slot, ItemStack stack, EntityLivingBase player);
}

View file

@ -43,7 +43,7 @@ import com.minelittlepony.unicopia.world.UWorld;
modid = Unicopia.MODID, modid = Unicopia.MODID,
name = Unicopia.NAME, name = Unicopia.NAME,
version = Unicopia.VERSION, version = Unicopia.VERSION,
dependencies = "required-after:jumpingcastle" dependencies = "required-after:jumpingcastle;after:baubles"
) )
public class Unicopia implements IGuiHandler { public class Unicopia implements IGuiHandler {
public static final String MODID = "unicopia"; public static final String MODID = "unicopia";

View file

@ -8,6 +8,7 @@ import javax.annotation.Nullable;
import com.minelittlepony.jumpingcastle.api.Target; import com.minelittlepony.jumpingcastle.api.Target;
import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer; import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer;
import com.minelittlepony.unicopia.extern.MineLP;
import com.minelittlepony.unicopia.init.UEntities; import com.minelittlepony.unicopia.init.UEntities;
import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.init.UParticles;
import com.minelittlepony.unicopia.input.Keyboard; import com.minelittlepony.unicopia.input.Keyboard;

View file

@ -0,0 +1,49 @@
package com.minelittlepony.unicopia.extern;
import com.minelittlepony.unicopia.item.ItemAlicornAmulet;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import baubles.api.IBauble;
import baubles.api.cap.IBaublesItemHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
public class BaubleAlicornAmulet extends ItemAlicornAmulet implements IBauble {
public BaubleAlicornAmulet(String domain, String name) {
super(domain, name);
}
@Override
public BaubleType getBaubleType(ItemStack itemstack) {
return BaubleType.AMULET;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack itemstack = player.getHeldItem(hand);
IBaublesItemHandler iplayer = BaublesApi.getBaublesHandler(player);
for (int slot : getBaubleType(itemstack).getValidSlots()) {
if (iplayer.getStackInSlot(slot).isEmpty()) {
iplayer.setStackInSlot(slot, itemstack.copy());
itemstack.setCount(0);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
}
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
@Override
public EntityEquipmentSlot getEquipmentSlot() {
return EntityEquipmentSlot.MAINHAND;
}
}

View file

@ -0,0 +1,40 @@
package com.minelittlepony.unicopia.extern;
import java.util.function.Supplier;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
public class Baubles {
private static boolean checkComplete;
private static boolean modIsActive;
static boolean isModActive() {
if (!checkComplete) {
checkComplete = true;
try {
modIsActive = BaubleType.AMULET.getValidSlots().length > 0;
} catch (Exception e) {
modIsActive = false;
}
}
return modIsActive;
}
public static <T> T ifActiveElseGet(Supplier<T> yes, Supplier<T> no) {
return (isModActive() ? yes : no).get();
}
public static int isBaubleEquipped(EntityPlayer player, Item bauble) {
if (isModActive()) {
return BaublesApi.isBaubleEquipped(player, bauble);
}
return -1;
}
}

View file

@ -1,8 +1,9 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia.extern;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.pony.data.IPony; import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.pony.data.PonyRace; import com.minelittlepony.pony.data.PonyRace;
import com.minelittlepony.unicopia.Race;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;

View file

@ -53,6 +53,8 @@ import com.minelittlepony.unicopia.edibles.FlowerToxicityDeterminent;
import com.minelittlepony.unicopia.edibles.ItemEdible; import com.minelittlepony.unicopia.edibles.ItemEdible;
import com.minelittlepony.unicopia.edibles.Toxicity; import com.minelittlepony.unicopia.edibles.Toxicity;
import com.minelittlepony.unicopia.edibles.UItemFoodDelegate; import com.minelittlepony.unicopia.edibles.UItemFoodDelegate;
import com.minelittlepony.unicopia.extern.BaubleAlicornAmulet;
import com.minelittlepony.unicopia.extern.Baubles;
import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery; import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery;
import com.minelittlepony.unicopia.forgebullshit.ItemModels; import com.minelittlepony.unicopia.forgebullshit.ItemModels;
import com.minelittlepony.unicopia.forgebullshit.OreReplacer; import com.minelittlepony.unicopia.forgebullshit.OreReplacer;
@ -110,7 +112,9 @@ public class UItems {
public static final ItemSpell curse = new ItemCurse(Unicopia.MODID, "corrupted_gem"); public static final ItemSpell curse = new ItemCurse(Unicopia.MODID, "corrupted_gem");
public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding"); public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding");
public static final ItemAlicornAmulet alicorn_amulet = new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet"); public static final ItemAlicornAmulet alicorn_amulet = Baubles.ifActiveElseGet(
() -> new BaubleAlicornAmulet(Unicopia.MODID, "alicorn_amulet"),
() -> new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet"));
public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook"); public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook");
public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2); public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2);

View file

@ -28,6 +28,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
@ -99,13 +100,17 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable {
if (!player.world.isRemote && !entity.isDead) { if (!player.world.isRemote && !entity.isDead) {
if (player.getPositionVector().distanceTo(entity.getPositionVector()) < 3) { if (player.getPositionVector().distanceTo(entity.getPositionVector()) < 3) {
if (entity.world.rand.nextInt(150) == 0) { if (entity.world.rand.nextInt(150) == 0) {
player.setItemStackToSlot(getEquipmentSlot(), entity.getItem());
ActionResult<ItemStack> result = onItemRightClick(player.world, player, EnumHand.MAIN_HAND);
if (result.getType() == EnumActionResult.SUCCESS) {
entity.setPickupDelay(1000); entity.setPickupDelay(1000);
entity.setDead(); entity.setDead();
} }
} }
} }
} }
}
@Override @Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
@ -213,15 +218,6 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable {
} }
} }
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ActionResult<ItemStack> result = super.onItemRightClick(world, player, hand);
return result;
}
@Override @Override
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) { public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
Multimap<String, AttributeModifier> multimap = HashMultimap.create();; Multimap<String, AttributeModifier> multimap = HashMultimap.create();;

View file

@ -4,6 +4,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.extern.Baubles;
import com.minelittlepony.unicopia.item.IDependable; import com.minelittlepony.unicopia.item.IDependable;
import com.minelittlepony.unicopia.item.IMagicalItem; import com.minelittlepony.unicopia.item.IMagicalItem;
import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable; import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable;
@ -75,7 +76,7 @@ public class PlayerInventory implements IInventory, IUpdatable, InbtSerialisable
} }
} }
return false; return item instanceof Item && Baubles.isBaubleEquipped(player.getOwner(), (Item)item) != -1;
} }
@Override @Override