Further fattening and dispensibles rewrites

This commit is contained in:
Sollace 2019-03-20 22:37:49 +02:00
parent 05c6c7b2b4
commit 6ab9343164
20 changed files with 276 additions and 241 deletions

View file

@ -1,49 +0,0 @@
package com.minelittlepony.unicopia;
import java.util.function.Function;
import com.minelittlepony.unicopia.entity.*;
import net.minecraft.world.World;
public enum CloudSize {
SMALL(EntityRacingCloud::new),
MEDIUM(EntityConstructionCloud::new),
LARGE(EntityWildCloud::new);
private static final CloudSize[] META_LOOKUP = new CloudSize[values().length];
static {
CloudSize[] values = values();
for (CloudSize i : values) {
META_LOOKUP[i.getMetadata()] = i;
}
}
private final String name;
private final Function<World, EntityCloud> constructor;
CloudSize(Function<World, EntityCloud> constructor) {
this.constructor = constructor;
this.name = name().toLowerCase();
}
public String getName() {
return name;
}
public int getMetadata() {
return ordinal();
}
public EntityCloud createEntity(World w) {
return constructor.apply(w);
}
public static CloudSize byMetadata(int meta) {
if (meta < 0 || meta >= META_LOOKUP.length) {
meta = 0;
}
return META_LOOKUP[meta];
}
}

View file

@ -19,10 +19,12 @@ public class Fixes {
CompoundDataFixer forgeDataFixer = (CompoundDataFixer)fixer;
try {
ModFixs modfix = forgeDataFixer.init(Unicopia.MODID, 1342);
ModFixs modfix = forgeDataFixer.init(Unicopia.MODID, 1343);
modfix.registerFix(FixTypes.CHUNK, new FixCloudBlocks());
modfix.registerFix(FixTypes.ITEM_INSTANCE, new FixCloudItems());
modfix.registerFix(FixTypes.ITEM_INSTANCE, new FixItems());
} catch (Throwable ignored) {
// no way to check if our fixer is already registered.
// so just do it anyway and ignore the error.
@ -30,6 +32,49 @@ public class Fixes {
}
}
static class FixItems implements IFixableData {
private final String[] cloud_spawners = new String[] {
"unicopia:racing_cloud_spawner",
"unicopia:construction_cloud_spawner",
"unicopia:wild_cloud_spawner"
};
@Override
public int getFixVersion() {
return 1343;
}
@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
if (compound.hasKey("id", 8)) {
String id = compound.getString("id");
int damage = compound.hasKey("Damage", 3) ? compound.getInteger("Damage") : 0;
if (id == "unicopia:cloud") {
id = cloud_spawners[damage % cloud_spawners.length];
damage = 0;
}
if (id == "unicopia:tomato" && damage == 1) {
id = "unicopia:rotten_tomato";
damage = 0;
}
if (id == "unicopia:cloudsdale_tomato" && damage == 1) {
id = "unicopia:rotten_cloudsdale_tomato";
damage = 0;
}
compound.setString("id", id);
compound.setInteger("Damage", 0);
}
return compound;
}
}
static class FixCloudItems implements IFixableData {
@Override
public int getFixVersion() {

View file

@ -123,7 +123,7 @@ public class BlockTomatoPlant extends BlockCrops {
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
if (isMaxAge(state)) {
return state.getValue(TYPE) == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
return state.getValue(TYPE).getCrop();
}
return getSeed();
@ -148,18 +148,16 @@ public class BlockTomatoPlant extends BlockCrops {
if (player.getHeldItem(hand).isEmpty()) {
Type type = state.getValue(TYPE);
Item crop = type == Type.CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
int good = getAge(state);
int rotten = world.rand.nextInt(good);
good -= rotten;
if (good > 0) {
spawnAsEntity(world, pos, new ItemStack(crop, good, 0));
spawnAsEntity(world, pos, new ItemStack(type.getCrop(), good));
}
if (rotten > 0) {
spawnAsEntity(world, pos, new ItemStack(crop, rotten, 1));
spawnAsEntity(world, pos, new ItemStack(type.getWaste(), rotten));
}
world.setBlockState(pos, state.withProperty(getAgeProperty(), 0));
@ -239,5 +237,13 @@ public class BlockTomatoPlant extends BlockCrops {
public String getName() {
return this == NORMAL ? "normal" : "cloudsdale";
}
public Item getCrop() {
return this == CLOUDSDALE ? UItems.cloudsdale_tomato : UItems.tomato;
}
public Item getWaste() {
return this == CLOUDSDALE ? UItems.rotten_cloudsdale_tomato : UItems.rotten_tomato;
}
}
}

View file

@ -4,13 +4,14 @@ import com.minelittlepony.unicopia.item.ItemAlicornAmulet;
import com.minelittlepony.unicopia.item.ItemApple;
import com.minelittlepony.unicopia.item.ItemAppleMultiType;
import com.minelittlepony.unicopia.item.ItemCereal;
import com.minelittlepony.unicopia.item.ItemCloud;
import com.minelittlepony.unicopia.item.ItemCloudPlacer;
import com.minelittlepony.unicopia.item.ItemCurse;
import com.minelittlepony.unicopia.item.ItemFruitLeaves;
import com.minelittlepony.unicopia.item.ItemMagicStaff;
import com.minelittlepony.unicopia.item.ItemMoss;
import com.minelittlepony.unicopia.item.ItemOfHolding;
import com.minelittlepony.unicopia.item.ItemRottenApple;
import com.minelittlepony.unicopia.item.ItemRottenTomato;
import com.minelittlepony.unicopia.item.ItemSpell;
import com.minelittlepony.unicopia.item.ItemSpellbook;
import com.minelittlepony.unicopia.item.ItemStaff;
@ -58,6 +59,9 @@ import com.minelittlepony.unicopia.edibles.FlowerToxicityDeterminent;
import com.minelittlepony.unicopia.edibles.MultiItemEdible;
import com.minelittlepony.unicopia.edibles.Toxicity;
import com.minelittlepony.unicopia.edibles.UItemFoodDelegate;
import com.minelittlepony.unicopia.entity.EntityConstructionCloud;
import com.minelittlepony.unicopia.entity.EntityRacingCloud;
import com.minelittlepony.unicopia.entity.EntityWildCloud;
import com.minelittlepony.unicopia.extern.Baubles;
import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery;
import com.minelittlepony.unicopia.forgebullshit.ItemRegistrar;
@ -87,7 +91,9 @@ public class UItems {
.setTranslationKey("dew_drop")
.setRegistryName(Unicopia.MODID, "dew_drop");
public static final ItemCloud cloud_spawner = new ItemCloud(Unicopia.MODID, "cloud");
public static final ItemCloudPlacer racing_cloud_spawner = new ItemCloudPlacer(EntityRacingCloud::new, Unicopia.MODID, "racing_cloud_spawner");
public static final ItemCloudPlacer construction_cloud_spawner = new ItemCloudPlacer(EntityConstructionCloud::new, Unicopia.MODID, "construction_cloud_spawner");
public static final ItemCloudPlacer wild_cloud_spawner = new ItemCloudPlacer(EntityWildCloud::new, Unicopia.MODID, "wild_cloud_spawner");
public static final Item cloud_block = new UItemBlock(UBlocks.normal_cloud, INTERACT_WITH_CLOUDS);
public static final Item enchanted_cloud = new UItemBlock(UBlocks.enchanted_cloud, INTERACT_WITH_CLOUDS);
@ -169,7 +175,11 @@ public class UItems {
public static final Item sugar_cereal = new ItemCereal(Unicopia.MODID, "sugar_cereal", 20, -2).setSugarAmount(110).setAlwaysEdible();
public static final ItemTomato tomato = new ItemTomato(Unicopia.MODID, "tomato", 4, 34);
public static final ItemRottenTomato rotten_tomato = new ItemRottenTomato(Unicopia.MODID, "rotten_tomato", 4, 34);
public static final ItemTomato cloudsdale_tomato = new ItemTomato(Unicopia.MODID, "cloudsdale_tomato", 16, 4);
public static final ItemRottenTomato rotten_cloudsdale_tomato = new ItemRottenTomato(Unicopia.MODID, "rotten_cloudsdale_tomato", 4, 34);
public static final ItemTomatoSeeds tomato_seeds = new ItemTomatoSeeds(Unicopia.MODID, "tomato_seeds");
public static final Item apple_seeds = new UItemDecoration(UBlocks.apple_tree, Unicopia.MODID, "apple_seeds");
@ -244,14 +254,16 @@ public class UItems {
.replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower));
ItemRegistrar.registerAll(registry,
cloud_spawner,
racing_cloud_spawner, construction_cloud_spawner, wild_cloud_spawner,
green_apple, sweet_apple, sour_apple,
zap_apple, rotten_apple, cooked_zap_apple,
apple_seeds, apple_leaves,
dew_drop,
tomato, cloudsdale_tomato, tomato_seeds, moss,
tomato, rotten_tomato,
cloudsdale_tomato, rotten_cloudsdale_tomato,
tomato_seeds, moss,
cloud_matter, cloud_block, enchanted_cloud, packed_cloud,
cloud_stairs,

View file

@ -4,15 +4,41 @@ import com.minelittlepony.unicopia.entity.EntitySpell;
import com.minelittlepony.unicopia.spell.IDispenceable;
import com.minelittlepony.unicopia.spell.IMagicEffect;
import com.minelittlepony.unicopia.spell.SpellCastResult;
import com.minelittlepony.unicopia.spell.SpellRegistry;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface ICastable extends IMagicalItem {
public interface ICastable extends IMagicalItem, IDispensable {
@Override
default ActionResult<ItemStack> dispenseStack(IBlockSource source, ItemStack stack) {
IDispenceable effect = SpellRegistry.instance().getDispenseActionFrom(stack);
if (effect == null) {
return new ActionResult<>(EnumActionResult.FAIL, stack);
}
SpellCastResult dispenceResult = onDispenseSpell(source, stack, effect);
if (dispenceResult == SpellCastResult.DEFAULT) {
return new ActionResult<>(EnumActionResult.PASS, stack);
}
if (dispenceResult == SpellCastResult.PLACE) {
castContainedSpell(source.getWorld(), source.getBlockPos(), stack, effect);
stack.shrink(1);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
SpellCastResult onDispenseSpell(IBlockSource source, ItemStack stack, IDispenceable effect);

View file

@ -0,0 +1,40 @@
package com.minelittlepony.unicopia.item;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
public interface IDispensable {
IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem() {
@Override
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
ActionResult<ItemStack> result = ((IDispensable)stack.getItem()).dispenseStack(source, stack);
if (result.getType() != EnumActionResult.SUCCESS) {
return super.dispense(source, stack);
}
return result.getResult();
}
};
/**
* Enables dispensing behaviours for this item.
*/
default Item setDispenseable() {
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject((Item)(Object)this, dispenserBehavior);
return (Item)(Object)this;
}
/**
* Called to dispense this stack.
*/
ActionResult<ItemStack> dispenseStack(IBlockSource source, ItemStack stack);
}

View file

@ -1,10 +1,14 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.CloudSize;
import com.minelittlepony.unicopia.entity.EntityCloud;
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
import java.util.function.Function;
import com.minelittlepony.unicopia.entity.EntityCloud;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.BlockDispenser;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -16,24 +20,36 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class ItemCloud extends Item implements IMultiItem {
public class ItemCloudPlacer extends Item implements IDispensable {
private static final String[] variants = new String[] {"cloud_small", "cloud_medium", "cloud_large"};
private final Function<World, EntityCloud> cloudSupplier;
public ItemCloud(String domain, String name) {
public ItemCloudPlacer(Function<World, EntityCloud> cloudSupplier, String domain, String name) {
super();
setHasSubtypes(true);
setMaxDamage(0);
setTranslationKey(name);
setRegistryName(domain, name);
setCreativeTab(CreativeTabs.MATERIALS);
maxStackSize = 16;
this.cloudSupplier = cloudSupplier;
setDispenseable();
}
@Override
public String[] getVariants() {
return variants;
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (this == UItems.racing_cloud_spawner && isInCreativeTab(tab)) {
items.add(new ItemStack(this));
items.add(new ItemStack(UItems.construction_cloud_spawner));
items.add(new ItemStack(UItems.wild_cloud_spawner));
}
}
public void placeCloud(World world, BlockPos pos) {
EntityCloud cloud = cloudSupplier.apply(world);
cloud.moveToBlockPosAndAngles(pos, 0, 0);
world.spawnEntity(cloud);
}
@Override
@ -51,9 +67,7 @@ public class ItemCloud extends Item implements IMultiItem {
pos = player.getPosition();
}
EntityCloud cloud = CloudSize.byMetadata(stack.getItemDamage()).createEntity(world);
cloud.moveToBlockPosAndAngles(pos, 0, 0);
world.spawnEntity(cloud);
placeCloud(world, pos);
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
@ -64,16 +78,13 @@ public class ItemCloud extends Item implements IMultiItem {
}
@Override
public String getTranslationKey(ItemStack stack) {
return super.getTranslationKey(stack) + "." + CloudSize.byMetadata(stack.getItemDamage()).getName();
}
public ActionResult<ItemStack> dispenseStack(IBlockSource source, ItemStack stack) {
IPosition pos = BlockDispenser.getDispensePosition(source);
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subs) {
if (isInCreativeTab(tab)) {
for (CloudSize i : CloudSize.values()) {
subs.add(new ItemStack(this, 1, i.getMetadata()));
}
}
placeCloud(source.getWorld(), new BlockPos(pos.getX(), pos.getY(), pos.getZ()));
stack.shrink(1);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
}

View file

@ -128,15 +128,11 @@ public class ItemMagicStaff extends ItemStaff implements IAligned, ITossableItem
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 72000;
}
@Override
public boolean canBeThrown(ItemStack stack) {
return true;
}
@Override
public void toss(World world, ItemStack stack, EntityPlayer player) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);

View file

@ -0,0 +1,66 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.spell.ICaster;
import com.minelittlepony.unicopia.tossable.ITossableItem;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemRottenTomato extends ItemTomato implements ITossableItem {
public ItemRottenTomato(String domain, String name, int heal, int sat) {
super(domain, name, heal, sat);
setDispenseable();
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack itemstack = player.getHeldItem(hand);
if (canBeThrown(itemstack) && !player.canEat(false)) {
toss(world, itemstack, player);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
return super.onItemRightClick(world, player, hand);
}
protected boolean isSickening(ItemStack stack, EntityPlayer player) {
return canBeThrown(stack)
&& !PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canUseEarth();
}
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
if (isSickening(stack, player)) {
int duration = 7000;
PotionEffect effect = player.getActivePotionEffect(MobEffects.NAUSEA);
if (effect != null) {
duration += Math.max(0, effect.getDuration());
}
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, duration, 4));
}
}
@Override
public void onImpact(ICaster<?> caster, BlockPos pos, IBlockState state) {
if (caster.isLocal() && state.getMaterial() == Material.GLASS) {
caster.getWorld().destroyBlock(pos, true);
}
}
}

View file

@ -18,8 +18,6 @@ import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.block.BlockDispenser;
import net.minecraft.client.util.ITooltipFlag;
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;
@ -35,35 +33,6 @@ 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);
}
if (stack.getItem() instanceof ICastable) {
ICastable castable = (ICastable)stack.getItem();
SpellCastResult dispenceResult = castable.onDispenseSpell(source, stack, effect);
if (dispenceResult == SpellCastResult.DEFAULT) {
return super.dispenseStack(source, stack);
}
if (dispenceResult == SpellCastResult.PLACE) {
castable.castContainedSpell(source.getWorld(), source.getBlockPos(), stack, effect);
stack.shrink(1);
}
}
return stack;
}
};
protected String translationKey;

View file

@ -1,105 +1,44 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.spell.ICaster;
import com.minelittlepony.unicopia.tossable.ITossableItem;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
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.BlockPos;
import net.minecraft.world.World;
public class ItemTomato extends ItemFood implements ITossableItem, IMultiItem {
private final String name;
public class ItemTomato extends ItemFood {
public ItemTomato(String domain, String name, int heal, int sat) {
super(heal, sat, false);
this.name = name;
setTranslationKey(name);
setRegistryName(domain, name);
setDispenseable();
setHasSubtypes(true);
}
@Override
public String[] getVariants() {
return new String[] {name, "rotten_" + name};
}
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (isInCreativeTab(tab)) {
items.add(new ItemStack(this, 1, 0));
items.add(new ItemStack(this, 1, 1));
if (this == UItems.tomato && isInCreativeTab(tab)) {
items.add(new ItemStack(this));
items.add(new ItemStack(UItems.rotten_tomato));
items.add(new ItemStack(UItems.cloudsdale_tomato));
items.add(new ItemStack(UItems.rotten_cloudsdale_tomato));
}
}
@Override
public String getTranslationKey(ItemStack stack) {
return super.getTranslationKey(stack) + (canBeThrown(stack) ? ".rotten" : "");
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack itemstack = player.getHeldItem(hand);
if (canBeThrown(itemstack) && !player.canEat(false)) {
toss(world, itemstack, player);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
return super.onItemRightClick(world, player, hand);
}
public boolean canBeThrown(ItemStack stack) {
return stack.getMetadata() > 0;
}
protected boolean isSickening(ItemStack stack, EntityPlayer player) {
return canBeThrown(stack)
&& !PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canUseEarth();
}
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
PotionEffect effect = player.getActivePotionEffect(MobEffects.NAUSEA);
if (isSickening(stack, player)) {
int duration = 7000;
if (effect != null) {
duration += Math.max(0, effect.getDuration());
}
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, duration, 4));
} else if (effect != null) {
player.removePotionEffect(MobEffects.NAUSEA);
}
super.onFoodEaten(stack, worldIn, player);
}
@Override
public void onImpact(ICaster<?> caster, BlockPos pos, IBlockState state) {
if (caster.isLocal() && state.getMaterial() == Material.GLASS) {
caster.getWorld().destroyBlock(pos, true);
}
}
}

View file

@ -1,35 +0,0 @@
package com.minelittlepony.unicopia.tossable;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
class DispenserBehaviour extends BehaviorDefaultDispenseItem {
@Override
public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
ITossableItem tossable = (ITossableItem)stack.getItem();
if (tossable.canBeThrown(stack)) {
return shootStack(source, stack);
}
return super.dispenseStack(source, stack);
}
public ItemStack shootStack(IBlockSource source, ItemStack stack) {
return ((ITossableItem)stack.getItem()).toss(source.getWorld(),
BlockDispenser.getDispensePosition(source),
(EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING),
stack, getProjectileInaccuracy(), getProjectileVelocity());
}
protected float getProjectileInaccuracy() {
return 6.0F;
}
protected float getProjectileVelocity() {
return 1.1F;
}
}

View file

@ -1,27 +1,36 @@
package com.minelittlepony.unicopia.tossable;
import com.minelittlepony.unicopia.entity.EntityProjectile;
import com.minelittlepony.unicopia.item.IDispensable;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
public interface ITossableItem extends ITossable<ItemStack> {
IBehaviorDispenseItem dispenserBehavior = new DispenserBehaviour();
public interface ITossableItem extends ITossable<ItemStack>, IDispensable {
boolean canBeThrown(ItemStack stack);
default boolean canBeThrown(ItemStack stack) {
return true;
}
default Item setDispenseable() {
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject((Item)(Object)this, dispenserBehavior);
@Override
default ActionResult<ItemStack> dispenseStack(IBlockSource source, ItemStack stack) {
return (Item)(Object)this;
if (canBeThrown(stack)) {
stack = toss(source.getWorld(), BlockDispenser.getDispensePosition(source), (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING), stack);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
return new ActionResult<>(EnumActionResult.PASS, stack);
}
default void toss(World world, ItemStack itemstack, EntityPlayer player) {
@ -44,13 +53,13 @@ public interface ITossableItem extends ITossable<ItemStack> {
player.addStat(StatList.getObjectUseStats(itemstack.getItem()));
}
default ItemStack toss(World world, IPosition pos, EnumFacing facing, ItemStack stack, float velocity, float inaccuracy) {
default ItemStack toss(World world, IPosition pos, EnumFacing facing, ItemStack stack) {
EntityProjectile iprojectile = new EntityProjectile(world, pos.getX(), pos.getY(), pos.getZ());
iprojectile.setItem(stack);
iprojectile.setThrowDamage(getThrowDamage(stack));
iprojectile.shoot(facing.getXOffset(), facing.getYOffset() + 0.1F, facing.getZOffset(), velocity, inaccuracy);
iprojectile.shoot(facing.getXOffset(), facing.getYOffset() + 0.1F, facing.getZOffset(), 1.1F, 6);
world.spawnEntity(iprojectile);

View file

@ -29,9 +29,9 @@ tile.sugar_block.name=Block of Sugar
tile.enchanted_torch.name=Stone Lamp
item.cloud_matter.name=Lump of Cloud
item.cloud.small.name=Bucking Bronco
item.cloud.medium.name=Construction Cloud
item.cloud.large.name=Wild Cloud
item.racing_cloud_spawner.name=Racing Cloud
item.construction_cloud_spawner.name=Construction Cloud
item.wild_cloud_spawner.name=Wild Cloud
item.mist_door.name=Cloud Door
item.library_door.name=Dutch Library Door
@ -140,11 +140,11 @@ item.zap_apple.zap.name=Cooked Zap Apple
item.apple_seeds.name=Apple Seeds
item.tomato.name=Tomato
item.tomato.rotten.name=Rotten Tomato
item.rotten_tomato.name=Rotten Tomato
item.tomato_seeds.name=Tomato Seeds
item.cloudsdale_tomato.name=Cloudsdale Tomato
item.cloudsdale_tomato.rotten.name=Rotten Cloudsdale Tomato
item.rotten_cloudsdale_tomato.name=Rotten Cloudsdale Tomato
item.alfalfa_leaves.name=Alfalfa
item.alfalfa_seeds.name=Grain

View file

@ -13,5 +13,5 @@
{ "item": "unicopia:cloud_matter" }
]
},
"result": { "item": "unicopia:cloud", "data": 1, "count": 1 }
"result": { "item": "unicopia:construction_cloud_spawner", "count": 1 }
}

View file

@ -12,5 +12,5 @@
{ "item": "unicopia:cloud_matter" }
]
},
"result": { "item": "unicopia:cloud", "data": 0, "count": 1 }
"result": { "item": "unicopia:racing_cloud_spawner", "count": 1 }
}

View file

@ -10,5 +10,5 @@
{ "item": "unicopia:cloud_block" }
]
},
"result": { "item": "unicopia:cloud", "data": 2, "count": 1 }
"result": { "item": "unicopia:wild_cloud_spawner", "count": 1 }
}