Split up apples

This commit is contained in:
Sollace 2019-01-13 22:05:40 +02:00
parent 1f433bf497
commit 337b652cc0
15 changed files with 216 additions and 107 deletions

View file

@ -5,11 +5,13 @@ import com.minelittlepony.unicopia.item.ItemCereal;
import com.minelittlepony.unicopia.item.ItemCloud;
import com.minelittlepony.unicopia.item.ItemCurse;
import com.minelittlepony.unicopia.item.ItemOfHolding;
import com.minelittlepony.unicopia.item.ItemRottenApple;
import com.minelittlepony.unicopia.item.ItemSpell;
import com.minelittlepony.unicopia.item.ItemSpellbook;
import com.minelittlepony.unicopia.item.ItemStick;
import com.minelittlepony.unicopia.item.ItemTomato;
import com.minelittlepony.unicopia.item.ItemTomatoSeeds;
import com.minelittlepony.unicopia.item.ItemZapApple;
import com.minelittlepony.unicopia.item.UItemBlock;
import com.minelittlepony.unicopia.item.UItemMultiTexture;
import com.minelittlepony.unicopia.item.UItemSlab;
@ -43,10 +45,17 @@ import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery;
import com.minelittlepony.unicopia.forgebullshit.RegistryLockSpinner;
public class UItems {
public static final ItemApple apple = new ItemApple()
.setSubTypes("apple", "green", "sweet", "rotten", "zap", "zap_cooked")
public static final ItemApple apple = new ItemApple("minecraft", "apple")
.setSubTypes("apple", "green", "sweet", "sour")
.setTypeRarities(10, 20, 10, 30);
public static final ItemApple zap_apple = new ItemZapApple(Unicopia.MODID, "zap_apple")
.setSubTypes("zap_apple", "red", "green", "sweet", "sour");
public static final ItemApple rotten_apple = new ItemRottenApple(Unicopia.MODID, "rotten_apple");
public static final ItemApple cooked_zap_apple = new ItemApple(Unicopia.MODID, "cooked_zap_apple");
public static final Item cloud_matter = new Item()
.setCreativeTab(CreativeTabs.MATERIALS)
.setTranslationKey("cloud_matter")
@ -129,11 +138,15 @@ public class UItems {
alfalfa_seeds, alfalfa_leaves,
cereal, sugar_cereal, sugar_block,
rotten_apple, zap_apple, cooked_zap_apple,
cloudsdale_tomato, tomato_seeds, tomato);
if (UClient.isClientSide()) {
registerAllVariants(apple, apple.getVariants());
registerAllVariants(zap_apple, zap_apple.getVariants());
registerAllVariants(rotten_apple, "rotten_apple");
registerAllVariants(cooked_zap_apple, "cooked_zap_apple");
registerAllVariants(cloud_spawner, "cloud_small", "cloud_medium", "cloud_large");
registerAllVariants(dew_drop, "dew_drop");
registerAllVariants(cloud_matter, "cloud_matter");
@ -169,10 +182,9 @@ public class UItems {
}
static void registerFuels() {
int zap = apple.getZapAppleMetadata();
FurnaceRecipes.instance().addSmeltingRecipe(
new ItemStack(UItems.apple, 1, zap),
new ItemStack(UItems.apple, 1, zap + 1), 0.1F);
new ItemStack(UItems.zap_apple, 1),
new ItemStack(UItems.cooked_zap_apple, 1), 0.1F);
}
static void registerRecipes(IForgeRegistry<IRecipe> registry) {

View file

@ -2,106 +2,77 @@ package com.minelittlepony.unicopia.item;
import java.util.Random;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.vector.VecHelper;
import com.minelittlepony.unicopia.UItems;
import net.minecraft.block.BlockPlanks;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class ItemApple extends ItemFood {
private int[] typeRarities = new int[0];
private String[] subTypes = new String[0];
private String[] variants = subTypes;
public int getRandomAppleMetadata(Random rand, Object variant) {
public ItemStack getRandomApple(Random rand, Object variant) {
int[] rarity = typeRarities;
int result = 0;
for (int i = 0; i < rarity.length && i < subTypes.length; i++) {
if (rand.nextInt(rarity[i]) == 0) {
result++;
}
}
if (variant == BlockPlanks.EnumType.JUNGLE) {
result = result == 0 ? 1 : result == 1 ? 0 : result;
}
if (variant == BlockPlanks.EnumType.SPRUCE) {
result = result == 0 ? 3 : result == 3 ? 0 : result;
result = oneOr(result, 0, 1);
}
if (variant == BlockPlanks.EnumType.BIRCH) {
result = result == 0 ? 2 : result == 2 ? 0 : result;
result = oneOr(result, 0, 2);
}
if (variant == BlockPlanks.EnumType.SPRUCE) {
if (result == 0) {
return new ItemStack(UItems.rotten_apple, 1);
}
}
if (variant == BlockPlanks.EnumType.DARK_OAK) {
result = result == 1 ? getZapAppleMetadata() : result == getZapAppleMetadata() ? 1 : result;
if (result == 1) {
return new ItemStack(UItems.zap_apple, 1);
}
return result;
}
public ItemApple() {
if (variant == BlockPlanks.EnumType.ACACIA) {
result = oneOr(result, 0, 4);
}
return new ItemStack(this, 1, result);
}
int oneOr(int initial, int a, int b) {
if (initial == a) {
return b;
}
if (initial == b) {
return a;
}
return initial;
}
public ItemApple(String domain, String name) {
super(4, 3, false);
setHasSubtypes(true);
setMaxDamage(0);
setTranslationKey("apple");
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
RayTraceResult mop = VecHelper.getObjectMouseOver(player, 5, 0);
if (mop != null && mop.typeOfHit == RayTraceResult.Type.ENTITY) {
ItemStack stack = player.getHeldItem(hand);
if (canFeedTo(stack, mop.entityHit)) {
return onFedTo(stack, player, mop.entityHit);
}
}
return super.onItemRightClick(world, player, hand);
}
@Override
protected void onFoodEaten(ItemStack stack, World w, EntityPlayer player) {
super.onFoodEaten(stack, w, player);
if (isZapApple(stack)) {
player.attackEntityFrom(MagicalDamageSource.create("zap"), 120);
w.addWeatherEffect(new EntityLightningBolt(w, player.posX, player.posY, player.posZ, false));
}
}
public boolean canFeedTo(ItemStack stack, Entity e) {
return isZapApple(stack) && (e instanceof EntityVillager || e instanceof EntityCreeper || e instanceof EntityPig);
}
public boolean isZapApple(ItemStack stack) {
int meta = stack.getMetadata();
return meta == getZapAppleMetadata() || meta >= subTypes.length;
}
public ActionResult<ItemStack> onFedTo(ItemStack stack, EntityPlayer player, Entity e) {
e.onStruckByLightning(new EntityLightningBolt(e.world, e.posX, e.posY, e.posZ, false));
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
setTranslationKey(name);
setRegistryName(domain, name);
}
public int getZapAppleMetadata() {
@ -109,13 +80,16 @@ public class ItemApple extends ItemFood {
}
public ItemApple setSubTypes(String... types) {
setHasSubtypes(true);
setMaxDamage(0);
subTypes = types;
variants = new String[subTypes.length * 2];
variants = new String[subTypes.length];
setTranslationKey(variants[0] = types[0]);
for (int i = 1; i < variants.length; i++) {
variants[i] = variants[0] + (i % subTypes.length != 0 ? "_" + subTypes[i % subTypes.length] : "");
variants[i] = variants[0] + "_" + subTypes[i % subTypes.length];
}
return this;
}
@ -132,36 +106,22 @@ public class ItemApple extends ItemFood {
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (isInCreativeTab(tab)) {
for (int i = 0; i < subTypes.length; i++) {
items.add(new ItemStack(this, 1, 0));
for (int i = 1; i < subTypes.length; i++) {
items.add(new ItemStack(this, 1, i));
}
}
}
@Override
public EnumRarity getRarity(ItemStack stack) {
int meta = stack.getMetadata();
if (meta == getZapAppleMetadata()) {
return EnumRarity.EPIC;
}
if (meta >= subTypes.length) {
return EnumRarity.RARE;
}
return EnumRarity.COMMON;
}
@Override
public String getTranslationKey(ItemStack stack) {
if (subTypes.length > 0) {
int meta = Math.max(0, stack.getMetadata() % subTypes.length);
return super.getTranslationKey(stack) + (meta > 0 ? "." + subTypes[meta] : "");
}
@Override
public int getItemBurnTime(ItemStack stack) {
return stack.getMetadata() == 2 ? 150 : 0;
return super.getTranslationKey(stack);
}
}

View file

@ -0,0 +1,15 @@
package com.minelittlepony.unicopia.item;
import net.minecraft.item.ItemStack;
public class ItemRottenApple extends ItemApple {
public ItemRottenApple(String domain, String name) {
super(domain, name);
}
@Override
public int getItemBurnTime(ItemStack stack) {
return 150;
}
}

View file

@ -0,0 +1,85 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class ItemZapApple extends ItemApple {
public ItemZapApple(String domain, String name) {
super(domain, name);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
RayTraceResult mop = VecHelper.getObjectMouseOver(player, 5, 0);
if (mop != null && mop.typeOfHit == RayTraceResult.Type.ENTITY) {
ItemStack stack = player.getHeldItem(hand);
if (canFeedTo(stack, mop.entityHit)) {
return onFedTo(stack, player, mop.entityHit);
}
}
return super.onItemRightClick(world, player, hand);
}
@Override
protected void onFoodEaten(ItemStack stack, World w, EntityPlayer player) {
super.onFoodEaten(stack, w, player);
player.attackEntityFrom(MagicalDamageSource.create("zap"), 120);
w.addWeatherEffect(new EntityLightningBolt(w, player.posX, player.posY, player.posZ, false));
}
public boolean canFeedTo(ItemStack stack, Entity e) {
return e instanceof EntityVillager
|| e instanceof EntityCreeper
|| e instanceof EntityPig;
}
public ActionResult<ItemStack> onFedTo(ItemStack stack, EntityPlayer player, Entity e) {
e.onStruckByLightning(new EntityLightningBolt(e.world, e.posX, e.posY, e.posZ, false));
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (isInCreativeTab(tab)) {
items.add(new ItemStack(this, 1, 0));
}
}
@Override
public EnumRarity getRarity(ItemStack stack) {
int meta = stack.getMetadata();
if (meta == 0) {
return EnumRarity.EPIC;
}
return EnumRarity.RARE;
}
}

View file

@ -30,7 +30,6 @@ import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
@ -323,7 +322,7 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
w.playEvent(2001, pos, Block.getStateId(state));
EntityItem item = new EntityItem(w);
item.setPosition(pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5);
item.setItem(new ItemStack(Items.APPLE, 1, getAppleMeta(w, log)));
item.setItem(getApple(w, log));
w.spawnEntity(item);
}
@ -334,8 +333,8 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
}
}
private int getAppleMeta(World w, IBlockState log) {
return UItems.apple.getRandomAppleMetadata(w.rand, getVariant(log));
private ItemStack getApple(World w, IBlockState log) {
return UItems.apple.getRandomApple(w.rand, getVariant(log));
}
private int measureTree(World w, IBlockState log, BlockPos pos) {

View file

@ -44,9 +44,17 @@ item.bag_of_holding.name=Bag of Holding
item.apple.green.name=Granny Smith Apple
item.apple.sweet.name=Sweet Apple Acres Apple
item.apple.rotten.name=Rotten Apple
item.apple.zap.name=Zap Apple
item.apple.zap_cooked.name=Cooked Zap Apple
item.apple.sour.name=Sour Apple
item.rotten_apple.name=Rotten Apple
item.cooked_zap_zap.name=Cooked Zap Apple
item.zap_apple.name=Zap Apple
item.zap_apple.red.name=Apple
item.zap_apple.green.name=Granny Smith Apple
item.zap_apple.sweet.name=Sweet Apple Acres Apple
item.zap_apple.sour.name=Sour Apple
item.tomato.name=Tomato
item.tomato.rotten.name=Rotten Tomato

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:items/apple_sour"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:items/apple_green"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "minecraft:items/apple"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:items/apple_sour"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:items/apple_sweet"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB