mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Added gems
This commit is contained in:
parent
495e170bbe
commit
8bad2ce2de
18 changed files with 475 additions and 56 deletions
|
@ -2,13 +2,18 @@ package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.item.ItemApple;
|
import com.minelittlepony.unicopia.item.ItemApple;
|
||||||
import com.minelittlepony.unicopia.item.ItemCloud;
|
import com.minelittlepony.unicopia.item.ItemCloud;
|
||||||
|
import com.minelittlepony.unicopia.item.ItemCurse;
|
||||||
import com.minelittlepony.unicopia.item.ItemOfHolding;
|
import com.minelittlepony.unicopia.item.ItemOfHolding;
|
||||||
|
import com.minelittlepony.unicopia.item.ItemSpell;
|
||||||
import com.minelittlepony.unicopia.item.UItemBlock;
|
import com.minelittlepony.unicopia.item.UItemBlock;
|
||||||
import com.minelittlepony.unicopia.item.UItemMultiTexture;
|
import com.minelittlepony.unicopia.item.UItemMultiTexture;
|
||||||
import com.minelittlepony.unicopia.item.UItemSlab;
|
import com.minelittlepony.unicopia.item.UItemSlab;
|
||||||
|
import com.minelittlepony.unicopia.spell.SpellRegistry;
|
||||||
|
|
||||||
import come.minelittlepony.unicopia.forgebullshit.RegistryLockSpinner;
|
import come.minelittlepony.unicopia.forgebullshit.RegistryLockSpinner;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.client.renderer.color.ItemColors;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.init.Enchantments;
|
import net.minecraft.init.Enchantments;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
|
@ -65,6 +70,8 @@ public class UItems {
|
||||||
.setTranslationKey("cloud_slab")
|
.setTranslationKey("cloud_slab")
|
||||||
.setRegistryName(Unicopia.MODID, "cloud_slab");
|
.setRegistryName(Unicopia.MODID, "cloud_slab");
|
||||||
|
|
||||||
|
public static final ItemSpell spell = new ItemSpell(Unicopia.MODID, "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");
|
||||||
|
|
||||||
|
@ -77,7 +84,7 @@ public class UItems {
|
||||||
|
|
||||||
registry.registerAll(cloud_spawner, dew_drop, cloud_matter, cloud_block,
|
registry.registerAll(cloud_spawner, dew_drop, cloud_matter, cloud_block,
|
||||||
cloud_stairs, cloud_slab, mist_door, anvil,
|
cloud_stairs, cloud_slab, mist_door, anvil,
|
||||||
bag_of_holding);
|
bag_of_holding, spell, curse);
|
||||||
|
|
||||||
if (UClient.isClientSide()) {
|
if (UClient.isClientSide()) {
|
||||||
registerAllVariants(apple, apple.getVariants());
|
registerAllVariants(apple, apple.getVariants());
|
||||||
|
@ -90,6 +97,8 @@ public class UItems {
|
||||||
registerAllVariants(mist_door, "mist_door");
|
registerAllVariants(mist_door, "mist_door");
|
||||||
registerAllVariants(anvil, "anvil");
|
registerAllVariants(anvil, "anvil");
|
||||||
registerAllVariants(bag_of_holding, "bag_of_holding");
|
registerAllVariants(bag_of_holding, "bag_of_holding");
|
||||||
|
registerAllVariants(spell, "gem");
|
||||||
|
registerAllVariants(curse, "corrupted_gem");
|
||||||
}
|
}
|
||||||
|
|
||||||
registerFuels();
|
registerFuels();
|
||||||
|
@ -123,4 +132,14 @@ public class UItems {
|
||||||
cloud, cloud, cloud
|
cloud, cloud, cloud
|
||||||
), new ItemStack(cloud_block, 1, 2)).setRegistryName(Unicopia.MODID, "id_dont_care_just_use_it"));
|
), new ItemStack(cloud_block, 1, 2)).setRegistryName(Unicopia.MODID, "id_dont_care_just_use_it"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void registerColors(ItemColors registry) {
|
||||||
|
registry.registerItemColorHandler((stack, tint) -> {
|
||||||
|
if (Predicates.MAGI.test(Minecraft.getMinecraft().player)) {
|
||||||
|
return SpellRegistry.instance().getSpellTintFromStack(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xffffff;
|
||||||
|
}, spell, curse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,19 @@ package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.EnumAction;
|
import net.minecraft.item.EnumAction;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||||
import net.minecraftforge.client.event.FOVUpdateEvent;
|
import net.minecraftforge.client.event.FOVUpdateEvent;
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
import net.minecraftforge.event.RegistryEvent;
|
||||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
||||||
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||||
|
@ -65,15 +66,12 @@ public class Unicopia {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void init(FMLInitializationEvent event) {
|
public void init(FMLInitializationEvent event) {
|
||||||
channel = JumpingCastle.listen(MODID, () -> {
|
channel = JumpingCastle.subscribeTo(MODID, () -> {
|
||||||
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
|
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
|
||||||
})
|
})
|
||||||
// client ------> server
|
.listenFor(MsgRequestCapabilities.class)
|
||||||
.consume(MsgRequestCapabilities.class)
|
.listenFor(MsgPlayerCapabilities.class)
|
||||||
// client <------ server
|
.listenFor(MsgPlayerAbility.class);
|
||||||
.consume(MsgPlayerCapabilities.class)
|
|
||||||
// client ------> server
|
|
||||||
.consume(MsgPlayerAbility.class);
|
|
||||||
|
|
||||||
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
|
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
|
||||||
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
|
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
|
||||||
|
@ -90,6 +88,11 @@ public class Unicopia {
|
||||||
UItems.registerItems(event.getRegistry());
|
UItems.registerItems(event.getRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerItemColoursStatic(ColorHandlerEvent.Item event) {
|
||||||
|
UItems.registerColors(event.getItemColors());
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerBlocksStatic(RegistryEvent.Register<Block> event) {
|
public static void registerBlocksStatic(RegistryEvent.Register<Block> event) {
|
||||||
UBlocks.registerBlocks(event.getRegistry());
|
UBlocks.registerBlocks(event.getRegistry());
|
||||||
|
@ -113,6 +116,24 @@ public class Unicopia {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) {
|
||||||
|
if (event.getState().getBlock() == Blocks.STONE) {
|
||||||
|
int fortuneFactor = 1 + event.getFortuneLevel() * 15;
|
||||||
|
System.out.println(event.getFortuneLevel());
|
||||||
|
|
||||||
|
if (event.getWorld().rand.nextInt(500 / fortuneFactor) == 0) {
|
||||||
|
for (int i = 0; i < 1 + event.getFortuneLevel(); i++) {
|
||||||
|
if (event.getWorld().rand.nextInt(10) > 3) {
|
||||||
|
event.getDrops().add(new ItemStack(UItems.curse, 1));
|
||||||
|
} else {
|
||||||
|
event.getDrops().add(new ItemStack(UItems.spell, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||||
if (event.phase == Phase.END) {
|
if (event.phase == Phase.END) {
|
||||||
|
@ -169,14 +190,4 @@ public class Unicopia {
|
||||||
|
|
||||||
event.setNewfov(fov);
|
event.setNewfov(fov);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
|
||||||
FBS.attach(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void clonePlayer(PlayerEvent.Clone event) {
|
|
||||||
FBS.clone(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.spell.IDispenceable;
|
||||||
|
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
|
import com.minelittlepony.unicopia.spell.SpellCastResult;
|
||||||
|
|
||||||
|
import net.minecraft.dispenser.IBlockSource;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface ICastable extends IMagicalItem {
|
||||||
|
|
||||||
|
SpellCastResult onDispenseSpell(IBlockSource source, ItemStack stack, IDispenceable effect);
|
||||||
|
|
||||||
|
SpellCastResult onCastSpell(EntityPlayer player, World world, BlockPos pos, ItemStack stack, IMagicEffect effect, EnumFacing side, float hitX, float hitY, float hitZ);
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.spell.IDispenceable;
|
||||||
|
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
|
import com.minelittlepony.unicopia.spell.SpellCastResult;
|
||||||
|
import com.minelittlepony.util.MagicalDamageSource;
|
||||||
|
|
||||||
|
import net.minecraft.dispenser.IBlockSource;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class ItemCurse extends ItemSpell {
|
||||||
|
|
||||||
|
public ItemCurse(String domain, String name) {
|
||||||
|
super(domain, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpellCastResult onDispenseSpell(IBlockSource source, ItemStack stack, IDispenceable effect) {
|
||||||
|
|
||||||
|
BlockPos pos = source.getBlockPos();
|
||||||
|
World world = source.getWorld();
|
||||||
|
|
||||||
|
SpellCastResult result = super.onDispenseSpell(source, stack, effect);
|
||||||
|
|
||||||
|
if (result != SpellCastResult.NONE) {
|
||||||
|
if (world.rand.nextInt(200) == 0) {
|
||||||
|
float strength = world.rand.nextFloat() * 100;
|
||||||
|
|
||||||
|
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), strength, true);
|
||||||
|
|
||||||
|
return SpellCastResult.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpellCastResult onCastSpell(EntityPlayer player, World world, BlockPos pos, ItemStack stack, IMagicEffect effect, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
SpellCastResult result = super.onCastSpell(player, world, pos, stack, effect, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
|
if (result != SpellCastResult.NONE) {
|
||||||
|
player.attackEntityFrom(MagicalDamageSource.causePlayerDamage("corruption", player), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
179
src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java
Normal file
179
src/main/java/com/minelittlepony/unicopia/item/ItemSpell.java
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.Predicates;
|
||||||
|
import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
|
import com.minelittlepony.unicopia.spell.IUseAction;
|
||||||
|
import com.minelittlepony.unicopia.spell.SpellCastResult;
|
||||||
|
import com.minelittlepony.unicopia.spell.IDispenceable;
|
||||||
|
import com.minelittlepony.unicopia.spell.SpellRegistry;
|
||||||
|
import com.minelittlepony.util.vector.VecHelper;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockDispenser;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||||
|
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||||
|
import net.minecraft.dispenser.IBlockSource;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.EnumActionResult;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class ItemSpell extends Item implements ICastable {
|
||||||
|
private static final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem() {
|
||||||
|
@Override
|
||||||
|
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
|
||||||
|
|
||||||
|
IDispenceable effect = SpellRegistry.instance().getDispenseActionFrom(stack);
|
||||||
|
|
||||||
|
if (effect == null) {
|
||||||
|
return super.dispenseStack(source, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpellCastResult dispenceResult = ((ICastable)stack.getItem()).onDispenseSpell(source, stack, effect);
|
||||||
|
|
||||||
|
if (dispenceResult == SpellCastResult.DEFAULT) {
|
||||||
|
return super.dispenseStack(source, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dispenceResult == SpellCastResult.PLACE) {
|
||||||
|
|
||||||
|
// castContainedSpell(source.getWorld(), pos.getX(), pos.getY(), pos.getZ(), stack, effect);
|
||||||
|
|
||||||
|
stack.shrink(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public ItemSpell(String domain, String name) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
setHasSubtypes(true);
|
||||||
|
setMaxDamage(0);
|
||||||
|
setTranslationKey(name);
|
||||||
|
setRegistryName(domain, name);
|
||||||
|
setMaxStackSize(16);
|
||||||
|
|
||||||
|
setCreativeTab(CreativeTabs.BREWING);
|
||||||
|
|
||||||
|
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, dispenserBehavior);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasEffect(ItemStack stack) {
|
||||||
|
return SpellRegistry.stackHasEnchantment(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpellCastResult onDispenseSpell(IBlockSource source, ItemStack stack, IDispenceable effect) {
|
||||||
|
EnumFacing facing = source.getBlockState().getValue(BlockDispenser.FACING);
|
||||||
|
BlockPos pos = source.getBlockPos().offset(facing);
|
||||||
|
|
||||||
|
return effect.onDispenced(pos, facing, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpellCastResult onCastSpell(EntityPlayer player, World world, BlockPos pos, ItemStack stack, IMagicEffect effect, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
if (effect instanceof IUseAction) {
|
||||||
|
return ((IUseAction)effect).onUse(stack, player, world, pos, side, hitX, hitY, hitZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SpellCastResult.PLACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
|
||||||
|
if (hand != EnumHand.MAIN_HAND || !Predicates.MAGI.test(player)) {
|
||||||
|
return EnumActionResult.PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = player.getHeldItem(hand);
|
||||||
|
|
||||||
|
if (!SpellRegistry.stackHasEnchantment(stack)) {
|
||||||
|
return EnumActionResult.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMagicEffect effect = SpellRegistry.instance().getSpellFromItemStack(stack);
|
||||||
|
|
||||||
|
if (effect == null) {
|
||||||
|
return EnumActionResult.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpellCastResult result = ((ICastable)stack.getItem()).onCastSpell(player, world, pos, stack, effect, side, hitX, hitY, hitZ);
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
pos = pos.offset(side);
|
||||||
|
|
||||||
|
if (result == SpellCastResult.PLACE) {
|
||||||
|
// castContainedSpell(world, pos.getX(), pos.getY(), pos.getZ(), stack, effect).setOwner(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != SpellCastResult.NONE) {
|
||||||
|
if (!player.capabilities.isCreativeMode) {
|
||||||
|
stack.shrink(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EnumActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EnumActionResult.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||||
|
|
||||||
|
Entity target = VecHelper.getLookedAtEntity(player, 5);
|
||||||
|
|
||||||
|
ItemStack stack = player.getHeldItem(hand);
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SpellRegistry.stackHasEnchantment(stack)) {
|
||||||
|
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems) {
|
||||||
|
super.getSubItems(tab, subItems);
|
||||||
|
|
||||||
|
if (isInCreativeTab(tab)) {
|
||||||
|
for (String name : SpellRegistry.instance().getAllNames()) {
|
||||||
|
subItems.add(SpellRegistry.instance().enchantStack(new ItemStack(this, 1), name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTranslationKey(ItemStack stack) {
|
||||||
|
String result = super.getTranslationKey(stack);
|
||||||
|
|
||||||
|
if (SpellRegistry.stackHasEnchantment(stack)) {
|
||||||
|
result += "." + stack.getTagCompound().getString("spell");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* protected static EntitySpell castContainedSpell(World world, int x, int y, int z, ItemStack stack, IMagicEffect effect) {
|
||||||
|
EntitySpell spell = new EntitySpell(world);
|
||||||
|
spell.setEffect(effect);
|
||||||
|
spell.setLocationAndAngles(x + 0.5, y + 0.5, z + 0.5, 0, 0);
|
||||||
|
world.spawnEntity(spell);
|
||||||
|
return spell;
|
||||||
|
} */
|
||||||
|
}
|
|
@ -210,15 +210,7 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
||||||
setPlayerSpecies(Race.fromName(compound.getString("playerSpecies"), Race.HUMAN));
|
setPlayerSpecies(Race.fromName(compound.getString("playerSpecies"), Race.HUMAN));
|
||||||
powers.readFromNBT(compound.getCompoundTag("powers"));
|
powers.readFromNBT(compound.getCompoundTag("powers"));
|
||||||
gravity.readFromNBT(compound.getCompoundTag("gravity"));
|
gravity.readFromNBT(compound.getCompoundTag("gravity"));
|
||||||
|
effect = SpellRegistry.instance().createEffectFroNBT(compound);
|
||||||
effect = null;
|
|
||||||
|
|
||||||
if (compound.hasKey("effect_id") && compound.hasKey("effect")) {
|
|
||||||
SpellRegistry.instance().getSpellFromName(compound.getString("effect_id")).ifPresent(f -> {
|
|
||||||
effect = f;
|
|
||||||
effect.readFromNBT(compound.getCompoundTag("effect"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,5 +18,5 @@ public interface IDispenceable {
|
||||||
* @param source The dispenser currently dispensing
|
* @param source The dispenser currently dispensing
|
||||||
* @return an ActionResult for the type of action to perform.
|
* @return an ActionResult for the type of action to perform.
|
||||||
*/
|
*/
|
||||||
public ActionResult onDispenced(BlockPos pos, EnumFacing facing, IBlockSource source);
|
public SpellCastResult onDispenced(BlockPos pos, EnumFacing facing, IBlockSource source);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public interface IUseAction {
|
||||||
*
|
*
|
||||||
* @return ActionResult for the type of action to perform
|
* @return ActionResult for the type of action to perform
|
||||||
*/
|
*/
|
||||||
public ActionResult onUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ);
|
public SpellCastResult onUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered when the player right clicks
|
* Triggered when the player right clicks
|
||||||
|
@ -39,5 +39,5 @@ public interface IUseAction {
|
||||||
*
|
*
|
||||||
* @return ActionResult for the type of action to perform
|
* @return ActionResult for the type of action to perform
|
||||||
*/
|
*/
|
||||||
public ActionResult onUse(ItemStack stack, EntityPlayer player, World world, Entity hitEntity);
|
public SpellCastResult onUse(ItemStack stack, EntityPlayer player, World world, Entity hitEntity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.spell;
|
||||||
/**
|
/**
|
||||||
* A type of action to perform after a spell has completed its handling.
|
* A type of action to perform after a spell has completed its handling.
|
||||||
*/
|
*/
|
||||||
public enum ActionResult {
|
public enum SpellCastResult {
|
||||||
/**
|
/**
|
||||||
* No action.
|
* No action.
|
||||||
*/
|
*/
|
|
@ -2,9 +2,12 @@ package com.minelittlepony.unicopia.spell;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
public class SpellRegistry {
|
public class SpellRegistry {
|
||||||
|
|
||||||
private static final SpellRegistry instance = new SpellRegistry();
|
private static final SpellRegistry instance = new SpellRegistry();
|
||||||
|
@ -13,25 +16,116 @@ public class SpellRegistry {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<String, Callable<IMagicEffect>> factories = new HashMap<>();
|
public static boolean stackHasEnchantment(ItemStack stack) {
|
||||||
|
return stack.hasTagCompound() && stack.getTagCompound().hasKey("spell");
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<String, Entry> entries = new HashMap<>();
|
||||||
|
|
||||||
private SpellRegistry() {
|
private SpellRegistry() {
|
||||||
registerSpell("shield", SpellShield::new);
|
registerSpell("shield", 0xffff00, SpellShield::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<IMagicEffect> getSpellFromName(String name) {
|
public IMagicEffect getSpellFromName(String name) {
|
||||||
try {
|
if (entries.containsKey(name)) {
|
||||||
if (factories.containsKey(name)) {
|
return entries.get(name).create();
|
||||||
return Optional.ofNullable(factories.get(name).call());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMagicEffect createEffectFroNBT(NBTTagCompound compound) {
|
||||||
|
if (compound.hasKey("effect_id") && compound.hasKey("effect")) {
|
||||||
|
IMagicEffect effect = getSpellFromName(compound.getString("effect_id"));
|
||||||
|
|
||||||
|
if (effect != null) {
|
||||||
|
effect.readFromNBT(compound.getCompoundTag("effect"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDispenceable getDispenseActionFrom(ItemStack stack) {
|
||||||
|
String key = getKeyFromStack(stack);
|
||||||
|
|
||||||
|
if (entries.containsKey(key)) {
|
||||||
|
Entry entry = entries.get(key);
|
||||||
|
if (entry.canDispense) {
|
||||||
|
return entry.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMagicEffect getSpellFromItemStack(ItemStack stack) {
|
||||||
|
return getSpellFromName(getKeyFromStack(stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSpell(String key, int tint, Callable<IMagicEffect> factory) {
|
||||||
|
try {
|
||||||
|
entries.put(key, new Entry(factory, tint));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack enchantStack(ItemStack stack, String name) {
|
||||||
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
|
stack.getTagCompound().setString("spell", name);
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getKeyFromStack(ItemStack stack) {
|
||||||
|
if (stack.isEmpty() || !stack.hasTagCompound() || !stack.getTagCompound().hasKey("spell")) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack.getTagCompound().getString("spell");
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpellTintFromStack(ItemStack stack) {
|
||||||
|
return getSpellTint(getKeyFromStack(stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpellTint(String key) {
|
||||||
|
if (entries.containsKey(key)) {
|
||||||
|
return entries.get(key).color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAllNames() {
|
||||||
|
return entries.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Entry {
|
||||||
|
Callable<IMagicEffect> factory;
|
||||||
|
|
||||||
|
int color;
|
||||||
|
|
||||||
|
boolean canDispense;
|
||||||
|
|
||||||
|
Entry(Callable<IMagicEffect> factory, int color) throws Exception {
|
||||||
|
this.factory = factory;
|
||||||
|
this.color = color;
|
||||||
|
this.canDispense = factory.call() instanceof IDispenceable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
<T extends IMagicEffect> T create() {
|
||||||
|
try {
|
||||||
|
return (T) factory.call();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSpell(String key, Callable<IMagicEffect> factory) {
|
|
||||||
factories.put(key, factory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package come.minelittlepony.unicopia.forgebullshit;
|
package come.minelittlepony.unicopia.forgebullshit;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -8,15 +10,18 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = Unicopia.MODID)
|
||||||
public class FBS {
|
public class FBS {
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public static void init() {
|
public static void init() {
|
||||||
CapabilityManager.INSTANCE.register(ICapabilitiesProxyContainer.class,
|
CapabilityManager.INSTANCE.register(ICapabilitiesProxyContainer.class,
|
||||||
new Storage(), DefaultEntityCapabilitiesProxyContainer::new);
|
new Storage(), DefaultEntityCapabilitiesProxyContainer::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
public static void attach(AttachCapabilitiesEvent<Entity> event) {
|
public static void attach(AttachCapabilitiesEvent<Entity> event) {
|
||||||
if (event.getObject() instanceof EntityPlayer
|
if (event.getObject() instanceof EntityPlayer
|
||||||
|| event.getObject() instanceof EntityItem) {
|
|| event.getObject() instanceof EntityItem) {
|
||||||
|
@ -24,6 +29,7 @@ public class FBS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
public static void clone(PlayerEvent.Clone event) {
|
public static void clone(PlayerEvent.Clone event) {
|
||||||
final ICapabilitiesProxyContainer<EntityPlayer> original = of(event.getOriginal());
|
final ICapabilitiesProxyContainer<EntityPlayer> original = of(event.getOriginal());
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,23 @@ item.mist_door.name=Cloud Door
|
||||||
item.dew_drop.name=Dew Drop
|
item.dew_drop.name=Dew Drop
|
||||||
item.cloud_anvil.name=Anvilhead Anvil
|
item.cloud_anvil.name=Anvilhead Anvil
|
||||||
|
|
||||||
item.spell.name=Gem
|
item.gem.name=Gem
|
||||||
item.spell.shield.name=Gem of Repulsion
|
item.corrupted_gem.name=Fractured Gem
|
||||||
item.spell.fire.name=Gem of Flame
|
item.gem.shield.name=Gem of Repulsion
|
||||||
item.spell.inferno.name=Gem of Inferno
|
item.corrupted_gem.shield.name=Corrupt Gem of Repulsion
|
||||||
item.spell.ice.name=Gem of Freezing
|
item.gem.fire.name=Gem of Flame
|
||||||
item.spell.portal.name=Gem of Teleportation
|
item.corrupted_gem.fire.name=Corrupt Gem of Burning
|
||||||
item.spell.attract.name=Gem of Retention
|
item.gem.inferno.name=Gem of Inferno
|
||||||
item.spell.minion.name=Gem of Obedience
|
item.corrupted_gem.inferno.name=Corrupt Gem of Inferno
|
||||||
|
item.gem.ice.name=Gem of Freezing
|
||||||
|
item.corrupted_gem.ice.name=Corrupt Gem of Freezing
|
||||||
|
item.gem.portal.name=Gem of Transportation
|
||||||
|
item.corrupted_gem.portal.name=Corrupt Gem of Transportation
|
||||||
|
item.gem.attract.name=Gem of Retention
|
||||||
|
item.corrupted_gem.attract.name=Gem of Entrapment
|
||||||
|
item.gem.minion.name=Gem of Obedience
|
||||||
|
item.corrupted_gem.minion.name=Corrupt Gem of Obedience
|
||||||
|
|
||||||
item.spellbook.name=Spellbook
|
item.spellbook.name=Spellbook
|
||||||
item.bag_of_holding.name=Bag of Holding
|
item.bag_of_holding.name=Bag of Holding
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:items/corrupted_gem",
|
||||||
|
"layer1": "unicopia:items/corrupted_gem_overlay"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
src/main/resources/assets/unicopia/models/item/gem.json
Normal file
19
src/main/resources/assets/unicopia/models/item/gem.json
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:items/gem",
|
||||||
|
"layer1": "unicopia:items/gem_overlay"
|
||||||
|
},
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ -90, 0, 0 ],
|
||||||
|
"translation": [ 0, 1, -3 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson": {
|
||||||
|
"rotation": [ 0, -135, 25 ],
|
||||||
|
"translation": [ 0, 4, 2 ],
|
||||||
|
"scale": [ 1.7, 1.7, 1.7 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 543 B |
Binary file not shown.
After Width: | Height: | Size: 543 B |
BIN
src/main/resources/assets/unicopia/textures/items/gem.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/items/gem.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 603 B |
Binary file not shown.
After Width: | Height: | Size: 603 B |
Loading…
Reference in a new issue