base mod created
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
public enum EnumAction
|
||||
{
|
||||
NONE,
|
||||
EAT,
|
||||
DRINK,
|
||||
BLOCK,
|
||||
BOW;
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public enum EnumDyeColor implements IStringSerializable
|
||||
{
|
||||
WHITE(0, 15, "white", "white", 16383998, TextFormatting.WHITE),
|
||||
ORANGE(1, 14, "orange", "orange", 16351261, TextFormatting.GOLD),
|
||||
MAGENTA(2, 13, "magenta", "magenta", 13061821, TextFormatting.AQUA),
|
||||
LIGHT_BLUE(3, 12, "light_blue", "lightBlue", 3847130, TextFormatting.BLUE),
|
||||
YELLOW(4, 11, "yellow", "yellow", 16701501, TextFormatting.YELLOW),
|
||||
LIME(5, 10, "lime", "lime", 8439583, TextFormatting.GREEN),
|
||||
PINK(6, 9, "pink", "pink", 15961002, TextFormatting.LIGHT_PURPLE),
|
||||
GRAY(7, 8, "gray", "gray", 4673362, TextFormatting.DARK_GRAY),
|
||||
SILVER(8, 7, "silver", "silver", 10329495, TextFormatting.GRAY),
|
||||
CYAN(9, 6, "cyan", "cyan", 1481884, TextFormatting.DARK_AQUA),
|
||||
PURPLE(10, 5, "purple", "purple", 8991416, TextFormatting.DARK_PURPLE),
|
||||
BLUE(11, 4, "blue", "blue", 3949738, TextFormatting.DARK_BLUE),
|
||||
BROWN(12, 3, "brown", "brown", 8606770, TextFormatting.GOLD),
|
||||
GREEN(13, 2, "green", "green", 6192150, TextFormatting.DARK_GREEN),
|
||||
RED(14, 1, "red", "red", 11546150, TextFormatting.DARK_RED),
|
||||
BLACK(15, 0, "black", "black", 1908001, TextFormatting.BLACK);
|
||||
|
||||
private static final EnumDyeColor[] META_LOOKUP = new EnumDyeColor[values().length];
|
||||
private static final EnumDyeColor[] DYE_DMG_LOOKUP = new EnumDyeColor[values().length];
|
||||
private final int meta;
|
||||
private final int dyeDamage;
|
||||
private final String name;
|
||||
private final String unlocalizedName;
|
||||
/** An int containing the corresponding RGB color for this dye color. */
|
||||
private final int colorValue;
|
||||
/**
|
||||
* An array containing 3 floats ranging from 0.0 to 1.0: the red, green, and blue components of the corresponding
|
||||
* color.
|
||||
*/
|
||||
private final float[] colorComponentValues;
|
||||
private final TextFormatting chatColor;
|
||||
|
||||
private EnumDyeColor(int metaIn, int dyeDamageIn, String nameIn, String unlocalizedNameIn, int colorValueIn, TextFormatting chatColorIn)
|
||||
{
|
||||
this.meta = metaIn;
|
||||
this.dyeDamage = dyeDamageIn;
|
||||
this.name = nameIn;
|
||||
this.unlocalizedName = unlocalizedNameIn;
|
||||
this.colorValue = colorValueIn;
|
||||
this.chatColor = chatColorIn;
|
||||
int i = (colorValueIn & 16711680) >> 16;
|
||||
int j = (colorValueIn & 65280) >> 8;
|
||||
int k = (colorValueIn & 255) >> 0;
|
||||
this.colorComponentValues = new float[] {(float)i / 255.0F, (float)j / 255.0F, (float)k / 255.0F};
|
||||
}
|
||||
|
||||
public int getMetadata()
|
||||
{
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
public int getDyeDamage()
|
||||
{
|
||||
return this.dyeDamage;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDyeColorName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return this.unlocalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RGB color corresponding to this dye color.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getColorValue()
|
||||
{
|
||||
return this.colorValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array containing 3 floats ranging from 0.0 to 1.0: the red, green, and blue components of the
|
||||
* corresponding color.
|
||||
*/
|
||||
public float[] getColorComponentValues()
|
||||
{
|
||||
return this.colorComponentValues;
|
||||
}
|
||||
|
||||
public static EnumDyeColor byDyeDamage(int damage)
|
||||
{
|
||||
if (damage < 0 || damage >= DYE_DMG_LOOKUP.length)
|
||||
{
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
return DYE_DMG_LOOKUP[damage];
|
||||
}
|
||||
|
||||
public static EnumDyeColor byMetadata(int meta)
|
||||
{
|
||||
if (meta < 0 || meta >= META_LOOKUP.length)
|
||||
{
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
return META_LOOKUP[meta];
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.unlocalizedName;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for (EnumDyeColor enumdyecolor : values())
|
||||
{
|
||||
META_LOOKUP[enumdyecolor.getMetadata()] = enumdyecolor;
|
||||
DYE_DMG_LOOKUP[enumdyecolor.getDyeDamage()] = enumdyecolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
public enum EnumRarity
|
||||
{
|
||||
COMMON(TextFormatting.WHITE, "Common"),
|
||||
UNCOMMON(TextFormatting.YELLOW, "Uncommon"),
|
||||
RARE(TextFormatting.AQUA, "Rare"),
|
||||
EPIC(TextFormatting.LIGHT_PURPLE, "Epic");
|
||||
|
||||
/**
|
||||
* A decimal representation of the hex color codes of a the color assigned to this rarity type. (13 becomes d as in
|
||||
* \247d which is light purple)
|
||||
*/
|
||||
public final TextFormatting rarityColor;
|
||||
/** Rarity name. */
|
||||
public final String rarityName;
|
||||
|
||||
private EnumRarity(TextFormatting color, String name)
|
||||
{
|
||||
this.rarityColor = color;
|
||||
this.rarityName = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IItemPropertyGetter
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn);
|
||||
}
|
||||
2004
build/tmp/recompileMc/sources/net/minecraft/item/Item.java
Normal file
2004
build/tmp/recompileMc/sources/net/minecraft/item/Item.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemAir extends Item
|
||||
{
|
||||
private final Block block;
|
||||
|
||||
public ItemAir(Block blockIn)
|
||||
{
|
||||
this.block = blockIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return this.block.getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item.
|
||||
*/
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return this.block.getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
this.block.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemAnvilBlock extends ItemMultiTexture
|
||||
{
|
||||
public ItemAnvilBlock(Block block)
|
||||
{
|
||||
super(block, block, new String[] {"intact", "slightlyDamaged", "veryDamaged"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage << 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemAppleGold extends ItemFood
|
||||
{
|
||||
public ItemAppleGold(int amount, float saturation, boolean isWolfFood)
|
||||
{
|
||||
super(amount, saturation, isWolfFood);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return super.hasEffect(stack) || stack.getMetadata() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an item rarity from EnumRarity
|
||||
*/
|
||||
public EnumRarity getRarity(ItemStack stack)
|
||||
{
|
||||
return stack.getMetadata() == 0 ? EnumRarity.RARE : EnumRarity.EPIC;
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
if (stack.getMetadata() > 0)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 400, 1));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 6000, 0));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, 6000, 0));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 2400, 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 100, 1));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 2400, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
items.add(new ItemStack(this));
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
404
build/tmp/recompileMc/sources/net/minecraft/item/ItemArmor.java
Normal file
404
build/tmp/recompileMc/sources/net/minecraft/item/ItemArmor.java
Normal file
@@ -0,0 +1,404 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
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.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EntitySelectors;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemArmor extends Item
|
||||
{
|
||||
/** Holds the 'base' maxDamage that each armorType have. */
|
||||
private static final int[] MAX_DAMAGE_ARRAY = new int[] {13, 15, 16, 11};
|
||||
private static final UUID[] ARMOR_MODIFIERS = new UUID[] {UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")};
|
||||
public static final String[] EMPTY_SLOT_NAMES = new String[] {"minecraft:items/empty_armor_slot_boots", "minecraft:items/empty_armor_slot_leggings", "minecraft:items/empty_armor_slot_chestplate", "minecraft:items/empty_armor_slot_helmet"};
|
||||
public static final IBehaviorDispenseItem DISPENSER_BEHAVIOR = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
/**
|
||||
* Dispense the specified stack, play the dispense sound and spawn particles.
|
||||
*/
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
ItemStack itemstack = ItemArmor.dispenseArmor(source, stack);
|
||||
return itemstack.isEmpty() ? super.dispenseStack(source, stack) : itemstack;
|
||||
}
|
||||
};
|
||||
/** Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots */
|
||||
public final EntityEquipmentSlot armorType;
|
||||
/** Holds the amount of damage that the armor reduces at full durability. */
|
||||
public final int damageReduceAmount;
|
||||
public final float toughness;
|
||||
/**
|
||||
* Used on RenderPlayer to select the correspondent armor to be rendered on the player: 0 is cloth, 1 is chain, 2 is
|
||||
* iron, 3 is diamond and 4 is gold.
|
||||
*/
|
||||
public final int renderIndex;
|
||||
/** The EnumArmorMaterial used for this ItemArmor */
|
||||
private final ItemArmor.ArmorMaterial material;
|
||||
|
||||
public static ItemStack dispenseArmor(IBlockSource blockSource, ItemStack stack)
|
||||
{
|
||||
BlockPos blockpos = blockSource.getBlockPos().offset((EnumFacing)blockSource.getBlockState().getValue(BlockDispenser.FACING));
|
||||
List<EntityLivingBase> list = blockSource.getWorld().<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(blockpos), Predicates.and(EntitySelectors.NOT_SPECTATING, new EntitySelectors.ArmoredMob(stack)));
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityLivingBase entitylivingbase = list.get(0);
|
||||
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(stack);
|
||||
ItemStack itemstack = stack.splitStack(1);
|
||||
entitylivingbase.setItemStackToSlot(entityequipmentslot, itemstack);
|
||||
|
||||
if (entitylivingbase instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving)entitylivingbase).setDropChance(entityequipmentslot, 2.0F);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemArmor(ItemArmor.ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn)
|
||||
{
|
||||
this.material = materialIn;
|
||||
this.armorType = equipmentSlotIn;
|
||||
this.renderIndex = renderIndexIn;
|
||||
this.damageReduceAmount = materialIn.getDamageReductionAmount(equipmentSlotIn);
|
||||
this.setMaxDamage(materialIn.getDurability(equipmentSlotIn));
|
||||
this.toughness = materialIn.getToughness();
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.COMBAT);
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, DISPENSER_BEHAVIOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the equipment slot of this armor piece (formerly known as armor type)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EntityEquipmentSlot getEquipmentSlot()
|
||||
{
|
||||
return this.armorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.material.getEnchantability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the armor material for this armor item.
|
||||
*/
|
||||
public ItemArmor.ArmorMaterial getArmorMaterial()
|
||||
{
|
||||
return this.material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified armor ItemStack has a color.
|
||||
*/
|
||||
public boolean hasColor(ItemStack stack)
|
||||
{
|
||||
if (this.material != ItemArmor.ArmorMaterial.LEATHER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
return nbttagcompound != null && nbttagcompound.hasKey("display", 10) ? nbttagcompound.getCompoundTag("display").hasKey("color", 3) : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color for the specified armor ItemStack.
|
||||
*/
|
||||
public int getColor(ItemStack stack)
|
||||
{
|
||||
if (this.material != ItemArmor.ArmorMaterial.LEATHER)
|
||||
{
|
||||
return 16777215;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
|
||||
if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3))
|
||||
{
|
||||
return nbttagcompound1.getInteger("color");
|
||||
}
|
||||
}
|
||||
|
||||
return 10511680;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the color from the specified armor ItemStack.
|
||||
*/
|
||||
public void removeColor(ItemStack stack)
|
||||
{
|
||||
if (this.material == ItemArmor.ArmorMaterial.LEATHER)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
|
||||
if (nbttagcompound1.hasKey("color"))
|
||||
{
|
||||
nbttagcompound1.removeTag("color");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the specified armor ItemStack
|
||||
*/
|
||||
public void setColor(ItemStack stack, int color)
|
||||
{
|
||||
if (this.material != ItemArmor.ArmorMaterial.LEATHER)
|
||||
{
|
||||
throw new UnsupportedOperationException("Can't dye non-leather!");
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound == null)
|
||||
{
|
||||
nbttagcompound = new NBTTagCompound();
|
||||
stack.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
|
||||
if (!nbttagcompound.hasKey("display", 10))
|
||||
{
|
||||
nbttagcompound.setTag("display", nbttagcompound1);
|
||||
}
|
||||
|
||||
nbttagcompound1.setInteger("color", color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*
|
||||
* @param toRepair the {@code ItemStack} being repaired
|
||||
* @param repair the {@code ItemStack} being used to perform the repair
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
ItemStack mat = this.material.getRepairItemStack();
|
||||
if (!mat.isEmpty() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat,repair,false)) return true;
|
||||
return super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
|
||||
ItemStack itemstack1 = playerIn.getItemStackFromSlot(entityequipmentslot);
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
playerIn.setItemStackToSlot(entityequipmentslot, itemstack.copy());
|
||||
itemstack.setCount(0);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
|
||||
*/
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
||||
{
|
||||
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
||||
|
||||
if (equipmentSlot == this.armorType)
|
||||
{
|
||||
multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor modifier", (double)this.damageReduceAmount, 0));
|
||||
multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor toughness", (double)this.toughness, 0));
|
||||
}
|
||||
|
||||
return multimap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this armor will be rendered with the secondary 'overlay' texture.
|
||||
* If this is true, the first texture will be rendered using a tint of the color
|
||||
* specified by getColor(ItemStack)
|
||||
*
|
||||
* @param stack The stack
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean hasOverlay(ItemStack stack)
|
||||
{
|
||||
return this.material == ItemArmor.ArmorMaterial.LEATHER || getColor(stack) != 0x00FFFFFF;
|
||||
}
|
||||
|
||||
public static enum ArmorMaterial
|
||||
{
|
||||
LEATHER("leather", 5, new int[]{1, 2, 3, 1}, 15, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0.0F),
|
||||
CHAIN("chainmail", 15, new int[]{1, 4, 5, 2}, 12, SoundEvents.ITEM_ARMOR_EQUIP_CHAIN, 0.0F),
|
||||
IRON("iron", 15, new int[]{2, 5, 6, 2}, 9, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0.0F),
|
||||
GOLD("gold", 7, new int[]{1, 3, 5, 2}, 25, SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 0.0F),
|
||||
DIAMOND("diamond", 33, new int[]{3, 6, 8, 3}, 10, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 2.0F);
|
||||
|
||||
private final String name;
|
||||
/**
|
||||
* Holds the maximum damage factor (each piece multiply this by it's own value) of the material, this is the
|
||||
* item damage (how much can absorb before breaks)
|
||||
*/
|
||||
private final int maxDamageFactor;
|
||||
/**
|
||||
* Holds the damage reduction (each 1 points is half a shield on gui) of each piece of armor (helmet, plate,
|
||||
* legs and boots)
|
||||
*/
|
||||
private final int[] damageReductionAmountArray;
|
||||
/** Return the enchantability factor of the material */
|
||||
private final int enchantability;
|
||||
private final SoundEvent soundEvent;
|
||||
private final float toughness;
|
||||
//Added by forge for custom Armor materials.
|
||||
public ItemStack repairMaterial = ItemStack.EMPTY;
|
||||
|
||||
private ArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountArrayIn, int enchantabilityIn, SoundEvent soundEventIn, float toughnessIn)
|
||||
{
|
||||
this.name = nameIn;
|
||||
this.maxDamageFactor = maxDamageFactorIn;
|
||||
this.damageReductionAmountArray = damageReductionAmountArrayIn;
|
||||
this.enchantability = enchantabilityIn;
|
||||
this.soundEvent = soundEventIn;
|
||||
this.toughness = toughnessIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the durability for a armor slot of for this type.
|
||||
*/
|
||||
public int getDurability(EntityEquipmentSlot armorType)
|
||||
{
|
||||
return ItemArmor.MAX_DAMAGE_ARRAY[armorType.getIndex()] * this.maxDamageFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the damage reduction (each 1 point is a half a shield on gui) of the piece index passed (0 = helmet, 1
|
||||
* = plate, 2 = legs and 3 = boots)
|
||||
*/
|
||||
public int getDamageReductionAmount(EntityEquipmentSlot armorType)
|
||||
{
|
||||
return this.damageReductionAmountArray[armorType.getIndex()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the material.
|
||||
*/
|
||||
public int getEnchantability()
|
||||
{
|
||||
return this.enchantability;
|
||||
}
|
||||
|
||||
public SoundEvent getSoundEvent()
|
||||
{
|
||||
return this.soundEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a main crafting component of this Armor Material (example is Items.iron_ingot)
|
||||
*/
|
||||
@Deprecated // Use getRepairItemStack below
|
||||
public Item getRepairItem()
|
||||
{
|
||||
if (this == LEATHER)
|
||||
{
|
||||
return Items.LEATHER;
|
||||
}
|
||||
else if (this == CHAIN)
|
||||
{
|
||||
return Items.IRON_INGOT;
|
||||
}
|
||||
else if (this == GOLD)
|
||||
{
|
||||
return Items.GOLD_INGOT;
|
||||
}
|
||||
else if (this == IRON)
|
||||
{
|
||||
return Items.IRON_INGOT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this == DIAMOND ? Items.DIAMOND : null;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public float getToughness()
|
||||
{
|
||||
return this.toughness;
|
||||
}
|
||||
|
||||
public ArmorMaterial setRepairItem(ItemStack stack)
|
||||
{
|
||||
if (!this.repairMaterial.isEmpty()) throw new RuntimeException("Repair material has already been set");
|
||||
if (this == LEATHER || this == CHAIN || this == GOLD || this == IRON || this == DIAMOND) throw new RuntimeException("Can not change vanilla armor repair materials");
|
||||
this.repairMaterial = stack;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getRepairItemStack()
|
||||
{
|
||||
if (!repairMaterial.isEmpty()) return repairMaterial;
|
||||
Item ret = this.getRepairItem();
|
||||
if (ret != null) repairMaterial = new ItemStack(ret,1,net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE);
|
||||
return repairMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityArmorStand;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Rotations;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemArmorStand extends Item
|
||||
{
|
||||
public ItemArmorStand()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (facing == EnumFacing.DOWN)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
|
||||
BlockPos blockpos = flag ? pos : pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(blockpos, facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos blockpos1 = blockpos.up();
|
||||
boolean flag1 = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
|
||||
flag1 = flag1 | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0 = (double)blockpos.getX();
|
||||
double d1 = (double)blockpos.getY();
|
||||
double d2 = (double)blockpos.getZ();
|
||||
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
worldIn.setBlockToAir(blockpos);
|
||||
worldIn.setBlockToAir(blockpos1);
|
||||
EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
|
||||
float f = (float)MathHelper.floor((MathHelper.wrapDegrees(player.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
|
||||
entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
|
||||
this.applyRandomRotations(entityarmorstand, worldIn.rand);
|
||||
ItemMonsterPlacer.applyItemEntityDataToEntity(worldIn, player, itemstack, entityarmorstand);
|
||||
worldIn.spawnEntity(entityarmorstand);
|
||||
worldIn.playSound((EntityPlayer)null, entityarmorstand.posX, entityarmorstand.posY, entityarmorstand.posZ, SoundEvents.ENTITY_ARMORSTAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyRandomRotations(EntityArmorStand armorStand, Random rand)
|
||||
{
|
||||
Rotations rotations = armorStand.getHeadRotation();
|
||||
float f = rand.nextFloat() * 5.0F;
|
||||
float f1 = rand.nextFloat() * 20.0F - 10.0F;
|
||||
Rotations rotations1 = new Rotations(rotations.getX() + f, rotations.getY() + f1, rotations.getZ());
|
||||
armorStand.setHeadRotation(rotations1);
|
||||
rotations = armorStand.getBodyRotation();
|
||||
f = rand.nextFloat() * 10.0F - 5.0F;
|
||||
rotations1 = new Rotations(rotations.getX(), rotations.getY() + f, rotations.getZ());
|
||||
armorStand.setBodyRotation(rotations1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemArrow extends Item
|
||||
{
|
||||
public ItemArrow()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.COMBAT);
|
||||
}
|
||||
|
||||
public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter)
|
||||
{
|
||||
EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, shooter);
|
||||
entitytippedarrow.setPotionEffect(stack);
|
||||
return entitytippedarrow;
|
||||
}
|
||||
|
||||
public boolean isInfinite(ItemStack stack, ItemStack bow, net.minecraft.entity.player.EntityPlayer player)
|
||||
{
|
||||
int enchant = net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, bow);
|
||||
return enchant <= 0 ? false : this.getClass() == ItemArrow.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class ItemAxe extends ItemTool
|
||||
{
|
||||
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON, Blocks.WOODEN_PRESSURE_PLATE);
|
||||
private static final float[] ATTACK_DAMAGES = new float[] {6.0F, 8.0F, 8.0F, 8.0F, 6.0F};
|
||||
private static final float[] ATTACK_SPEEDS = new float[] { -3.2F, -3.2F, -3.1F, -3.0F, -3.0F};
|
||||
|
||||
protected ItemAxe(Item.ToolMaterial material)
|
||||
{
|
||||
super(material, EFFECTIVE_ON);
|
||||
this.attackDamage = ATTACK_DAMAGES[material.ordinal()];
|
||||
this.attackSpeed = ATTACK_SPEEDS[material.ordinal()];
|
||||
}
|
||||
|
||||
protected ItemAxe(Item.ToolMaterial material, float damage, float speed)
|
||||
{
|
||||
super(material, EFFECTIVE_ON);
|
||||
this.attackDamage = damage;
|
||||
this.attackSpeed = speed;
|
||||
}
|
||||
|
||||
public float getDestroySpeed(ItemStack stack, IBlockState state)
|
||||
{
|
||||
Material material = state.getMaterial();
|
||||
return material != Material.WOOD && material != Material.PLANTS && material != Material.VINE ? super.getDestroySpeed(stack, state) : this.efficiency;
|
||||
}
|
||||
}
|
||||
180
build/tmp/recompileMc/sources/net/minecraft/item/ItemBanner.java
Normal file
180
build/tmp/recompileMc/sources/net/minecraft/item/ItemBanner.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.BlockStandingSign;
|
||||
import net.minecraft.block.BlockWallSign;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.BannerPattern;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityBanner;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBanner extends ItemBlock
|
||||
{
|
||||
public ItemBanner()
|
||||
{
|
||||
super(Blocks.STANDING_BANNER);
|
||||
this.maxStackSize = 16;
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
boolean flag = iblockstate.getBlock().isReplaceable(worldIn, pos);
|
||||
|
||||
if (facing != EnumFacing.DOWN && (iblockstate.getMaterial().isSolid() || flag) && (!flag || facing == EnumFacing.UP))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && Blocks.STANDING_BANNER.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = flag ? pos.down() : pos;
|
||||
|
||||
if (facing == EnumFacing.UP)
|
||||
{
|
||||
int i = MathHelper.floor((double)((player.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
worldIn.setBlockState(pos, Blocks.STANDING_BANNER.getDefaultState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setBlockState(pos, Blocks.WALL_BANNER.getDefaultState().withProperty(BlockWallSign.FACING, facing), 3);
|
||||
}
|
||||
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntityBanner)
|
||||
{
|
||||
((TileEntityBanner)tileentity).setItemValues(itemstack, false);
|
||||
}
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
String s = "item.banner.";
|
||||
EnumDyeColor enumdyecolor = getBaseColor(stack);
|
||||
s = s + enumdyecolor.getUnlocalizedName() + ".name";
|
||||
return I18n.translateToLocal(s);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void appendHoverTextFromTileEntityTag(ItemStack stack, List<String> p_185054_1_)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag");
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("Patterns"))
|
||||
{
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount() && i < 6; ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(nbttagcompound1.getInteger("Color"));
|
||||
BannerPattern bannerpattern = BannerPattern.byHash(nbttagcompound1.getString("Pattern"));
|
||||
|
||||
if (bannerpattern != null)
|
||||
{
|
||||
p_185054_1_.add(I18n.translateToLocal("item.banner." + bannerpattern.getFileName() + "." + enumdyecolor.getUnlocalizedName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
appendHoverTextFromTileEntityTag(stack, tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
|
||||
{
|
||||
items.add(makeBanner(enumdyecolor, (NBTTagList)null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack makeBanner(EnumDyeColor p_190910_0_, @Nullable NBTTagList p_190910_1_)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(Items.BANNER, 1, p_190910_0_.getDyeDamage());
|
||||
|
||||
if (p_190910_1_ != null && !p_190910_1_.hasNoTags())
|
||||
{
|
||||
itemstack.getOrCreateSubCompound("BlockEntityTag").setTag("Patterns", p_190910_1_.copy());
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the CreativeTab this item is displayed on
|
||||
*/
|
||||
public CreativeTabs getCreativeTab()
|
||||
{
|
||||
return CreativeTabs.DECORATIONS;
|
||||
}
|
||||
|
||||
public static EnumDyeColor getBaseColor(ItemStack stack)
|
||||
{
|
||||
return EnumDyeColor.byDyeDamage(stack.getMetadata() & 15);
|
||||
}
|
||||
}
|
||||
134
build/tmp/recompileMc/sources/net/minecraft/item/ItemBed.java
Normal file
134
build/tmp/recompileMc/sources/net/minecraft/item/ItemBed.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBed;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityBed;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBed extends Item
|
||||
{
|
||||
public ItemBed()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else if (facing != EnumFacing.UP)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
boolean flag = block.isReplaceable(worldIn, pos);
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
pos = pos.up();
|
||||
}
|
||||
|
||||
int i = MathHelper.floor((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
EnumFacing enumfacing = EnumFacing.getHorizontal(i);
|
||||
BlockPos blockpos = pos.offset(enumfacing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && player.canPlayerEdit(blockpos, facing, itemstack))
|
||||
{
|
||||
IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
|
||||
boolean flag1 = iblockstate1.getBlock().isReplaceable(worldIn, blockpos);
|
||||
boolean flag2 = flag || worldIn.isAirBlock(pos);
|
||||
boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);
|
||||
|
||||
if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid() && worldIn.getBlockState(blockpos.down()).isTopSolid())
|
||||
{
|
||||
IBlockState iblockstate2 = Blocks.BED.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
|
||||
worldIn.setBlockState(pos, iblockstate2, 10);
|
||||
worldIn.setBlockState(blockpos, iblockstate2.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD), 10);
|
||||
SoundType soundtype = iblockstate2.getBlock().getSoundType(iblockstate2, worldIn, pos, player);
|
||||
worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
TileEntity tileentity = worldIn.getTileEntity(blockpos);
|
||||
|
||||
if (tileentity instanceof TileEntityBed)
|
||||
{
|
||||
((TileEntityBed)tileentity).setItemValues(itemstack);
|
||||
}
|
||||
|
||||
TileEntity tileentity1 = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity1 instanceof TileEntityBed)
|
||||
{
|
||||
((TileEntityBed)tileentity1).setItemValues(itemstack);
|
||||
}
|
||||
|
||||
worldIn.notifyNeighborsRespectDebug(pos, block, false);
|
||||
worldIn.notifyNeighborsRespectDebug(blockpos, iblockstate1.getBlock(), false);
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + EnumDyeColor.byMetadata(stack.getMetadata()).getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
items.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
213
build/tmp/recompileMc/sources/net/minecraft/item/ItemBlock.java
Normal file
213
build/tmp/recompileMc/sources/net/minecraft/item/ItemBlock.java
Normal file
@@ -0,0 +1,213 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlock extends Item
|
||||
{
|
||||
protected final Block block;
|
||||
|
||||
public ItemBlock(Block block)
|
||||
{
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, (Entity)null))
|
||||
{
|
||||
int i = this.getMetadata(itemstack.getMetadata());
|
||||
IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
|
||||
|
||||
if (placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
|
||||
{
|
||||
iblockstate1 = worldIn.getBlockState(pos);
|
||||
SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
|
||||
{
|
||||
MinecraftServer minecraftserver = worldIn.getMinecraftServer();
|
||||
|
||||
if (minecraftserver == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stackIn.getSubCompound("BlockEntityTag");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = tileentity.writeToNBT(new NBTTagCompound());
|
||||
NBTTagCompound nbttagcompound2 = nbttagcompound1.copy();
|
||||
nbttagcompound1.merge(nbttagcompound);
|
||||
nbttagcompound1.setInteger("x", pos.getX());
|
||||
nbttagcompound1.setInteger("y", pos.getY());
|
||||
nbttagcompound1.setInteger("z", pos.getZ());
|
||||
|
||||
if (!nbttagcompound1.equals(nbttagcompound2))
|
||||
{
|
||||
tileentity.readFromNBT(nbttagcompound1);
|
||||
tileentity.markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
Block block = worldIn.getBlockState(pos).getBlock();
|
||||
|
||||
if (block == Blocks.SNOW_LAYER && block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
side = EnumFacing.UP;
|
||||
}
|
||||
else if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
return worldIn.mayPlace(this.block, pos, false, side, (Entity)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return this.block.getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item.
|
||||
*/
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return this.block.getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the CreativeTab this item is displayed on
|
||||
*/
|
||||
public CreativeTabs getCreativeTab()
|
||||
{
|
||||
return this.block.getCreativeTabToDisplayOn();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
this.block.getSubBlocks(tab, items);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
this.block.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.getBlockRaw() == null ? null : this.getBlockRaw().delegate.get();
|
||||
}
|
||||
|
||||
private Block getBlockRaw()
|
||||
{
|
||||
return this.block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to actually place the block, after the location is determined
|
||||
* and all permission checks have been made.
|
||||
*
|
||||
* @param stack The item stack that was used to place the block. This can be changed inside the method.
|
||||
* @param player The player who is placing the block. Can be null if the block is not being placed by a player.
|
||||
* @param side The side the player (or machine) right-clicked on.
|
||||
*/
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
|
||||
{
|
||||
if (!world.setBlockState(pos, newState, 11)) return false;
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() == this.block)
|
||||
{
|
||||
setTileEntityNBT(world, player, pos, stack);
|
||||
this.block.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, stack);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSnow;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBlockSpecial extends Item
|
||||
{
|
||||
private final Block block;
|
||||
|
||||
public ItemBlockSpecial(Block block)
|
||||
{
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
|
||||
{
|
||||
facing = EnumFacing.UP;
|
||||
}
|
||||
else if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, (Entity)null))
|
||||
{
|
||||
IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
|
||||
|
||||
if (!worldIn.setBlockState(pos, iblockstate1, 11))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
iblockstate1 = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate1.getBlock() == this.block)
|
||||
{
|
||||
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
|
||||
iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, player, itemstack);
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.getBlockRaw() == null ? null : this.getBlockRaw().delegate.get();
|
||||
}
|
||||
|
||||
private Block getBlockRaw()
|
||||
{
|
||||
return this.block;
|
||||
}
|
||||
}
|
||||
118
build/tmp/recompileMc/sources/net/minecraft/item/ItemBoat.java
Normal file
118
build/tmp/recompileMc/sources/net/minecraft/item/ItemBoat.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityBoat;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBoat extends Item
|
||||
{
|
||||
private final EntityBoat.Type type;
|
||||
|
||||
public ItemBoat(EntityBoat.Type typeIn)
|
||||
{
|
||||
this.type = typeIn;
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
||||
this.setUnlocalizedName("boat." + typeIn.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
float f = 1.0F;
|
||||
float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * 1.0F;
|
||||
float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * 1.0F;
|
||||
double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * 1.0D;
|
||||
double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * 1.0D + (double)playerIn.getEyeHeight();
|
||||
double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * 1.0D;
|
||||
Vec3d vec3d = new Vec3d(d0, d1, d2);
|
||||
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
||||
float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = 5.0D;
|
||||
Vec3d vec3d1 = vec3d.addVector((double)f7 * 5.0D, (double)f6 * 5.0D, (double)f8 * 5.0D);
|
||||
RayTraceResult raytraceresult = worldIn.rayTraceBlocks(vec3d, vec3d1, true);
|
||||
|
||||
if (raytraceresult == null)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3d vec3d2 = playerIn.getLook(1.0F);
|
||||
boolean flag = false;
|
||||
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().expand(vec3d2.x * 5.0D, vec3d2.y * 5.0D, vec3d2.z * 5.0D).grow(1.0D));
|
||||
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
Entity entity = list.get(i);
|
||||
|
||||
if (entity.canBeCollidedWith())
|
||||
{
|
||||
AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().grow((double)entity.getCollisionBorderSize());
|
||||
|
||||
if (axisalignedbb.contains(vec3d))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
Block block = worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock();
|
||||
boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
|
||||
EntityBoat entityboat = new EntityBoat(worldIn, raytraceresult.hitVec.x, flag1 ? raytraceresult.hitVec.y - 0.12D : raytraceresult.hitVec.y, raytraceresult.hitVec.z);
|
||||
entityboat.setBoatType(this.type);
|
||||
entityboat.rotationYaw = playerIn.rotationYaw;
|
||||
|
||||
if (!worldIn.getCollisionBoxes(entityboat, entityboat.getEntityBoundingBox().grow(-0.1D)).isEmpty())
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
worldIn.spawnEntity(entityboat);
|
||||
}
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
public class ItemBook extends Item
|
||||
{
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isEnchantable(ItemStack stack)
|
||||
{
|
||||
return stack.getCount() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
232
build/tmp/recompileMc/sources/net/minecraft/item/ItemBow.java
Normal file
232
build/tmp/recompileMc/sources/net/minecraft/item/ItemBow.java
Normal file
@@ -0,0 +1,232 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBow extends Item
|
||||
{
|
||||
public ItemBow()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(384);
|
||||
this.setCreativeTab(CreativeTabs.COMBAT);
|
||||
this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
if (entityIn == null)
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entityIn.getActiveItemStack().getItem() != Items.BOW ? 0.0F : (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ItemStack findAmmo(EntityPlayer player)
|
||||
{
|
||||
if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND)))
|
||||
{
|
||||
return player.getHeldItem(EnumHand.OFF_HAND);
|
||||
}
|
||||
else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND)))
|
||||
{
|
||||
return player.getHeldItem(EnumHand.MAIN_HAND);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = player.inventory.getStackInSlot(i);
|
||||
|
||||
if (this.isArrow(itemstack))
|
||||
{
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isArrow(ItemStack stack)
|
||||
{
|
||||
return stack.getItem() instanceof ItemArrow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player stops using an Item (stops holding the right mouse button).
|
||||
*/
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
|
||||
{
|
||||
if (entityLiving instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
|
||||
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
|
||||
ItemStack itemstack = this.findAmmo(entityplayer);
|
||||
|
||||
int i = this.getMaxItemUseDuration(stack) - timeLeft;
|
||||
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
|
||||
if (i < 0) return;
|
||||
|
||||
if (!itemstack.isEmpty() || flag)
|
||||
{
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
itemstack = new ItemStack(Items.ARROW);
|
||||
}
|
||||
|
||||
float f = getArrowVelocity(i);
|
||||
|
||||
if ((double)f >= 0.1D)
|
||||
{
|
||||
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
|
||||
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
|
||||
entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
|
||||
|
||||
if (f == 1.0F)
|
||||
{
|
||||
entityarrow.setIsCritical(true);
|
||||
}
|
||||
|
||||
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
|
||||
}
|
||||
|
||||
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
entityarrow.setKnockbackStrength(k);
|
||||
}
|
||||
|
||||
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
|
||||
{
|
||||
entityarrow.setFire(100);
|
||||
}
|
||||
|
||||
stack.damageItem(1, entityplayer);
|
||||
|
||||
if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
|
||||
{
|
||||
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
|
||||
}
|
||||
|
||||
worldIn.spawnEntity(entityarrow);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
|
||||
|
||||
if (!flag1 && !entityplayer.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
entityplayer.inventory.deleteStack(itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
entityplayer.addStat(StatList.getObjectUseStats(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the velocity of the arrow entity from the bow's charge
|
||||
*/
|
||||
public static float getArrowVelocity(int charge)
|
||||
{
|
||||
float f = (float)charge / 20.0F;
|
||||
f = (f * f + f * 2.0F) / 3.0F;
|
||||
|
||||
if (f > 1.0F)
|
||||
{
|
||||
f = 1.0F;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 72000;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return EnumAction.BOW;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
boolean flag = !this.findAmmo(playerIn).isEmpty();
|
||||
|
||||
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
|
||||
if (ret != null) return ret;
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode && !flag)
|
||||
{
|
||||
return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerIn.setActiveHand(handIn);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
209
build/tmp/recompileMc/sources/net/minecraft/item/ItemBucket.java
Normal file
209
build/tmp/recompileMc/sources/net/minecraft/item/ItemBucket.java
Normal file
@@ -0,0 +1,209 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
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.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBucket extends Item
|
||||
{
|
||||
/** field for checking if the bucket has been filled. */
|
||||
private final Block containedBlock;
|
||||
|
||||
public ItemBucket(Block containedBlockIn)
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.containedBlock = containedBlockIn;
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
boolean flag = this.containedBlock == Blocks.AIR;
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, flag);
|
||||
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemstack, raytraceresult);
|
||||
if (ret != null) return ret;
|
||||
|
||||
if (raytraceresult == null)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos blockpos = raytraceresult.getBlockPos();
|
||||
|
||||
if (!worldIn.isBlockModifiable(playerIn, blockpos))
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
else if (flag)
|
||||
{
|
||||
if (!playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
||||
Material material = iblockstate.getMaterial();
|
||||
|
||||
if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
{
|
||||
worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.fillBucket(itemstack, playerIn, Items.WATER_BUCKET));
|
||||
}
|
||||
else if (material == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
{
|
||||
playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
|
||||
worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.fillBucket(itemstack, playerIn, Items.LAVA_BUCKET));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
|
||||
BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemstack))
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
else if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos1))
|
||||
{
|
||||
if (playerIn instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)playerIn, blockpos1, itemstack);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return !playerIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack fillBucket(ItemStack emptyBuckets, EntityPlayer player, Item fullBucket)
|
||||
{
|
||||
if (player.capabilities.isCreativeMode)
|
||||
{
|
||||
return emptyBuckets;
|
||||
}
|
||||
else
|
||||
{
|
||||
emptyBuckets.shrink(1);
|
||||
|
||||
if (emptyBuckets.isEmpty())
|
||||
{
|
||||
return new ItemStack(fullBucket);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.inventory.addItemStackToInventory(new ItemStack(fullBucket)))
|
||||
{
|
||||
player.dropItem(new ItemStack(fullBucket), false);
|
||||
}
|
||||
|
||||
return emptyBuckets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryPlaceContainedLiquid(@Nullable EntityPlayer player, World worldIn, BlockPos posIn)
|
||||
{
|
||||
if (this.containedBlock == Blocks.AIR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(posIn);
|
||||
Material material = iblockstate.getMaterial();
|
||||
boolean flag = !material.isSolid();
|
||||
boolean flag1 = iblockstate.getBlock().isReplaceable(worldIn, posIn);
|
||||
|
||||
if (!worldIn.isAirBlock(posIn) && !flag && !flag1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.provider.doesWaterVaporize() && this.containedBlock == Blocks.FLOWING_WATER)
|
||||
{
|
||||
int l = posIn.getX();
|
||||
int i = posIn.getY();
|
||||
int j = posIn.getZ();
|
||||
worldIn.playSound(player, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
|
||||
|
||||
for (int k = 0; k < 8; ++k)
|
||||
{
|
||||
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)l + Math.random(), (double)i + Math.random(), (double)j + Math.random(), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.isRemote && (flag || flag1) && !material.isLiquid())
|
||||
{
|
||||
worldIn.destroyBlock(posIn, true);
|
||||
}
|
||||
|
||||
SoundEvent soundevent = this.containedBlock == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
|
||||
worldIn.playSound(player, posIn, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
worldIn.setBlockState(posIn, this.containedBlock.getDefaultState(), 11);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraftforge.common.capabilities.ICapabilityProvider initCapabilities(ItemStack stack, @Nullable net.minecraft.nbt.NBTTagCompound nbt) {
|
||||
if (this.getClass() == ItemBucket.class)
|
||||
{
|
||||
return new net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper(stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.initCapabilities(stack, nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBucketMilk extends Item
|
||||
{
|
||||
public ItemBucketMilk()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
|
||||
{
|
||||
if (!worldIn.isRemote) entityLiving.curePotionEffects(stack); // FORGE - move up so stack.shrink does not turn stack into air
|
||||
if (entityLiving instanceof EntityPlayerMP)
|
||||
{
|
||||
EntityPlayerMP entityplayermp = (EntityPlayerMP)entityLiving;
|
||||
CriteriaTriggers.CONSUME_ITEM.trigger(entityplayermp, stack);
|
||||
entityplayermp.addStat(StatList.getObjectUseStats(this));
|
||||
}
|
||||
|
||||
if (entityLiving instanceof EntityPlayer && !((EntityPlayer)entityLiving).capabilities.isCreativeMode)
|
||||
{
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
return stack.isEmpty() ? new ItemStack(Items.BUCKET) : stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return EnumAction.DRINK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraftforge.common.capabilities.ICapabilityProvider initCapabilities(ItemStack stack, net.minecraft.nbt.NBTTagCompound nbt) {
|
||||
return new net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
playerIn.setActiveHand(handIn);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.passive.EntityPig;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemCarrotOnAStick extends Item
|
||||
{
|
||||
public ItemCarrotOnAStick()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(25);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item should be rotated by 180 degrees around the Y axis when being held in an entities
|
||||
* hands.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldRotateAroundWhenRendering()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerIn.isRiding() && playerIn.getRidingEntity() instanceof EntityPig)
|
||||
{
|
||||
EntityPig entitypig = (EntityPig)playerIn.getRidingEntity();
|
||||
|
||||
if (itemstack.getMaxDamage() - itemstack.getMetadata() >= 7 && entitypig.boost())
|
||||
{
|
||||
itemstack.damageItem(7, playerIn);
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
ItemStack itemstack1 = new ItemStack(Items.FISHING_ROD);
|
||||
itemstack1.setTagCompound(itemstack.getTagCompound());
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack1);
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemChorusFruit extends ItemFood
|
||||
{
|
||||
public ItemChorusFruit(int amount, float saturation)
|
||||
{
|
||||
super(amount, saturation, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
|
||||
{
|
||||
ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
double d0 = entityLiving.posX;
|
||||
double d1 = entityLiving.posY;
|
||||
double d2 = entityLiving.posZ;
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
double d3 = entityLiving.posX + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
|
||||
double d4 = MathHelper.clamp(entityLiving.posY + (double)(entityLiving.getRNG().nextInt(16) - 8), 0.0D, (double)(worldIn.getActualHeight() - 1));
|
||||
double d5 = entityLiving.posZ + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
|
||||
|
||||
if (entityLiving.isRiding())
|
||||
{
|
||||
entityLiving.dismountRidingEntity();
|
||||
}
|
||||
|
||||
if (entityLiving.attemptTeleport(d3, d4, d5))
|
||||
{
|
||||
worldIn.playSound((EntityPlayer)null, d0, d1, d2, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||
entityLiving.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entityLiving instanceof EntityPlayer)
|
||||
{
|
||||
((EntityPlayer)entityLiving).getCooldownTracker().setCooldown(this, 20);
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemClock extends Item
|
||||
{
|
||||
public ItemClock()
|
||||
{
|
||||
this.addPropertyOverride(new ResourceLocation("time"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
double rotation;
|
||||
@SideOnly(Side.CLIENT)
|
||||
double rota;
|
||||
@SideOnly(Side.CLIENT)
|
||||
long lastUpdateTick;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
boolean flag = entityIn != null;
|
||||
Entity entity = (Entity)(flag ? entityIn : stack.getItemFrame());
|
||||
|
||||
if (worldIn == null && entity != null)
|
||||
{
|
||||
worldIn = entity.world;
|
||||
}
|
||||
|
||||
if (worldIn == null)
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0;
|
||||
|
||||
if (worldIn.provider.isSurfaceWorld())
|
||||
{
|
||||
d0 = (double)worldIn.getCelestialAngle(1.0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
d0 = Math.random();
|
||||
}
|
||||
|
||||
d0 = this.wobble(worldIn, d0);
|
||||
return (float)d0;
|
||||
}
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private double wobble(World p_185087_1_, double p_185087_2_)
|
||||
{
|
||||
if (p_185087_1_.getTotalWorldTime() != this.lastUpdateTick)
|
||||
{
|
||||
this.lastUpdateTick = p_185087_1_.getTotalWorldTime();
|
||||
double d0 = p_185087_2_ - this.rotation;
|
||||
d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D;
|
||||
this.rota += d0 * 0.1D;
|
||||
this.rota *= 0.9D;
|
||||
this.rotation = MathHelper.positiveModulo(this.rotation + this.rota, 1.0D);
|
||||
}
|
||||
|
||||
return this.rotation;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemCloth extends ItemBlock
|
||||
{
|
||||
public ItemCloth(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + EnumDyeColor.byMetadata(stack.getMetadata()).getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class ItemCoal extends Item
|
||||
{
|
||||
public ItemCoal()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
this.setCreativeTab(CreativeTabs.MATERIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return stack.getMetadata() == 1 ? "item.charcoal" : "item.coal";
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
items.add(new ItemStack(this, 1, 0));
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemColored extends ItemBlock
|
||||
{
|
||||
private String[] subtypeNames;
|
||||
|
||||
public ItemColored(Block block, boolean hasSubtypes)
|
||||
{
|
||||
super(block);
|
||||
|
||||
if (hasSubtypes)
|
||||
{
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
public ItemColored setSubtypeNames(String[] names)
|
||||
{
|
||||
this.subtypeNames = names;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
if (this.subtypeNames == null)
|
||||
{
|
||||
return super.getUnlocalizedName(stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = stack.getMetadata();
|
||||
return i >= 0 && i < this.subtypeNames.length ? super.getUnlocalizedName(stack) + "." + this.subtypeNames[i] : super.getUnlocalizedName(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemCompass extends Item
|
||||
{
|
||||
public ItemCompass()
|
||||
{
|
||||
this.addPropertyOverride(new ResourceLocation("angle"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
double rotation;
|
||||
@SideOnly(Side.CLIENT)
|
||||
double rota;
|
||||
@SideOnly(Side.CLIENT)
|
||||
long lastUpdateTick;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
if (entityIn == null && !stack.isOnItemFrame())
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = entityIn != null;
|
||||
Entity entity = (Entity)(flag ? entityIn : stack.getItemFrame());
|
||||
|
||||
if (worldIn == null)
|
||||
{
|
||||
worldIn = entity.world;
|
||||
}
|
||||
|
||||
double d0;
|
||||
|
||||
if (worldIn.provider.isSurfaceWorld())
|
||||
{
|
||||
double d1 = flag ? (double)entity.rotationYaw : this.getFrameRotation((EntityItemFrame)entity);
|
||||
d1 = MathHelper.positiveModulo(d1 / 360.0D, 1.0D);
|
||||
double d2 = this.getSpawnToAngle(worldIn, entity) / (Math.PI * 2D);
|
||||
d0 = 0.5D - (d1 - 0.25D - d2);
|
||||
}
|
||||
else
|
||||
{
|
||||
d0 = Math.random();
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
d0 = this.wobble(worldIn, d0);
|
||||
}
|
||||
|
||||
return MathHelper.positiveModulo((float)d0, 1.0F);
|
||||
}
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private double wobble(World worldIn, double p_185093_2_)
|
||||
{
|
||||
if (worldIn.getTotalWorldTime() != this.lastUpdateTick)
|
||||
{
|
||||
this.lastUpdateTick = worldIn.getTotalWorldTime();
|
||||
double d0 = p_185093_2_ - this.rotation;
|
||||
d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D;
|
||||
this.rota += d0 * 0.1D;
|
||||
this.rota *= 0.8D;
|
||||
this.rotation = MathHelper.positiveModulo(this.rotation + this.rota, 1.0D);
|
||||
}
|
||||
|
||||
return this.rotation;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private double getFrameRotation(EntityItemFrame p_185094_1_)
|
||||
{
|
||||
return (double)MathHelper.wrapDegrees(180 + p_185094_1_.facingDirection.getHorizontalIndex() * 90);
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private double getSpawnToAngle(World p_185092_1_, Entity p_185092_2_)
|
||||
{
|
||||
BlockPos blockpos = p_185092_1_.getSpawnPoint();
|
||||
return Math.atan2((double)blockpos.getZ() - p_185092_2_.posZ, (double)blockpos.getX() - p_185092_2_.posX);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemDoor extends Item
|
||||
{
|
||||
private final Block block;
|
||||
|
||||
public ItemDoor(Block block)
|
||||
{
|
||||
this.block = block;
|
||||
this.setCreativeTab(CreativeTabs.REDSTONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (facing != EnumFacing.UP)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
EnumFacing enumfacing = EnumFacing.fromAngle((double)player.rotationYaw);
|
||||
int i = enumfacing.getFrontOffsetX();
|
||||
int j = enumfacing.getFrontOffsetZ();
|
||||
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
|
||||
placeDoor(worldIn, pos, enumfacing, this.block, flag);
|
||||
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door, boolean isRightHinge)
|
||||
{
|
||||
BlockPos blockpos = pos.offset(facing.rotateY());
|
||||
BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
|
||||
int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
|
||||
int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
|
||||
boolean flag = worldIn.getBlockState(blockpos1).getBlock() == door || worldIn.getBlockState(blockpos1.up()).getBlock() == door;
|
||||
boolean flag1 = worldIn.getBlockState(blockpos).getBlock() == door || worldIn.getBlockState(blockpos.up()).getBlock() == door;
|
||||
|
||||
if ((!flag || flag1) && j <= i)
|
||||
{
|
||||
if (flag1 && !flag || j < i)
|
||||
{
|
||||
isRightHinge = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isRightHinge = true;
|
||||
}
|
||||
|
||||
BlockPos blockpos2 = pos.up();
|
||||
boolean flag2 = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos2);
|
||||
IBlockState iblockstate = door.getDefaultState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, isRightHinge ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(BlockDoor.POWERED, Boolean.valueOf(flag2)).withProperty(BlockDoor.OPEN, Boolean.valueOf(flag2));
|
||||
worldIn.setBlockState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2);
|
||||
worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2);
|
||||
worldIn.notifyNeighborsOfStateChange(pos, door, false);
|
||||
worldIn.notifyNeighborsOfStateChange(blockpos2, door, false);
|
||||
}
|
||||
}
|
||||
213
build/tmp/recompileMc/sources/net/minecraft/item/ItemDye.java
Normal file
213
build/tmp/recompileMc/sources/net/minecraft/item/ItemDye.java
Normal file
@@ -0,0 +1,213 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockOldLog;
|
||||
import net.minecraft.block.BlockPlanks;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.passive.EntitySheep;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemDye extends Item
|
||||
{
|
||||
public static final int[] DYE_COLORS = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320};
|
||||
|
||||
public ItemDye()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
this.setCreativeTab(CreativeTabs.MATERIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
int i = stack.getMetadata();
|
||||
return super.getUnlocalizedName() + "." + EnumDyeColor.byDyeDamage(i).getUnlocalizedName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(itemstack.getMetadata());
|
||||
|
||||
if (enumdyecolor == EnumDyeColor.WHITE)
|
||||
{
|
||||
if (applyBonemeal(itemstack, worldIn, pos, player, hand))
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
worldIn.playEvent(2005, pos, 0);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else if (enumdyecolor == EnumDyeColor.BROWN)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.LOG && iblockstate.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE)
|
||||
{
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
pos = pos.offset(facing);
|
||||
|
||||
if (worldIn.isAirBlock(pos))
|
||||
{
|
||||
IBlockState iblockstate1 = Blocks.COCOA.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
|
||||
worldIn.setBlockState(pos, iblockstate1, 10);
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)
|
||||
{
|
||||
if (worldIn instanceof net.minecraft.world.WorldServer)
|
||||
return applyBonemeal(stack, worldIn, target, net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer)worldIn), null);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player, @javax.annotation.Nullable EnumHand hand)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(target);
|
||||
|
||||
int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, target, iblockstate, stack, hand);
|
||||
if (hook != 0) return hook > 0;
|
||||
|
||||
if (iblockstate.getBlock() instanceof IGrowable)
|
||||
{
|
||||
IGrowable igrowable = (IGrowable)iblockstate.getBlock();
|
||||
|
||||
if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote))
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))
|
||||
{
|
||||
igrowable.grow(worldIn, worldIn.rand, target, iblockstate);
|
||||
}
|
||||
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void spawnBonemealParticles(World worldIn, BlockPos pos, int amount)
|
||||
{
|
||||
if (amount == 0)
|
||||
{
|
||||
amount = 15;
|
||||
}
|
||||
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getMaterial() != Material.AIR)
|
||||
{
|
||||
for (int i = 0; i < amount; ++i)
|
||||
{
|
||||
double d0 = itemRand.nextGaussian() * 0.02D;
|
||||
double d1 = itemRand.nextGaussian() * 0.02D;
|
||||
double d2 = itemRand.nextGaussian() * 0.02D;
|
||||
worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * iblockstate.getBoundingBox(worldIn, pos).maxY, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i1 = 0; i1 < amount; ++i1)
|
||||
{
|
||||
double d0 = itemRand.nextGaussian() * 0.02D;
|
||||
double d1 = itemRand.nextGaussian() * 0.02D;
|
||||
double d2 = itemRand.nextGaussian() * 0.02D;
|
||||
worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * 1.0f, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2, new int[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
|
||||
{
|
||||
if (target instanceof EntitySheep)
|
||||
{
|
||||
EntitySheep entitysheep = (EntitySheep)target;
|
||||
EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());
|
||||
|
||||
if (!entitysheep.getSheared() && entitysheep.getFleeceColor() != enumdyecolor)
|
||||
{
|
||||
entitysheep.setFleeceColor(enumdyecolor);
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
items.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityEgg;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemEgg extends Item
|
||||
{
|
||||
public ItemEgg()
|
||||
{
|
||||
this.maxStackSize = 16;
|
||||
this.setCreativeTab(CreativeTabs.MATERIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityEgg entityegg = new EntityEgg(worldIn, playerIn);
|
||||
entityegg.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
|
||||
worldIn.spawnEntity(entityegg);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemElytra extends Item
|
||||
{
|
||||
public ItemElytra()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(432);
|
||||
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
||||
this.addPropertyOverride(new ResourceLocation("broken"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
return ItemElytra.isUsable(stack) ? 0.0F : 1.0F;
|
||||
}
|
||||
});
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, ItemArmor.DISPENSER_BEHAVIOR);
|
||||
}
|
||||
|
||||
public static boolean isUsable(ItemStack stack)
|
||||
{
|
||||
return stack.getItemDamage() < stack.getMaxDamage() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*
|
||||
* @param toRepair the {@code ItemStack} being repaired
|
||||
* @param repair the {@code ItemStack} being used to perform the repair
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return repair.getItem() == Items.LEATHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
|
||||
ItemStack itemstack1 = playerIn.getItemStackFromSlot(entityequipmentslot);
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
playerIn.setItemStackToSlot(entityequipmentslot, itemstack.copy());
|
||||
itemstack.setCount(0);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemEmptyMap extends ItemMapBase
|
||||
{
|
||||
protected ItemEmptyMap()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = ItemMap.setupNewMap(worldIn, playerIn.posX, playerIn.posZ, (byte)0, true, false);
|
||||
ItemStack itemstack1 = playerIn.getHeldItem(handIn);
|
||||
itemstack1.shrink(1);
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!playerIn.inventory.addItemStackToInventory(itemstack.copy()))
|
||||
{
|
||||
playerIn.dropItem(itemstack, false);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentData;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemEnchantedBook extends Item
|
||||
{
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isEnchantable(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an item rarity from EnumRarity
|
||||
*/
|
||||
public EnumRarity getRarity(ItemStack stack)
|
||||
{
|
||||
return getEnchantments(stack).hasNoTags() ? super.getRarity(stack) : EnumRarity.UNCOMMON;
|
||||
}
|
||||
|
||||
public static NBTTagList getEnchantments(ItemStack p_92110_0_)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = p_92110_0_.getTagCompound();
|
||||
return nbttagcompound != null ? nbttagcompound.getTagList("StoredEnchantments", 10) : new NBTTagList();
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
NBTTagList nbttaglist = getEnchantments(stack);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound.getShort("id");
|
||||
Enchantment enchantment = Enchantment.getEnchantmentByID(j);
|
||||
|
||||
if (enchantment != null)
|
||||
{
|
||||
tooltip.add(enchantment.getTranslatedName(nbttagcompound.getShort("lvl")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an stored enchantment to an enchanted book ItemStack
|
||||
*/
|
||||
public static void addEnchantment(ItemStack p_92115_0_, EnchantmentData stack)
|
||||
{
|
||||
NBTTagList nbttaglist = getEnchantments(p_92115_0_);
|
||||
boolean flag = true;
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
|
||||
if (Enchantment.getEnchantmentByID(nbttagcompound.getShort("id")) == stack.enchantment)
|
||||
{
|
||||
if (nbttagcompound.getShort("lvl") < stack.enchantmentLevel)
|
||||
{
|
||||
nbttagcompound.setShort("lvl", (short)stack.enchantmentLevel);
|
||||
}
|
||||
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setShort("id", (short)Enchantment.getEnchantmentID(stack.enchantment));
|
||||
nbttagcompound1.setShort("lvl", (short)stack.enchantmentLevel);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
|
||||
if (!p_92115_0_.hasTagCompound())
|
||||
{
|
||||
p_92115_0_.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
p_92115_0_.getTagCompound().setTag("StoredEnchantments", nbttaglist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ItemStack of an enchanted version of this item.
|
||||
*/
|
||||
public static ItemStack getEnchantedItemStack(EnchantmentData p_92111_0_)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(Items.ENCHANTED_BOOK);
|
||||
addEnchantment(itemstack, p_92111_0_);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (tab == CreativeTabs.SEARCH)
|
||||
{
|
||||
for (Enchantment enchantment : Enchantment.REGISTRY)
|
||||
{
|
||||
if (enchantment.type != null)
|
||||
{
|
||||
for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i)
|
||||
{
|
||||
items.add(getEnchantedItemStack(new EnchantmentData(enchantment, i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tab.getRelevantEnchantmentTypes().length != 0)
|
||||
{
|
||||
for (Enchantment enchantment1 : Enchantment.REGISTRY)
|
||||
{
|
||||
if (tab.hasRelevantEnchantmentType(enchantment1.type))
|
||||
{
|
||||
items.add(getEnchantedItemStack(new EnchantmentData(enchantment1, enchantment1.getMaxLevel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityEnderCrystal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProviderEnd;
|
||||
import net.minecraft.world.end.DragonFightManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemEndCrystal extends Item
|
||||
{
|
||||
public ItemEndCrystal()
|
||||
{
|
||||
this.setUnlocalizedName("end_crystal");
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getBlock() != Blocks.OBSIDIAN && iblockstate.getBlock() != Blocks.BEDROCK)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos blockpos = pos.up();
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(blockpos, facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos blockpos1 = blockpos.up();
|
||||
boolean flag = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
|
||||
flag = flag | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));
|
||||
|
||||
if (flag)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0 = (double)blockpos.getX();
|
||||
double d1 = (double)blockpos.getY();
|
||||
double d2 = (double)blockpos.getZ();
|
||||
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(worldIn, (double)((float)pos.getX() + 0.5F), (double)(pos.getY() + 1), (double)((float)pos.getZ() + 0.5F));
|
||||
entityendercrystal.setShowBottom(false);
|
||||
worldIn.spawnEntity(entityendercrystal);
|
||||
|
||||
if (worldIn.provider instanceof WorldProviderEnd)
|
||||
{
|
||||
DragonFightManager dragonfightmanager = ((WorldProviderEnd)worldIn.provider).getDragonFightManager();
|
||||
dragonfightmanager.respawnDragon();
|
||||
}
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.BlockEndPortalFrame;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.block.state.pattern.BlockPattern;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityEnderEye;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class ItemEnderEye extends Item
|
||||
{
|
||||
public ItemEnderEye()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos.offset(facing), facing, itemstack) && iblockstate.getBlock() == Blocks.END_PORTAL_FRAME && !((Boolean)iblockstate.getValue(BlockEndPortalFrame.EYE)).booleanValue())
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setBlockState(pos, iblockstate.withProperty(BlockEndPortalFrame.EYE, Boolean.valueOf(true)), 2);
|
||||
worldIn.updateComparatorOutputLevel(pos, Blocks.END_PORTAL_FRAME);
|
||||
itemstack.shrink(1);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
double d0 = (double)((float)pos.getX() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
|
||||
double d1 = (double)((float)pos.getY() + 0.8125F);
|
||||
double d2 = (double)((float)pos.getZ() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
|
||||
double d3 = 0.0D;
|
||||
double d4 = 0.0D;
|
||||
double d5 = 0.0D;
|
||||
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
BlockPattern.PatternHelper blockpattern$patternhelper = BlockEndPortalFrame.getOrCreatePortalShape().match(worldIn, pos);
|
||||
|
||||
if (blockpattern$patternhelper != null)
|
||||
{
|
||||
BlockPos blockpos = blockpattern$patternhelper.getFrontTopLeft().add(-3, 0, -3);
|
||||
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
worldIn.setBlockState(blockpos.add(j, 0, k), Blocks.END_PORTAL.getDefaultState(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
worldIn.playBroadcastSound(1038, blockpos.add(1, 0, 1), 0);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);
|
||||
|
||||
if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerIn.setActiveHand(handIn);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
BlockPos blockpos = ((WorldServer)worldIn).getChunkProvider().getNearestStructurePos(worldIn, "Stronghold", new BlockPos(playerIn), false);
|
||||
|
||||
if (blockpos != null)
|
||||
{
|
||||
EntityEnderEye entityendereye = new EntityEnderEye(worldIn, playerIn.posX, playerIn.posY + (double)(playerIn.height / 2.0F), playerIn.posZ);
|
||||
entityendereye.moveTowards(blockpos);
|
||||
worldIn.spawnEntity(entityendereye);
|
||||
|
||||
if (playerIn instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.USED_ENDER_EYE.trigger((EntityPlayerMP)playerIn, blockpos);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDEREYE_LAUNCH, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
worldIn.playEvent((EntityPlayer)null, 1003, new BlockPos(playerIn), 0);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityEnderPearl;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemEnderPearl extends Item
|
||||
{
|
||||
public ItemEnderPearl()
|
||||
{
|
||||
this.maxStackSize = 16;
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDERPEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
playerIn.getCooldownTracker().setCooldown(this, 20);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityEnderPearl entityenderpearl = new EntityEnderPearl(worldIn, playerIn);
|
||||
entityenderpearl.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
|
||||
worldIn.spawnEntity(entityenderpearl);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityExpBottle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemExpBottle extends Item
|
||||
{
|
||||
public ItemExpBottle()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityExpBottle entityexpbottle = new EntityExpBottle(worldIn, playerIn);
|
||||
entityexpbottle.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.7F, 1.0F);
|
||||
worldIn.spawnEntity(entityexpbottle);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFireball extends Item
|
||||
{
|
||||
public ItemFireball()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(pos, facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.getBlockState(pos).getMaterial() == Material.AIR)
|
||||
{
|
||||
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (itemRand.nextFloat() - itemRand.nextFloat()) * 0.2F + 1.0F);
|
||||
worldIn.setBlockState(pos, Blocks.FIRE.getDefaultState());
|
||||
}
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.item.EntityFireworkRocket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemFirework extends Item
|
||||
{
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
EntityFireworkRocket entityfireworkrocket = new EntityFireworkRocket(worldIn, (double)((float)pos.getX() + hitX), (double)((float)pos.getY() + hitY), (double)((float)pos.getZ() + hitZ), itemstack);
|
||||
worldIn.spawnEntity(entityfireworkrocket);
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
if (playerIn.isElytraFlying())
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityFireworkRocket entityfireworkrocket = new EntityFireworkRocket(worldIn, itemstack, playerIn);
|
||||
worldIn.spawnEntity(entityfireworkrocket);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getSubCompound("Fireworks");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
if (nbttagcompound.hasKey("Flight", 99))
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("item.fireworks.flight") + " " + nbttagcompound.getByte("Flight"));
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Explosions", 10);
|
||||
|
||||
if (!nbttaglist.hasNoTags())
|
||||
{
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
ItemFireworkCharge.addExplosionInfo(nbttagcompound1, list);
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
for (int j = 1; j < list.size(); ++j)
|
||||
{
|
||||
list.set(j, " " + (String)list.get(j));
|
||||
}
|
||||
|
||||
tooltip.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemFireworkCharge extends Item
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static NBTBase getExplosionTag(ItemStack stack, String key)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("Explosion");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
return nbttagcompound.getTag(key);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("Explosion");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
addExplosionInfo(nbttagcompound, tooltip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void addExplosionInfo(NBTTagCompound nbt, List<String> tooltip)
|
||||
{
|
||||
byte b0 = nbt.getByte("Type");
|
||||
|
||||
if (b0 >= 0 && b0 <= 4)
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("item.fireworksCharge.type." + b0).trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("item.fireworksCharge.type").trim());
|
||||
}
|
||||
|
||||
int[] aint = nbt.getIntArray("Colors");
|
||||
|
||||
if (aint.length > 0)
|
||||
{
|
||||
boolean flag = true;
|
||||
String s = "";
|
||||
|
||||
for (int i : aint)
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
s = s + ", ";
|
||||
}
|
||||
|
||||
flag = false;
|
||||
boolean flag1 = false;
|
||||
|
||||
for (int j = 0; j < ItemDye.DYE_COLORS.length; ++j)
|
||||
{
|
||||
if (i == ItemDye.DYE_COLORS[j])
|
||||
{
|
||||
flag1 = true;
|
||||
s = s + I18n.translateToLocal("item.fireworksCharge." + EnumDyeColor.byDyeDamage(j).getUnlocalizedName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag1)
|
||||
{
|
||||
s = s + I18n.translateToLocal("item.fireworksCharge.customColor");
|
||||
}
|
||||
}
|
||||
|
||||
tooltip.add(s);
|
||||
}
|
||||
|
||||
int[] aint1 = nbt.getIntArray("FadeColors");
|
||||
|
||||
if (aint1.length > 0)
|
||||
{
|
||||
boolean flag2 = true;
|
||||
String s1 = I18n.translateToLocal("item.fireworksCharge.fadeTo") + " ";
|
||||
|
||||
for (int l : aint1)
|
||||
{
|
||||
if (!flag2)
|
||||
{
|
||||
s1 = s1 + ", ";
|
||||
}
|
||||
|
||||
flag2 = false;
|
||||
boolean flag5 = false;
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
if (l == ItemDye.DYE_COLORS[k])
|
||||
{
|
||||
flag5 = true;
|
||||
s1 = s1 + I18n.translateToLocal("item.fireworksCharge." + EnumDyeColor.byDyeDamage(k).getUnlocalizedName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag5)
|
||||
{
|
||||
s1 = s1 + I18n.translateToLocal("item.fireworksCharge.customColor");
|
||||
}
|
||||
}
|
||||
|
||||
tooltip.add(s1);
|
||||
}
|
||||
|
||||
boolean flag3 = nbt.getBoolean("Trail");
|
||||
|
||||
if (flag3)
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("item.fireworksCharge.trail"));
|
||||
}
|
||||
|
||||
boolean flag4 = nbt.getBoolean("Flicker");
|
||||
|
||||
if (flag4)
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("item.fireworksCharge.flicker"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFishFood extends ItemFood
|
||||
{
|
||||
/** Indicates whether this fish is "cooked" or not. */
|
||||
private final boolean cooked;
|
||||
|
||||
public ItemFishFood(boolean cooked)
|
||||
{
|
||||
super(0, 0.0F, false);
|
||||
this.cooked = cooked;
|
||||
}
|
||||
|
||||
public int getHealAmount(ItemStack stack)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
return this.cooked && itemfishfood$fishtype.canCook() ? itemfishfood$fishtype.getCookedHealAmount() : itemfishfood$fishtype.getUncookedHealAmount();
|
||||
}
|
||||
|
||||
public float getSaturationModifier(ItemStack stack)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
return this.cooked && itemfishfood$fishtype.canCook() ? itemfishfood$fishtype.getCookedSaturationModifier() : itemfishfood$fishtype.getUncookedSaturationModifier();
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
|
||||
if (itemfishfood$fishtype == ItemFishFood.FishType.PUFFERFISH)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.POISON, 1200, 3));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 300, 2));
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 300, 1));
|
||||
}
|
||||
|
||||
super.onFoodEaten(stack, worldIn, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
|
||||
{
|
||||
if (!this.cooked || itemfishfood$fishtype.canCook())
|
||||
{
|
||||
items.add(new ItemStack(this, 1, itemfishfood$fishtype.getMetadata()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
return this.getUnlocalizedName() + "." + itemfishfood$fishtype.getUnlocalizedName() + "." + (this.cooked && itemfishfood$fishtype.canCook() ? "cooked" : "raw");
|
||||
}
|
||||
|
||||
public static enum FishType
|
||||
{
|
||||
COD(0, "cod", 2, 0.1F, 5, 0.6F),
|
||||
SALMON(1, "salmon", 2, 0.1F, 6, 0.8F),
|
||||
CLOWNFISH(2, "clownfish", 1, 0.1F),
|
||||
PUFFERFISH(3, "pufferfish", 1, 0.1F);
|
||||
|
||||
/** Maps an item damage value for an ItemStack to the corresponding FishType value. */
|
||||
private static final Map<Integer, ItemFishFood.FishType> META_LOOKUP = Maps.<Integer, ItemFishFood.FishType>newHashMap();
|
||||
/** The item damage value on an ItemStack that represents this fish type */
|
||||
private final int meta;
|
||||
/**
|
||||
* The value that this fish type uses to replace "XYZ" in: "fish.XYZ.raw" / "fish.XYZ.cooked" for the
|
||||
* unlocalized name and "fish_XYZ_raw" / "fish_XYZ_cooked" for the icon string.
|
||||
*/
|
||||
private final String unlocalizedName;
|
||||
/** The amount that eating the uncooked version of this fish should heal the player. */
|
||||
private final int uncookedHealAmount;
|
||||
/** The saturation modifier to apply to the heal amount when the player eats the uncooked version of this fish. */
|
||||
private final float uncookedSaturationModifier;
|
||||
/** The amount that eating the cooked version of this fish should heal the player. */
|
||||
private final int cookedHealAmount;
|
||||
/** The saturation modifier to apply to the heal amount when the player eats the cooked version of this fish. */
|
||||
private final float cookedSaturationModifier;
|
||||
/** Indicates whether this type of fish has "raw" and "cooked" variants */
|
||||
private final boolean cookable;
|
||||
|
||||
private FishType(int meta, String unlocalizedName, int uncookedHeal, float uncookedSaturation, int cookedHeal, float cookedSaturation)
|
||||
{
|
||||
this.meta = meta;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.uncookedHealAmount = uncookedHeal;
|
||||
this.uncookedSaturationModifier = uncookedSaturation;
|
||||
this.cookedHealAmount = cookedHeal;
|
||||
this.cookedSaturationModifier = cookedSaturation;
|
||||
this.cookable = true;
|
||||
}
|
||||
|
||||
private FishType(int meta, String unlocalizedName, int uncookedHeal, float uncookedSaturation)
|
||||
{
|
||||
this.meta = meta;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.uncookedHealAmount = uncookedHeal;
|
||||
this.uncookedSaturationModifier = uncookedSaturation;
|
||||
this.cookedHealAmount = 0;
|
||||
this.cookedSaturationModifier = 0.0F;
|
||||
this.cookable = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item damage value on an ItemStack that represents this fish type
|
||||
*/
|
||||
public int getMetadata()
|
||||
{
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value that this fish type uses to replace "XYZ" in: "fish.XYZ.raw" / "fish.XYZ.cooked" for the
|
||||
* unlocalized name and "fish_XYZ_raw" / "fish_XYZ_cooked" for the icon string.
|
||||
*/
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return this.unlocalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount that eating the uncooked version of this fish should heal the player.
|
||||
*/
|
||||
public int getUncookedHealAmount()
|
||||
{
|
||||
return this.uncookedHealAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the saturation modifier to apply to the heal amount when the player eats the uncooked version of this
|
||||
* fish.
|
||||
*/
|
||||
public float getUncookedSaturationModifier()
|
||||
{
|
||||
return this.uncookedSaturationModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount that eating the cooked version of this fish should heal the player.
|
||||
*/
|
||||
public int getCookedHealAmount()
|
||||
{
|
||||
return this.cookedHealAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the saturation modifier to apply to the heal amount when the player eats the cooked version of this
|
||||
* fish.
|
||||
*/
|
||||
public float getCookedSaturationModifier()
|
||||
{
|
||||
return this.cookedSaturationModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this type of fish has "raw" and "cooked" variants.
|
||||
*/
|
||||
public boolean canCook()
|
||||
{
|
||||
return this.cookable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the corresponding FishType value for the given item damage value of an ItemStack, defaulting to COD for
|
||||
* unrecognized damage values.
|
||||
*/
|
||||
public static ItemFishFood.FishType byMetadata(int meta)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = META_LOOKUP.get(Integer.valueOf(meta));
|
||||
return itemfishfood$fishtype == null ? COD : itemfishfood$fishtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the FishType that corresponds to the given ItemStack, defaulting to COD if the given ItemStack does not
|
||||
* actually contain a fish.
|
||||
*/
|
||||
public static ItemFishFood.FishType byItemStack(ItemStack stack)
|
||||
{
|
||||
return stack.getItem() instanceof ItemFishFood ? byMetadata(stack.getMetadata()) : COD;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
for (ItemFishFood.FishType itemfishfood$fishtype : values())
|
||||
{
|
||||
META_LOOKUP.put(Integer.valueOf(itemfishfood$fishtype.getMetadata()), itemfishfood$fishtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityFishHook;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemFishingRod extends Item
|
||||
{
|
||||
public ItemFishingRod()
|
||||
{
|
||||
this.setMaxDamage(64);
|
||||
this.setMaxStackSize(1);
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
if (entityIn == null)
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean flag = entityIn.getHeldItemMainhand() == stack;
|
||||
boolean flag1 = entityIn.getHeldItemOffhand() == stack;
|
||||
|
||||
if (entityIn.getHeldItemMainhand().getItem() instanceof ItemFishingRod)
|
||||
{
|
||||
flag1 = false;
|
||||
}
|
||||
|
||||
return (flag || flag1) && entityIn instanceof EntityPlayer && ((EntityPlayer)entityIn).fishEntity != null ? 1.0F : 0.0F;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item should be rotated by 180 degrees around the Y axis when being held in an entities
|
||||
* hands.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldRotateAroundWhenRendering()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (playerIn.fishEntity != null)
|
||||
{
|
||||
int i = playerIn.fishEntity.handleHookRetraction();
|
||||
itemstack.damageItem(i, playerIn);
|
||||
playerIn.swingArm(handIn);
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityFishHook entityfishhook = new EntityFishHook(worldIn, playerIn);
|
||||
int j = EnchantmentHelper.getFishingSpeedBonus(itemstack);
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
entityfishhook.setLureSpeed(j);
|
||||
}
|
||||
|
||||
int k = EnchantmentHelper.getFishingLuckBonus(itemstack);
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
entityfishhook.setLuck(k);
|
||||
}
|
||||
|
||||
worldIn.spawnEntity(entityfishhook);
|
||||
}
|
||||
|
||||
playerIn.swingArm(handIn);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFlintAndSteel extends Item
|
||||
{
|
||||
public ItemFlintAndSteel()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(64);
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(pos, facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.isAirBlock(pos))
|
||||
{
|
||||
worldIn.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
|
||||
worldIn.setBlockState(pos, Blocks.FIRE.getDefaultState(), 11);
|
||||
}
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.damageItem(1, player);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
build/tmp/recompileMc/sources/net/minecraft/item/ItemFood.java
Normal file
146
build/tmp/recompileMc/sources/net/minecraft/item/ItemFood.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFood extends Item
|
||||
{
|
||||
/** Number of ticks to run while 'EnumAction'ing until result. */
|
||||
public final int itemUseDuration;
|
||||
/** The amount this food item heals the player. */
|
||||
private final int healAmount;
|
||||
private final float saturationModifier;
|
||||
/** Whether wolves like this food (true for raw and cooked porkchop). */
|
||||
private final boolean isWolfsFavoriteMeat;
|
||||
/** If this field is true, the food can be consumed even if the player don't need to eat. */
|
||||
private boolean alwaysEdible;
|
||||
/** represents the potion effect that will occurr upon eating this food. Set by setPotionEffect */
|
||||
private PotionEffect potionId;
|
||||
/** probably of the set potion effect occurring */
|
||||
private float potionEffectProbability;
|
||||
|
||||
public ItemFood(int amount, float saturation, boolean isWolfFood)
|
||||
{
|
||||
this.itemUseDuration = 32;
|
||||
this.healAmount = amount;
|
||||
this.isWolfsFavoriteMeat = isWolfFood;
|
||||
this.saturationModifier = saturation;
|
||||
this.setCreativeTab(CreativeTabs.FOOD);
|
||||
}
|
||||
|
||||
public ItemFood(int amount, boolean isWolfFood)
|
||||
{
|
||||
this(amount, 0.6F, isWolfFood);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
|
||||
{
|
||||
if (entityLiving instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
|
||||
entityplayer.getFoodStats().addStats(this, stack);
|
||||
worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
|
||||
this.onFoodEaten(stack, worldIn, entityplayer);
|
||||
entityplayer.addStat(StatList.getObjectUseStats(this));
|
||||
|
||||
if (entityplayer instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
|
||||
}
|
||||
}
|
||||
|
||||
stack.shrink(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
if (!worldIn.isRemote && this.potionId != null && worldIn.rand.nextFloat() < this.potionEffectProbability)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(this.potionId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return EnumAction.EAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (playerIn.canEat(this.alwaysEdible))
|
||||
{
|
||||
playerIn.setActiveHand(handIn);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHealAmount(ItemStack stack)
|
||||
{
|
||||
return this.healAmount;
|
||||
}
|
||||
|
||||
public float getSaturationModifier(ItemStack stack)
|
||||
{
|
||||
return this.saturationModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether wolves like this food (true for raw and cooked porkchop).
|
||||
*/
|
||||
public boolean isWolfsFavoriteMeat()
|
||||
{
|
||||
return this.isWolfsFavoriteMeat;
|
||||
}
|
||||
|
||||
public ItemFood setPotionEffect(PotionEffect effect, float probability)
|
||||
{
|
||||
this.potionId = effect;
|
||||
this.potionEffectProbability = probability;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field 'alwaysEdible' to true, and make the food edible even if the player don't need to eat.
|
||||
*/
|
||||
public ItemFood setAlwaysEdible()
|
||||
{
|
||||
this.alwaysEdible = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityAreaEffectCloud;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.PotionTypes;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemGlassBottle extends Item
|
||||
{
|
||||
public ItemGlassBottle()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.BREWING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
List<EntityAreaEffectCloud> list = worldIn.<EntityAreaEffectCloud>getEntitiesWithinAABB(EntityAreaEffectCloud.class, playerIn.getEntityBoundingBox().grow(2.0D), new Predicate<EntityAreaEffectCloud>()
|
||||
{
|
||||
public boolean apply(@Nullable EntityAreaEffectCloud p_apply_1_)
|
||||
{
|
||||
return p_apply_1_ != null && p_apply_1_.isEntityAlive() && p_apply_1_.getOwner() instanceof EntityDragon;
|
||||
}
|
||||
});
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
EntityAreaEffectCloud entityareaeffectcloud = list.get(0);
|
||||
entityareaeffectcloud.setRadius(entityareaeffectcloud.getRadius() - 0.5F);
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.NEUTRAL, 1.0F, 1.0F);
|
||||
return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemstack, playerIn, new ItemStack(Items.DRAGON_BREATH)));
|
||||
}
|
||||
else
|
||||
{
|
||||
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);
|
||||
|
||||
if (raytraceresult == null)
|
||||
{
|
||||
return new ActionResult(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = raytraceresult.getBlockPos();
|
||||
|
||||
if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
|
||||
{
|
||||
return new ActionResult(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
|
||||
if (worldIn.getBlockState(blockpos).getMaterial() == Material.WATER)
|
||||
{
|
||||
worldIn.playSound(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
|
||||
return new ActionResult(EnumActionResult.SUCCESS, this.turnBottleIntoItem(itemstack, playerIn, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER)));
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionResult(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ItemStack turnBottleIntoItem(ItemStack p_185061_1_, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
p_185061_1_.shrink(1);
|
||||
player.addStat(StatList.getObjectUseStats(this));
|
||||
|
||||
if (p_185061_1_.isEmpty())
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.inventory.addItemStackToInventory(stack))
|
||||
{
|
||||
player.dropItem(stack, false);
|
||||
}
|
||||
|
||||
return p_185061_1_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.entity.item.EntityPainting;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemHangingEntity extends Item
|
||||
{
|
||||
private final Class <? extends EntityHanging > hangingEntityClass;
|
||||
|
||||
public ItemHangingEntity(Class <? extends EntityHanging > entityClass)
|
||||
{
|
||||
this.hangingEntityClass = entityClass;
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
BlockPos blockpos = pos.offset(facing);
|
||||
|
||||
if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && player.canPlayerEdit(blockpos, facing, itemstack))
|
||||
{
|
||||
EntityHanging entityhanging = this.createEntity(worldIn, blockpos, facing);
|
||||
|
||||
if (entityhanging != null && entityhanging.onValidSurface())
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
entityhanging.playPlaceSound();
|
||||
worldIn.spawnEntity(entityhanging);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private EntityHanging createEntity(World worldIn, BlockPos pos, EnumFacing clickedSide)
|
||||
{
|
||||
if (this.hangingEntityClass == EntityPainting.class)
|
||||
{
|
||||
return new EntityPainting(worldIn, pos, clickedSide);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.hangingEntityClass == EntityItemFrame.class ? new EntityItemFrame(worldIn, pos, clickedSide) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
139
build/tmp/recompileMc/sources/net/minecraft/item/ItemHoe.java
Normal file
139
build/tmp/recompileMc/sources/net/minecraft/item/ItemHoe.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemHoe extends Item
|
||||
{
|
||||
private final float speed;
|
||||
protected Item.ToolMaterial toolMaterial;
|
||||
|
||||
public ItemHoe(Item.ToolMaterial material)
|
||||
{
|
||||
this.toolMaterial = material;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(material.getMaxUses());
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
this.speed = material.getAttackDamage() + 1.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(itemstack, player, worldIn, pos);
|
||||
if (hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
|
||||
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
if (block == Blocks.GRASS || block == Blocks.GRASS_PATH)
|
||||
{
|
||||
this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (block == Blocks.DIRT)
|
||||
{
|
||||
switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
|
||||
{
|
||||
case DIRT:
|
||||
this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
|
||||
return EnumActionResult.SUCCESS;
|
||||
case COARSE_DIRT:
|
||||
this.setBlock(itemstack, player, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||
{
|
||||
stack.damageItem(1, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state)
|
||||
{
|
||||
worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
worldIn.setBlockState(pos, state, 11);
|
||||
stack.damageItem(1, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the material this tool is made from as it is declared in EnumToolMaterial (meaning diamond
|
||||
* would return "EMERALD")
|
||||
*/
|
||||
public String getMaterialName()
|
||||
{
|
||||
return this.toolMaterial.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
|
||||
*/
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
||||
{
|
||||
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
||||
|
||||
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
|
||||
{
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 0.0D, 0));
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", (double)(this.speed - 4.0F), 0));
|
||||
}
|
||||
|
||||
return multimap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ItemKnowledgeBook extends Item
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public ItemKnowledgeBook()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
NBTTagCompound nbttagcompound = itemstack.getTagCompound();
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
playerIn.setHeldItem(handIn, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("Recipes", 9))
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Recipes", 8);
|
||||
List<IRecipe> list = Lists.<IRecipe>newArrayList();
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
String s = nbttaglist.getStringTagAt(i);
|
||||
IRecipe irecipe = CraftingManager.getRecipe(new ResourceLocation(s));
|
||||
|
||||
if (irecipe == null)
|
||||
{
|
||||
LOGGER.error("Invalid recipe: " + s);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
|
||||
list.add(irecipe);
|
||||
}
|
||||
|
||||
playerIn.unlockRecipes(list);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.error("Tag not valid: " + nbttagcompound);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFence;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLeashKnot;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemLead extends Item
|
||||
{
|
||||
public ItemLead()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
Block block = worldIn.getBlockState(pos).getBlock();
|
||||
|
||||
if (!(block instanceof BlockFence))
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
attachToFence(player, worldIn, pos);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean attachToFence(EntityPlayer player, World worldIn, BlockPos fence)
|
||||
{
|
||||
EntityLeashKnot entityleashknot = EntityLeashKnot.getKnotForPosition(worldIn, fence);
|
||||
boolean flag = false;
|
||||
double d0 = 7.0D;
|
||||
int i = fence.getX();
|
||||
int j = fence.getY();
|
||||
int k = fence.getZ();
|
||||
|
||||
for (EntityLiving entityliving : worldIn.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB((double)i - 7.0D, (double)j - 7.0D, (double)k - 7.0D, (double)i + 7.0D, (double)j + 7.0D, (double)k + 7.0D)))
|
||||
{
|
||||
if (entityliving.getLeashed() && entityliving.getLeashHolder() == player)
|
||||
{
|
||||
if (entityleashknot == null)
|
||||
{
|
||||
entityleashknot = EntityLeashKnot.createKnot(worldIn, fence);
|
||||
}
|
||||
|
||||
entityliving.setLeashHolder(entityleashknot, true);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.BlockLeaves;
|
||||
|
||||
public class ItemLeaves extends ItemBlock
|
||||
{
|
||||
private final BlockLeaves leaves;
|
||||
|
||||
public ItemLeaves(BlockLeaves block)
|
||||
{
|
||||
super(block);
|
||||
this.leaves = block;
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage | 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + this.leaves.getWoodType(stack.getMetadata()).getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemLilyPad extends ItemColored
|
||||
{
|
||||
public ItemLilyPad(Block block)
|
||||
{
|
||||
super(block, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);
|
||||
|
||||
if (raytraceresult == null)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = raytraceresult.getBlockPos();
|
||||
|
||||
if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
|
||||
BlockPos blockpos1 = blockpos.up();
|
||||
IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
||||
|
||||
if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
|
||||
{
|
||||
// special case for handling block placement with water lilies
|
||||
net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
|
||||
worldIn.setBlockState(blockpos1, Blocks.WATERLILY.getDefaultState());
|
||||
if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, handIn).isCanceled())
|
||||
{
|
||||
blocksnapshot.restore(true, false);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
|
||||
worldIn.setBlockState(blockpos1, Blocks.WATERLILY.getDefaultState(), 11);
|
||||
|
||||
if (playerIn instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)playerIn, blockpos1, itemstack);
|
||||
}
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityPotion;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemLingeringPotion extends ItemPotion
|
||||
{
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
return I18n.translateToLocal(PotionUtils.getPotionFromItem(stack).getNamePrefixed("lingering_potion.effect."));
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
PotionUtils.addPotionTooltip(stack, tooltip, 0.25F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
ItemStack itemstack1 = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_LINGERINGPOTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityPotion entitypotion = new EntityPotion(worldIn, playerIn, itemstack1);
|
||||
entitypotion.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
|
||||
worldIn.spawnEntity(entitypotion);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
507
build/tmp/recompileMc/sources/net/minecraft/item/ItemMap.java
Normal file
507
build/tmp/recompileMc/sources/net/minecraft/item/ItemMap.java
Normal file
@@ -0,0 +1,507 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Multisets;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.BlockStone;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemMap extends ItemMapBase
|
||||
{
|
||||
protected ItemMap()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public static ItemStack setupNewMap(World worldIn, double worldX, double worldZ, byte scale, boolean trackingPosition, boolean unlimitedTracking)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(Items.FILLED_MAP, 1, worldIn.getUniqueDataId("map"));
|
||||
String s = "map_" + itemstack.getMetadata();
|
||||
MapData mapdata = new MapData(s);
|
||||
worldIn.setData(s, mapdata);
|
||||
mapdata.scale = scale;
|
||||
mapdata.calculateMapCenter(worldX, worldZ, mapdata.scale);
|
||||
mapdata.dimension = worldIn.provider.getDimension();
|
||||
mapdata.trackingPosition = trackingPosition;
|
||||
mapdata.unlimitedTracking = unlimitedTracking;
|
||||
mapdata.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static MapData loadMapData(int mapId, World worldIn)
|
||||
{
|
||||
String s = "map_" + mapId;
|
||||
return (MapData)worldIn.loadData(MapData.class, s);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapData getMapData(ItemStack stack, World worldIn)
|
||||
{
|
||||
String s = "map_" + stack.getMetadata();
|
||||
MapData mapdata = (MapData)worldIn.loadData(MapData.class, s);
|
||||
|
||||
if (mapdata == null && !worldIn.isRemote)
|
||||
{
|
||||
stack.setItemDamage(worldIn.getUniqueDataId("map"));
|
||||
s = "map_" + stack.getMetadata();
|
||||
mapdata = new MapData(s);
|
||||
mapdata.scale = 3;
|
||||
mapdata.calculateMapCenter((double)worldIn.getWorldInfo().getSpawnX(), (double)worldIn.getWorldInfo().getSpawnZ(), mapdata.scale);
|
||||
mapdata.dimension = worldIn.provider.getDimension();
|
||||
mapdata.markDirty();
|
||||
worldIn.setData(s, mapdata);
|
||||
}
|
||||
|
||||
return mapdata;
|
||||
}
|
||||
|
||||
public void updateMapData(World worldIn, Entity viewer, MapData data)
|
||||
{
|
||||
if (worldIn.provider.getDimension() == data.dimension && viewer instanceof EntityPlayer)
|
||||
{
|
||||
int i = 1 << data.scale;
|
||||
int j = data.xCenter;
|
||||
int k = data.zCenter;
|
||||
int l = MathHelper.floor(viewer.posX - (double)j) / i + 64;
|
||||
int i1 = MathHelper.floor(viewer.posZ - (double)k) / i + 64;
|
||||
int j1 = 128 / i;
|
||||
|
||||
if (worldIn.provider.isNether())
|
||||
{
|
||||
j1 /= 2;
|
||||
}
|
||||
|
||||
MapData.MapInfo mapdata$mapinfo = data.getMapInfo((EntityPlayer)viewer);
|
||||
++mapdata$mapinfo.step;
|
||||
boolean flag = false;
|
||||
|
||||
for (int k1 = l - j1 + 1; k1 < l + j1; ++k1)
|
||||
{
|
||||
if ((k1 & 15) == (mapdata$mapinfo.step & 15) || flag)
|
||||
{
|
||||
flag = false;
|
||||
double d0 = 0.0D;
|
||||
|
||||
for (int l1 = i1 - j1 - 1; l1 < i1 + j1; ++l1)
|
||||
{
|
||||
if (k1 >= 0 && l1 >= -1 && k1 < 128 && l1 < 128)
|
||||
{
|
||||
int i2 = k1 - l;
|
||||
int j2 = l1 - i1;
|
||||
boolean flag1 = i2 * i2 + j2 * j2 > (j1 - 2) * (j1 - 2);
|
||||
int k2 = (j / i + k1 - 64) * i;
|
||||
int l2 = (k / i + l1 - 64) * i;
|
||||
Multiset<MapColor> multiset = HashMultiset.<MapColor>create();
|
||||
Chunk chunk = worldIn.getChunkFromBlockCoords(new BlockPos(k2, 0, l2));
|
||||
|
||||
if (!chunk.isEmpty())
|
||||
{
|
||||
int i3 = k2 & 15;
|
||||
int j3 = l2 & 15;
|
||||
int k3 = 0;
|
||||
double d1 = 0.0D;
|
||||
|
||||
if (worldIn.provider.isNether())
|
||||
{
|
||||
int l3 = k2 + l2 * 231871;
|
||||
l3 = l3 * l3 * 31287121 + l3 * 11;
|
||||
|
||||
if ((l3 >> 20 & 1) == 0)
|
||||
{
|
||||
multiset.add(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT).getMapColor(worldIn, BlockPos.ORIGIN), 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
multiset.add(Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.STONE).getMapColor(worldIn, BlockPos.ORIGIN), 100);
|
||||
}
|
||||
|
||||
d1 = 100.0D;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
||||
|
||||
for (int i4 = 0; i4 < i; ++i4)
|
||||
{
|
||||
for (int j4 = 0; j4 < i; ++j4)
|
||||
{
|
||||
int k4 = chunk.getHeightValue(i4 + i3, j4 + j3) + 1;
|
||||
IBlockState iblockstate = Blocks.AIR.getDefaultState();
|
||||
|
||||
if (k4 <= 1)
|
||||
{
|
||||
iblockstate = Blocks.BEDROCK.getDefaultState();
|
||||
}
|
||||
else
|
||||
{
|
||||
label175:
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
--k4;
|
||||
iblockstate = chunk.getBlockState(i4 + i3, k4, j4 + j3);
|
||||
blockpos$mutableblockpos.setPos((chunk.x << 4) + i4 + i3, k4, (chunk.z << 4) + j4 + j3);
|
||||
|
||||
if (iblockstate.getMapColor(worldIn, blockpos$mutableblockpos) != MapColor.AIR || k4 <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (k4 > 0 && iblockstate.getMaterial().isLiquid())
|
||||
{
|
||||
int l4 = k4 - 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
IBlockState iblockstate1 = chunk.getBlockState(i4 + i3, l4--, j4 + j3);
|
||||
++k3;
|
||||
|
||||
if (l4 <= 0 || !iblockstate1.getMaterial().isLiquid())
|
||||
{
|
||||
break label175;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d1 += (double)k4 / (double)(i * i);
|
||||
multiset.add(iblockstate.getMapColor(worldIn, blockpos$mutableblockpos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
k3 = k3 / (i * i);
|
||||
double d2 = (d1 - d0) * 4.0D / (double)(i + 4) + ((double)(k1 + l1 & 1) - 0.5D) * 0.4D;
|
||||
int i5 = 1;
|
||||
|
||||
if (d2 > 0.6D)
|
||||
{
|
||||
i5 = 2;
|
||||
}
|
||||
|
||||
if (d2 < -0.6D)
|
||||
{
|
||||
i5 = 0;
|
||||
}
|
||||
|
||||
MapColor mapcolor = (MapColor)Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MapColor.AIR);
|
||||
|
||||
if (mapcolor == MapColor.WATER)
|
||||
{
|
||||
d2 = (double)k3 * 0.1D + (double)(k1 + l1 & 1) * 0.2D;
|
||||
i5 = 1;
|
||||
|
||||
if (d2 < 0.5D)
|
||||
{
|
||||
i5 = 2;
|
||||
}
|
||||
|
||||
if (d2 > 0.9D)
|
||||
{
|
||||
i5 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
d0 = d1;
|
||||
|
||||
if (l1 >= 0 && i2 * i2 + j2 * j2 < j1 * j1 && (!flag1 || (k1 + l1 & 1) != 0))
|
||||
{
|
||||
byte b0 = data.colors[k1 + l1 * 128];
|
||||
byte b1 = (byte)(mapcolor.colorIndex * 4 + i5);
|
||||
|
||||
if (b0 != b1)
|
||||
{
|
||||
data.colors[k1 + l1 * 128] = b1;
|
||||
data.updateMapData(k1, l1);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws ambiguous landmasses representing unexplored terrain onto a treasure map
|
||||
*/
|
||||
public static void renderBiomePreviewMap(World worldIn, ItemStack map)
|
||||
{
|
||||
if (map.getItem() instanceof ItemMap)
|
||||
{
|
||||
MapData mapdata = ((ItemMap) map.getItem()).getMapData(map, worldIn);
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
if (worldIn.provider.getDimension() == mapdata.dimension)
|
||||
{
|
||||
int i = 1 << mapdata.scale;
|
||||
int j = mapdata.xCenter;
|
||||
int k = mapdata.zCenter;
|
||||
Biome[] abiome = worldIn.getBiomeProvider().getBiomes((Biome[])null, (j / i - 64) * i, (k / i - 64) * i, 128 * i, 128 * i, false);
|
||||
|
||||
for (int l = 0; l < 128; ++l)
|
||||
{
|
||||
for (int i1 = 0; i1 < 128; ++i1)
|
||||
{
|
||||
int j1 = l * i;
|
||||
int k1 = i1 * i;
|
||||
Biome biome = abiome[j1 + k1 * 128 * i];
|
||||
MapColor mapcolor = MapColor.AIR;
|
||||
int l1 = 3;
|
||||
int i2 = 8;
|
||||
|
||||
if (l > 0 && i1 > 0 && l < 127 && i1 < 127)
|
||||
{
|
||||
if (abiome[(l - 1) * i + (i1 - 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[(l - 1) * i + (i1 + 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[(l - 1) * i + i1 * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[(l + 1) * i + (i1 - 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[(l + 1) * i + (i1 + 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[(l + 1) * i + i1 * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[l * i + (i1 - 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (abiome[l * i + (i1 + 1) * i * 128 * i].getBaseHeight() >= 0.0F)
|
||||
{
|
||||
--i2;
|
||||
}
|
||||
|
||||
if (biome.getBaseHeight() < 0.0F)
|
||||
{
|
||||
mapcolor = MapColor.ADOBE;
|
||||
|
||||
if (i2 > 7 && i1 % 2 == 0)
|
||||
{
|
||||
l1 = (l + (int)(MathHelper.sin((float)i1 + 0.0F) * 7.0F)) / 8 % 5;
|
||||
|
||||
if (l1 == 3)
|
||||
{
|
||||
l1 = 1;
|
||||
}
|
||||
else if (l1 == 4)
|
||||
{
|
||||
l1 = 0;
|
||||
}
|
||||
}
|
||||
else if (i2 > 7)
|
||||
{
|
||||
mapcolor = MapColor.AIR;
|
||||
}
|
||||
else if (i2 > 5)
|
||||
{
|
||||
l1 = 1;
|
||||
}
|
||||
else if (i2 > 3)
|
||||
{
|
||||
l1 = 0;
|
||||
}
|
||||
else if (i2 > 1)
|
||||
{
|
||||
l1 = 0;
|
||||
}
|
||||
}
|
||||
else if (i2 > 0)
|
||||
{
|
||||
mapcolor = MapColor.BROWN;
|
||||
|
||||
if (i2 > 3)
|
||||
{
|
||||
l1 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
l1 = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapcolor != MapColor.AIR)
|
||||
{
|
||||
mapdata.colors[l + i1 * 128] = (byte)(mapcolor.colorIndex * 4 + l1);
|
||||
mapdata.updateMapData(l, i1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
|
||||
* update it's contents.
|
||||
*/
|
||||
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
MapData mapdata = this.getMapData(stack, worldIn);
|
||||
|
||||
if (entityIn instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityplayer = (EntityPlayer)entityIn;
|
||||
mapdata.updateVisiblePlayers(entityplayer, stack);
|
||||
}
|
||||
|
||||
if (isSelected || entityIn instanceof EntityPlayer && ((EntityPlayer)entityIn).getHeldItemOffhand() == stack)
|
||||
{
|
||||
this.updateMapData(worldIn, entityIn, mapdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Packet<?> createMapDataPacket(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
return this.getMapData(stack, worldIn).getMapPacket(stack, worldIn, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when item is crafted/smelted. Used only by maps so far.
|
||||
*/
|
||||
public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
if (nbttagcompound.hasKey("map_scale_direction", 99))
|
||||
{
|
||||
scaleMap(stack, worldIn, nbttagcompound.getInteger("map_scale_direction"));
|
||||
nbttagcompound.removeTag("map_scale_direction");
|
||||
}
|
||||
else if (nbttagcompound.getBoolean("map_tracking_position"))
|
||||
{
|
||||
enableMapTracking(stack, worldIn);
|
||||
nbttagcompound.removeTag("map_tracking_position");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void scaleMap(ItemStack p_185063_0_, World p_185063_1_, int p_185063_2_)
|
||||
{
|
||||
MapData mapdata = Items.FILLED_MAP.getMapData(p_185063_0_, p_185063_1_);
|
||||
p_185063_0_.setItemDamage(p_185063_1_.getUniqueDataId("map"));
|
||||
MapData mapdata1 = new MapData("map_" + p_185063_0_.getMetadata());
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
mapdata1.scale = (byte)MathHelper.clamp(mapdata.scale + p_185063_2_, 0, 4);
|
||||
mapdata1.trackingPosition = mapdata.trackingPosition;
|
||||
mapdata1.calculateMapCenter((double)mapdata.xCenter, (double)mapdata.zCenter, mapdata1.scale);
|
||||
mapdata1.dimension = mapdata.dimension;
|
||||
mapdata1.markDirty();
|
||||
p_185063_1_.setData("map_" + p_185063_0_.getMetadata(), mapdata1);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void enableMapTracking(ItemStack p_185064_0_, World p_185064_1_)
|
||||
{
|
||||
MapData mapdata = Items.FILLED_MAP.getMapData(p_185064_0_, p_185064_1_);
|
||||
p_185064_0_.setItemDamage(p_185064_1_.getUniqueDataId("map"));
|
||||
MapData mapdata1 = new MapData("map_" + p_185064_0_.getMetadata());
|
||||
mapdata1.trackingPosition = true;
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
mapdata1.xCenter = mapdata.xCenter;
|
||||
mapdata1.zCenter = mapdata.zCenter;
|
||||
mapdata1.scale = mapdata.scale;
|
||||
mapdata1.dimension = mapdata.dimension;
|
||||
mapdata1.markDirty();
|
||||
p_185064_1_.setData("map_" + p_185064_0_.getMetadata(), mapdata1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
if (flagIn.isAdvanced())
|
||||
{
|
||||
MapData mapdata = worldIn == null ? null : this.getMapData(stack, worldIn);
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
tooltip.add(I18n.translateToLocalFormatted("filled_map.scale", 1 << mapdata.scale));
|
||||
tooltip.add(I18n.translateToLocalFormatted("filled_map.level", mapdata.scale, Integer.valueOf(4)));
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip.add(I18n.translateToLocal("filled_map.unknown"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int getColor(ItemStack p_190907_0_)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = p_190907_0_.getSubCompound("display");
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("MapColor", 99))
|
||||
{
|
||||
int i = nbttagcompound.getInteger("MapColor");
|
||||
return -16777216 | i & 16777215;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -12173266;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemMapBase extends Item
|
||||
{
|
||||
/**
|
||||
* false for all Items except sub-classes of ItemMapBase
|
||||
*/
|
||||
public boolean isMap()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Packet<?> createMapDataPacket(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockRailBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemMinecart extends Item
|
||||
{
|
||||
private static final IBehaviorDispenseItem MINECART_DISPENSER_BEHAVIOR = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem behaviourDefaultDispenseItem = new BehaviorDefaultDispenseItem();
|
||||
/**
|
||||
* Dispense the specified stack, play the dispense sound and spawn particles.
|
||||
*/
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
|
||||
World world = source.getWorld();
|
||||
double d0 = source.getX() + (double)enumfacing.getFrontOffsetX() * 1.125D;
|
||||
double d1 = Math.floor(source.getY()) + (double)enumfacing.getFrontOffsetY();
|
||||
double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ() * 1.125D;
|
||||
BlockPos blockpos = source.getBlockPos().offset(enumfacing);
|
||||
IBlockState iblockstate = world.getBlockState(blockpos);
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? ((BlockRailBase)iblockstate.getBlock()).getRailDirection(world, blockpos, iblockstate, null) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d3;
|
||||
|
||||
if (BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d3 = 0.6D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = 0.1D;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iblockstate.getMaterial() != Material.AIR || !BlockRailBase.isRailBlock(world.getBlockState(blockpos.down())))
|
||||
{
|
||||
return this.behaviourDefaultDispenseItem.dispense(source, stack);
|
||||
}
|
||||
|
||||
IBlockState iblockstate1 = world.getBlockState(blockpos.down());
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection1 = iblockstate1.getBlock() instanceof BlockRailBase ? ((BlockRailBase)iblockstate1.getBlock()).getRailDirection(world, blockpos.down(), iblockstate1, null) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
|
||||
if (enumfacing != EnumFacing.DOWN && blockrailbase$enumraildirection1.isAscending())
|
||||
{
|
||||
d3 = -0.4D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = -0.9D;
|
||||
}
|
||||
}
|
||||
|
||||
EntityMinecart entityminecart = EntityMinecart.create(world, d0, d1 + d3, d2, ((ItemMinecart)stack.getItem()).minecartType);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntity(entityminecart);
|
||||
stack.shrink(1);
|
||||
return stack;
|
||||
}
|
||||
/**
|
||||
* Play the dispense sound from the specified block.
|
||||
*/
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playEvent(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
};
|
||||
private final EntityMinecart.Type minecartType;
|
||||
|
||||
public ItemMinecart(EntityMinecart.Type typeIn)
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.minecartType = typeIn;
|
||||
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, MINECART_DISPENSER_BEHAVIOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (!BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? ((BlockRailBase)iblockstate.getBlock()).getRailDirection(worldIn, pos, iblockstate, null) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d0 = 0.0D;
|
||||
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d0 = 0.5D;
|
||||
}
|
||||
|
||||
EntityMinecart entityminecart = EntityMinecart.create(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.0625D + d0, (double)pos.getZ() + 0.5D, this.minecartType);
|
||||
|
||||
if (itemstack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
worldIn.spawnEntity(entityminecart);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.IEntityLivingData;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.tileentity.MobSpawnerBaseLogic;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMobSpawner;
|
||||
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.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemMonsterPlacer extends Item
|
||||
{
|
||||
public ItemMonsterPlacer()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
String s = ("" + I18n.translateToLocal(this.getUnlocalizedName() + ".name")).trim();
|
||||
String s1 = EntityList.getTranslationName(getNamedIdFrom(stack));
|
||||
|
||||
if (s1 != null)
|
||||
{
|
||||
s = s + " " + I18n.translateToLocal("entity." + s1 + ".name");
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.MOB_SPAWNER)
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntityMobSpawner)
|
||||
{
|
||||
MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic();
|
||||
mobspawnerbaselogic.setEntityId(getNamedIdFrom(itemstack));
|
||||
tileentity.markDirty();
|
||||
worldIn.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
BlockPos blockpos = pos.offset(facing);
|
||||
double d0 = this.getYOffset(worldIn, blockpos);
|
||||
Entity entity = spawnCreature(worldIn, getNamedIdFrom(itemstack), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + d0, (double)blockpos.getZ() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (entity instanceof EntityLivingBase && itemstack.hasDisplayName())
|
||||
{
|
||||
entity.setCustomNameTag(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
applyItemEntityDataToEntity(worldIn, player, itemstack, entity);
|
||||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
protected double getYOffset(World p_190909_1_, BlockPos p_190909_2_)
|
||||
{
|
||||
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(p_190909_2_)).expand(0.0D, -1.0D, 0.0D);
|
||||
List<AxisAlignedBB> list = p_190909_1_.getCollisionBoxes((Entity)null, axisalignedbb);
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
return 0.0D;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d0 = axisalignedbb.minY;
|
||||
|
||||
for (AxisAlignedBB axisalignedbb1 : list)
|
||||
{
|
||||
d0 = Math.max(axisalignedbb1.maxY, d0);
|
||||
}
|
||||
|
||||
return d0 - (double)p_190909_2_.getY();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the data in the EntityTag tag of the given ItemStack to the given Entity.
|
||||
*/
|
||||
public static void applyItemEntityDataToEntity(World entityWorld, @Nullable EntityPlayer player, ItemStack stack, @Nullable Entity targetEntity)
|
||||
{
|
||||
MinecraftServer minecraftserver = entityWorld.getMinecraftServer();
|
||||
|
||||
if (minecraftserver != null && targetEntity != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
|
||||
{
|
||||
if (!entityWorld.isRemote && targetEntity.ignoreItemEntityData() && (player == null || !minecraftserver.getPlayerList().canSendCommands(player.getGameProfile())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = targetEntity.writeToNBT(new NBTTagCompound());
|
||||
UUID uuid = targetEntity.getUniqueID();
|
||||
nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
|
||||
targetEntity.setUniqueId(uuid);
|
||||
targetEntity.readFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);
|
||||
|
||||
if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = raytraceresult.getBlockPos();
|
||||
|
||||
if (!(worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid))
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else if (worldIn.isBlockModifiable(playerIn, blockpos) && playerIn.canPlayerEdit(blockpos, raytraceresult.sideHit, itemstack))
|
||||
{
|
||||
Entity entity = spawnCreature(worldIn, getNamedIdFrom(itemstack), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entity instanceof EntityLivingBase && itemstack.hasDisplayName())
|
||||
{
|
||||
entity.setCustomNameTag(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
applyItemEntityDataToEntity(worldIn, playerIn, itemstack, entity);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns the creature specified by the egg's type in the location specified by the last three parameters.
|
||||
* Parameters: world, entityID, x, y, z.
|
||||
*/
|
||||
@Nullable
|
||||
public static Entity spawnCreature(World worldIn, @Nullable ResourceLocation entityID, double x, double y, double z)
|
||||
{
|
||||
if (entityID != null && EntityList.ENTITY_EGGS.containsKey(entityID))
|
||||
{
|
||||
Entity entity = null;
|
||||
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
entity = EntityList.createEntityByIDFromName(entityID, worldIn);
|
||||
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
EntityLiving entityliving = (EntityLiving)entity;
|
||||
entity.setLocationAndAngles(x, y, z, MathHelper.wrapDegrees(worldIn.rand.nextFloat() * 360.0F), 0.0F);
|
||||
entityliving.rotationYawHead = entityliving.rotationYaw;
|
||||
entityliving.renderYawOffset = entityliving.rotationYaw;
|
||||
entityliving.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityliving)), (IEntityLivingData)null);
|
||||
worldIn.spawnEntity(entity);
|
||||
entityliving.playLivingSound();
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (EntityList.EntityEggInfo entitylist$entityegginfo : EntityList.ENTITY_EGGS.values())
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(this, 1);
|
||||
applyEntityIdToItemStack(itemstack, entitylist$entityegginfo.spawnedID);
|
||||
items.add(itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* APplies the given entity ID to the given ItemStack's NBT data.
|
||||
*/
|
||||
public static void applyEntityIdToItemStack(ItemStack stack, ResourceLocation entityId)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setString("id", entityId.toString());
|
||||
nbttagcompound.setTag("EntityTag", nbttagcompound1);
|
||||
stack.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity type ID from the given itemstack.
|
||||
*
|
||||
* @return The type ID, or {@code null} if there is no valid tag on the item.
|
||||
*/
|
||||
@Nullable
|
||||
public static ResourceLocation getNamedIdFrom(ItemStack stack)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (!nbttagcompound.hasKey("EntityTag", 10))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("EntityTag");
|
||||
|
||||
if (!nbttagcompound1.hasKey("id", 8))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = nbttagcompound1.getString("id");
|
||||
ResourceLocation resourcelocation = new ResourceLocation(s);
|
||||
|
||||
if (!s.contains(":"))
|
||||
{
|
||||
nbttagcompound1.setString("id", resourcelocation.toString());
|
||||
}
|
||||
|
||||
return resourcelocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemMultiTexture extends ItemBlock
|
||||
{
|
||||
protected final Block unused;
|
||||
protected final ItemMultiTexture.Mapper nameFunction;
|
||||
|
||||
public ItemMultiTexture(Block p_i47262_1_, Block p_i47262_2_, ItemMultiTexture.Mapper p_i47262_3_)
|
||||
{
|
||||
super(p_i47262_1_);
|
||||
this.unused = p_i47262_2_;
|
||||
this.nameFunction = p_i47262_3_;
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public ItemMultiTexture(Block block, Block block2, final String[] namesByMeta)
|
||||
{
|
||||
this(block, block2, new ItemMultiTexture.Mapper()
|
||||
{
|
||||
public String apply(ItemStack p_apply_1_)
|
||||
{
|
||||
int i = p_apply_1_.getMetadata();
|
||||
|
||||
if (i < 0 || i >= namesByMeta.length)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
return namesByMeta[i];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + this.nameFunction.apply(stack);
|
||||
}
|
||||
|
||||
public interface Mapper
|
||||
{
|
||||
String apply(ItemStack var1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
public class ItemNameTag extends Item
|
||||
{
|
||||
public ItemNameTag()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
|
||||
{
|
||||
if (stack.hasDisplayName() && !(target instanceof EntityPlayer))
|
||||
{
|
||||
target.setCustomNameTag(stack.getDisplayName());
|
||||
|
||||
if (target instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving)target).enablePersistence();
|
||||
}
|
||||
|
||||
stack.shrink(1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class ItemPickaxe extends ItemTool
|
||||
{
|
||||
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE);
|
||||
|
||||
protected ItemPickaxe(Item.ToolMaterial material)
|
||||
{
|
||||
super(1.0F, -2.8F, material, EFFECTIVE_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(IBlockState blockIn)
|
||||
{
|
||||
Block block = blockIn.getBlock();
|
||||
|
||||
if (block == Blocks.OBSIDIAN)
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() == 3;
|
||||
}
|
||||
else if (block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE)
|
||||
{
|
||||
if (block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK)
|
||||
{
|
||||
if (block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE)
|
||||
{
|
||||
if (block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE)
|
||||
{
|
||||
if (block != Blocks.LAPIS_BLOCK && block != Blocks.LAPIS_ORE)
|
||||
{
|
||||
if (block != Blocks.REDSTONE_ORE && block != Blocks.LIT_REDSTONE_ORE)
|
||||
{
|
||||
Material material = blockIn.getMaterial();
|
||||
|
||||
if (material == Material.ROCK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (material == Material.IRON)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return material == Material.ANVIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel() >= 2;
|
||||
}
|
||||
}
|
||||
|
||||
public float getDestroySpeed(ItemStack stack, IBlockState state)
|
||||
{
|
||||
Material material = state.getMaterial();
|
||||
return material != Material.IRON && material != Material.ANVIL && material != Material.ROCK ? super.getDestroySpeed(stack, state) : this.efficiency;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemPiston extends ItemBlock
|
||||
{
|
||||
public ItemPiston(Block block)
|
||||
{
|
||||
super(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
163
build/tmp/recompileMc/sources/net/minecraft/item/ItemPotion.java
Normal file
163
build/tmp/recompileMc/sources/net/minecraft/item/ItemPotion.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.PotionTypes;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.potion.PotionType;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemPotion extends Item
|
||||
{
|
||||
public ItemPotion()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setCreativeTab(CreativeTabs.BREWING);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getDefaultInstance()
|
||||
{
|
||||
return PotionUtils.addPotionToItemStack(super.getDefaultInstance(), PotionTypes.WATER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
|
||||
{
|
||||
EntityPlayer entityplayer = entityLiving instanceof EntityPlayer ? (EntityPlayer)entityLiving : null;
|
||||
|
||||
if (entityplayer == null || !entityplayer.capabilities.isCreativeMode)
|
||||
{
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
if (entityplayer instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.CONSUME_ITEM.trigger((EntityPlayerMP)entityplayer, stack);
|
||||
}
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack))
|
||||
{
|
||||
if (potioneffect.getPotion().isInstant())
|
||||
{
|
||||
potioneffect.getPotion().affectEntity(entityplayer, entityplayer, entityLiving, potioneffect.getAmplifier(), 1.0D);
|
||||
}
|
||||
else
|
||||
{
|
||||
entityLiving.addPotionEffect(new PotionEffect(potioneffect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entityplayer != null)
|
||||
{
|
||||
entityplayer.addStat(StatList.getObjectUseStats(this));
|
||||
}
|
||||
|
||||
if (entityplayer == null || !entityplayer.capabilities.isCreativeMode)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return new ItemStack(Items.GLASS_BOTTLE);
|
||||
}
|
||||
|
||||
if (entityplayer != null)
|
||||
{
|
||||
entityplayer.inventory.addItemStackToInventory(new ItemStack(Items.GLASS_BOTTLE));
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return EnumAction.DRINK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
playerIn.setActiveHand(handIn);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
return I18n.translateToLocal(PotionUtils.getPotionFromItem(stack).getNamePrefixed("potion.effect."));
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
PotionUtils.addPotionTooltip(stack, tooltip, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (PotionType potiontype : PotionType.REGISTRY)
|
||||
{
|
||||
if (potiontype != PotionTypes.EMPTY)
|
||||
{
|
||||
items.add(PotionUtils.addPotionToItemStack(new ItemStack(this), potiontype));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return super.hasEffect(stack) || !PotionUtils.getEffectsFromStack(stack).isEmpty();
|
||||
}
|
||||
}
|
||||
100
build/tmp/recompileMc/sources/net/minecraft/item/ItemRecord.java
Normal file
100
build/tmp/recompileMc/sources/net/minecraft/item/ItemRecord.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.BlockJukebox;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemRecord extends Item
|
||||
{
|
||||
private static final Map<SoundEvent, ItemRecord> RECORDS = Maps.<SoundEvent, ItemRecord>newHashMap();
|
||||
private final SoundEvent sound;
|
||||
private final String displayName;
|
||||
|
||||
protected ItemRecord(String p_i46742_1_, SoundEvent soundIn)
|
||||
{
|
||||
this.displayName = "item.record." + p_i46742_1_ + ".desc";
|
||||
this.sound = soundIn;
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
RECORDS.put(this.sound, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == Blocks.JUKEBOX && !((Boolean)iblockstate.getValue(BlockJukebox.HAS_RECORD)).booleanValue())
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
((BlockJukebox)Blocks.JUKEBOX).insertRecord(worldIn, pos, iblockstate, itemstack);
|
||||
worldIn.playEvent((EntityPlayer)null, 1010, pos, Item.getIdFromItem(this));
|
||||
itemstack.shrink(1);
|
||||
player.addStat(StatList.RECORD_PLAYED);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
tooltip.add(this.getRecordNameLocal());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getRecordNameLocal()
|
||||
{
|
||||
return I18n.translateToLocal(this.displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an item rarity from EnumRarity
|
||||
*/
|
||||
public EnumRarity getRarity(ItemStack stack)
|
||||
{
|
||||
return EnumRarity.RARE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static ItemRecord getBySound(SoundEvent soundIn)
|
||||
{
|
||||
return RECORDS.get(soundIn);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public SoundEvent getSound()
|
||||
{
|
||||
return this.sound;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemRedstone extends Item
|
||||
{
|
||||
public ItemRedstone()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.REDSTONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
|
||||
BlockPos blockpos = flag ? pos : pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(blockpos, facing, itemstack) && worldIn.mayPlace(worldIn.getBlockState(blockpos).getBlock(), blockpos, false, facing, (Entity)null) && Blocks.REDSTONE_WIRE.canPlaceBlockAt(worldIn, blockpos))
|
||||
{
|
||||
worldIn.setBlockState(blockpos, Blocks.REDSTONE_WIRE.getDefaultState());
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, blockpos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.passive.EntityPig;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
|
||||
public class ItemSaddle extends Item
|
||||
{
|
||||
public ItemSaddle()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.TRANSPORTATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
|
||||
{
|
||||
if (target instanceof EntityPig)
|
||||
{
|
||||
EntityPig entitypig = (EntityPig)target;
|
||||
|
||||
if (!entitypig.getSaddled() && !entitypig.isChild())
|
||||
{
|
||||
entitypig.setSaddled(true);
|
||||
entitypig.world.playSound(playerIn, entitypig.posX, entitypig.posY, entitypig.posZ, SoundEvents.ENTITY_PIG_SADDLE, SoundCategory.NEUTRAL, 0.5F, 1.0F);
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSeedFood extends ItemFood implements net.minecraftforge.common.IPlantable
|
||||
{
|
||||
private final Block crops;
|
||||
/** Block ID of the soil this seed food should be planted on. */
|
||||
private final Block soilId;
|
||||
|
||||
public ItemSeedFood(int healAmount, float saturation, Block crops, Block soil)
|
||||
{
|
||||
super(healAmount, saturation, false);
|
||||
this.crops = crops;
|
||||
this.soilId = soil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
net.minecraft.block.state.IBlockState state = worldIn.getBlockState(pos);
|
||||
if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
worldIn.setBlockState(pos.up(), this.crops.getDefaultState(), 11);
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return net.minecraftforge.common.EnumPlantType.Crop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.block.state.IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return this.crops.getDefaultState();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSeeds extends Item implements net.minecraftforge.common.IPlantable
|
||||
{
|
||||
private final Block crops;
|
||||
/** BlockID of the block the seeds can be planted on. */
|
||||
private final Block soilBlockID;
|
||||
|
||||
public ItemSeeds(Block crops, Block soil)
|
||||
{
|
||||
this.crops = crops;
|
||||
this.soilBlockID = soil;
|
||||
this.setCreativeTab(CreativeTabs.MATERIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
net.minecraft.block.state.IBlockState state = worldIn.getBlockState(pos);
|
||||
if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
worldIn.setBlockState(pos.up(), this.crops.getDefaultState());
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return this.crops == net.minecraft.init.Blocks.NETHER_WART ? net.minecraftforge.common.EnumPlantType.Nether : net.minecraftforge.common.EnumPlantType.Crop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.block.state.IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return this.crops.getDefaultState();
|
||||
}
|
||||
}
|
||||
130
build/tmp/recompileMc/sources/net/minecraft/item/ItemShears.java
Normal file
130
build/tmp/recompileMc/sources/net/minecraft/item/ItemShears.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemShears extends Item
|
||||
{
|
||||
public ItemShears()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(238);
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
|
||||
{
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
stack.damageItem(1, entityLiving);
|
||||
}
|
||||
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof net.minecraftforge.common.IShearable) return true;
|
||||
return state.getMaterial() != Material.LEAVES && block != Blocks.WEB && block != Blocks.TALLGRASS && block != Blocks.VINE && block != Blocks.TRIPWIRE && block != Blocks.WOOL ? super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving) : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(IBlockState blockIn)
|
||||
{
|
||||
Block block = blockIn.getBlock();
|
||||
return block == Blocks.WEB || block == Blocks.REDSTONE_WIRE || block == Blocks.TRIPWIRE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
@Override
|
||||
public boolean itemInteractionForEntity(ItemStack itemstack, net.minecraft.entity.player.EntityPlayer player, EntityLivingBase entity, net.minecraft.util.EnumHand hand)
|
||||
{
|
||||
if (entity.world.isRemote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (entity instanceof net.minecraftforge.common.IShearable)
|
||||
{
|
||||
net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable)entity;
|
||||
BlockPos pos = new BlockPos(entity.posX, entity.posY, entity.posZ);
|
||||
if (target.isShearable(itemstack, entity.world, pos))
|
||||
{
|
||||
java.util.List<ItemStack> drops = target.onSheared(itemstack, entity.world, pos,
|
||||
net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
|
||||
|
||||
java.util.Random rand = new java.util.Random();
|
||||
for(ItemStack stack : drops)
|
||||
{
|
||||
net.minecraft.entity.item.EntityItem ent = entity.entityDropItem(stack, 1.0F);
|
||||
ent.motionY += rand.nextFloat() * 0.05F;
|
||||
ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
|
||||
ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
|
||||
}
|
||||
itemstack.damageItem(1, entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, net.minecraft.entity.player.EntityPlayer player)
|
||||
{
|
||||
if (player.world.isRemote || player.capabilities.isCreativeMode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Block block = player.world.getBlockState(pos).getBlock();
|
||||
if (block instanceof net.minecraftforge.common.IShearable)
|
||||
{
|
||||
net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable)block;
|
||||
if (target.isShearable(itemstack, player.world, pos))
|
||||
{
|
||||
java.util.List<ItemStack> drops = target.onSheared(itemstack, player.world, pos,
|
||||
net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
|
||||
java.util.Random rand = new java.util.Random();
|
||||
|
||||
for (ItemStack stack : drops)
|
||||
{
|
||||
float f = 0.7F;
|
||||
double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
net.minecraft.entity.item.EntityItem entityitem = new net.minecraft.entity.item.EntityItem(player.world, (double)pos.getX() + d, (double)pos.getY() + d1, (double)pos.getZ() + d2, stack);
|
||||
entityitem.setDefaultPickupDelay();
|
||||
player.world.spawnEntity(entityitem);
|
||||
}
|
||||
|
||||
itemstack.damageItem(1, player);
|
||||
player.addStat(net.minecraft.stats.StatList.getBlockStats(block));
|
||||
player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11); //TODO: Move to IShearable implementors in 1.12+
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getDestroySpeed(ItemStack stack, IBlockState state)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block != Blocks.WEB && state.getMaterial() != Material.LEAVES)
|
||||
{
|
||||
return block == Blocks.WOOL ? 5.0F : super.getDestroySpeed(stack, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 15.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntityBanner;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemShield extends Item
|
||||
{
|
||||
public ItemShield()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setCreativeTab(CreativeTabs.COMBAT);
|
||||
this.setMaxDamage(336);
|
||||
this.addPropertyOverride(new ResourceLocation("blocking"), new IItemPropertyGetter()
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
|
||||
{
|
||||
return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
|
||||
}
|
||||
});
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, ItemArmor.DISPENSER_BEHAVIOR);
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (stack.getSubCompound("BlockEntityTag") != null)
|
||||
{
|
||||
EnumDyeColor enumdyecolor = TileEntityBanner.getColor(stack);
|
||||
return I18n.translateToLocal("item.shield." + enumdyecolor.getUnlocalizedName() + ".name");
|
||||
}
|
||||
else
|
||||
{
|
||||
return I18n.translateToLocal("item.shield.name");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
ItemBanner.appendHoverTextFromTileEntityTag(stack, tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return EnumAction.BLOCK;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 72000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
playerIn.setActiveHand(handIn);
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*
|
||||
* @param toRepair the {@code ItemStack} being repaired
|
||||
* @param repair the {@code ItemStack} being used to perform the repair
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return repair.getItem() == Item.getItemFromBlock(Blocks.PLANKS) ? true : super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ItemShulkerBox extends ItemBlock
|
||||
{
|
||||
public ItemShulkerBox(Block blockInstance)
|
||||
{
|
||||
super(blockInstance);
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.BlockStandingSign;
|
||||
import net.minecraft.block.BlockWallSign;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSign extends Item
|
||||
{
|
||||
public ItemSign()
|
||||
{
|
||||
this.maxStackSize = 16;
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
boolean flag = iblockstate.getBlock().isReplaceable(worldIn, pos);
|
||||
|
||||
if (facing != EnumFacing.DOWN && (iblockstate.getMaterial().isSolid() || flag) && (!flag || facing == EnumFacing.UP))
|
||||
{
|
||||
pos = pos.offset(facing);
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && Blocks.STANDING_SIGN.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = flag ? pos.down() : pos;
|
||||
|
||||
if (facing == EnumFacing.UP)
|
||||
{
|
||||
int i = MathHelper.floor((double)((player.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
worldIn.setBlockState(pos, Blocks.STANDING_SIGN.getDefaultState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 11);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setBlockState(pos, Blocks.WALL_SIGN.getDefaultState().withProperty(BlockWallSign.FACING, facing), 11);
|
||||
}
|
||||
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack))
|
||||
{
|
||||
player.openEditSign((TileEntitySign)tileentity);
|
||||
}
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemSimpleFoiled extends Item
|
||||
{
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
218
build/tmp/recompileMc/sources/net/minecraft/item/ItemSkull.java
Normal file
218
build/tmp/recompileMc/sources/net/minecraft/item/ItemSkull.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSkull;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntitySkull;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ItemSkull extends Item
|
||||
{
|
||||
private static final String[] SKULL_TYPES = new String[] {"skeleton", "wither", "zombie", "char", "creeper", "dragon"};
|
||||
|
||||
public ItemSkull()
|
||||
{
|
||||
this.setCreativeTab(CreativeTabs.DECORATIONS);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (facing == EnumFacing.DOWN)
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos))
|
||||
{
|
||||
facing = EnumFacing.UP;
|
||||
pos = pos.down();
|
||||
}
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
boolean flag = block.isReplaceable(worldIn, pos);
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
if (!worldIn.getBlockState(pos).getMaterial().isSolid() && !worldIn.isSideSolid(pos, facing, true))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
pos = pos.offset(facing);
|
||||
}
|
||||
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && Blocks.SKULL.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setBlockState(pos, Blocks.SKULL.getDefaultState().withProperty(BlockSkull.FACING, facing), 11);
|
||||
int i = 0;
|
||||
|
||||
if (facing == EnumFacing.UP)
|
||||
{
|
||||
i = MathHelper.floor((double)(player.rotationYaw * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
}
|
||||
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntitySkull)
|
||||
{
|
||||
TileEntitySkull tileentityskull = (TileEntitySkull)tileentity;
|
||||
|
||||
if (itemstack.getMetadata() == 3)
|
||||
{
|
||||
GameProfile gameprofile = null;
|
||||
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = itemstack.getTagCompound();
|
||||
|
||||
if (nbttagcompound.hasKey("SkullOwner", 10))
|
||||
{
|
||||
gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
|
||||
}
|
||||
else if (nbttagcompound.hasKey("SkullOwner", 8) && !StringUtils.isBlank(nbttagcompound.getString("SkullOwner")))
|
||||
{
|
||||
gameprofile = new GameProfile((UUID)null, nbttagcompound.getString("SkullOwner"));
|
||||
}
|
||||
}
|
||||
|
||||
tileentityskull.setPlayerProfile(gameprofile);
|
||||
}
|
||||
else
|
||||
{
|
||||
tileentityskull.setType(itemstack.getMetadata());
|
||||
}
|
||||
|
||||
tileentityskull.setSkullRotation(i);
|
||||
Blocks.SKULL.checkWitherSpawn(worldIn, pos, tileentityskull);
|
||||
}
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (int i = 0; i < SKULL_TYPES.length; ++i)
|
||||
{
|
||||
items.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
int i = stack.getMetadata();
|
||||
|
||||
if (i < 0 || i >= SKULL_TYPES.length)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
return super.getUnlocalizedName() + "." + SKULL_TYPES[i];
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (stack.getMetadata() == 3 && stack.hasTagCompound())
|
||||
{
|
||||
if (stack.getTagCompound().hasKey("SkullOwner", 8))
|
||||
{
|
||||
return I18n.translateToLocalFormatted("item.skull.player.name", stack.getTagCompound().getString("SkullOwner"));
|
||||
}
|
||||
|
||||
if (stack.getTagCompound().hasKey("SkullOwner", 10))
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("SkullOwner");
|
||||
|
||||
if (nbttagcompound.hasKey("Name", 8))
|
||||
{
|
||||
return I18n.translateToLocalFormatted("item.skull.player.name", nbttagcompound.getString("Name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.getItemStackDisplayName(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an ItemStack with NBT data is read to potentially that ItemStack's NBT data
|
||||
*/
|
||||
public boolean updateItemStackNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.updateItemStackNBT(nbt);
|
||||
|
||||
if (nbt.hasKey("SkullOwner", 8) && !StringUtils.isBlank(nbt.getString("SkullOwner")))
|
||||
{
|
||||
GameProfile gameprofile = new GameProfile((UUID)null, nbt.getString("SkullOwner"));
|
||||
gameprofile = TileEntitySkull.updateGameprofile(gameprofile);
|
||||
nbt.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
154
build/tmp/recompileMc/sources/net/minecraft/item/ItemSlab.java
Normal file
154
build/tmp/recompileMc/sources/net/minecraft/item/ItemSlab.java
Normal file
@@ -0,0 +1,154 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemSlab extends ItemBlock
|
||||
{
|
||||
private final BlockSlab singleSlab;
|
||||
private final BlockSlab doubleSlab;
|
||||
|
||||
public ItemSlab(Block block, BlockSlab singleSlab, BlockSlab doubleSlab)
|
||||
{
|
||||
super(block);
|
||||
this.singleSlab = singleSlab;
|
||||
this.doubleSlab = doubleSlab;
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return this.singleSlab.getUnlocalizedName(stack.getMetadata());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!itemstack.isEmpty() && player.canPlayerEdit(pos.offset(facing), facing, itemstack))
|
||||
{
|
||||
Comparable<?> comparable = this.singleSlab.getTypeForItem(itemstack);
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.singleSlab)
|
||||
{
|
||||
IProperty<?> iproperty = this.singleSlab.getVariantProperty();
|
||||
Comparable<?> comparable1 = iblockstate.getValue(iproperty);
|
||||
BlockSlab.EnumBlockHalf blockslab$enumblockhalf = (BlockSlab.EnumBlockHalf)iblockstate.getValue(BlockSlab.HALF);
|
||||
|
||||
if ((facing == EnumFacing.UP && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable1 == comparable)
|
||||
{
|
||||
IBlockState iblockstate1 = this.makeState(iproperty, comparable1);
|
||||
AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, pos);
|
||||
|
||||
if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, iblockstate1, 11))
|
||||
{
|
||||
SoundType soundtype = this.doubleSlab.getSoundType(iblockstate1, worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
itemstack.shrink(1);
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return this.tryPlace(player, itemstack, worldIn, pos.offset(facing), comparable) ? EnumActionResult.SUCCESS : super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
BlockPos blockpos = pos;
|
||||
IProperty<?> iproperty = this.singleSlab.getVariantProperty();
|
||||
Comparable<?> comparable = this.singleSlab.getTypeForItem(stack);
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.singleSlab)
|
||||
{
|
||||
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
|
||||
|
||||
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && comparable == iblockstate.getValue(iproperty))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
pos = pos.offset(side);
|
||||
IBlockState iblockstate1 = worldIn.getBlockState(pos);
|
||||
return iblockstate1.getBlock() == this.singleSlab && comparable == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack);
|
||||
}
|
||||
|
||||
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos, Object itemSlabType)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.singleSlab)
|
||||
{
|
||||
Comparable<?> comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());
|
||||
|
||||
if (comparable == itemSlabType)
|
||||
{
|
||||
IBlockState iblockstate1 = this.makeState(this.singleSlab.getVariantProperty(), comparable);
|
||||
AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, pos);
|
||||
|
||||
if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, iblockstate1, 11))
|
||||
{
|
||||
SoundType soundtype = this.doubleSlab.getSoundType(iblockstate1, worldIn, pos, player);
|
||||
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
stack.shrink(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected <T extends Comparable<T>> IBlockState makeState(IProperty<T> p_185055_1_, Comparable<?> p_185055_2_)
|
||||
{
|
||||
return this.doubleSlab.getDefaultState().withProperty(p_185055_1_, (T)p_185055_2_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockSnow;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSnow extends ItemBlock
|
||||
{
|
||||
public ItemSnow(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack))
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
BlockPos blockpos = pos;
|
||||
|
||||
if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
blockpos = pos.offset(facing);
|
||||
iblockstate = worldIn.getBlockState(blockpos);
|
||||
block = iblockstate.getBlock();
|
||||
}
|
||||
|
||||
if (block == this.block)
|
||||
{
|
||||
int i = ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue();
|
||||
|
||||
if (i < 8)
|
||||
{
|
||||
IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, Integer.valueOf(i + 1));
|
||||
AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);
|
||||
|
||||
if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10))
|
||||
{
|
||||
SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, pos, player);
|
||||
worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
return (state.getBlock() != net.minecraft.init.Blocks.SNOW_LAYER || ((Integer)state.getValue(BlockSnow.LAYERS)) > 7) ? super.canPlaceBlockOnSide(world, pos, side, player, stack) : true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntitySnowball;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSnowball extends Item
|
||||
{
|
||||
public ItemSnowball()
|
||||
{
|
||||
this.maxStackSize = 16;
|
||||
this.setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!playerIn.capabilities.isCreativeMode)
|
||||
{
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntitySnowball entitysnowball = new EntitySnowball(worldIn, playerIn);
|
||||
entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
|
||||
worldIn.spawnEntity(entitysnowball);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSoup extends ItemFood
|
||||
{
|
||||
public ItemSoup(int healAmount)
|
||||
{
|
||||
super(healAmount, false);
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
|
||||
{
|
||||
super.onItemUseFinish(stack, worldIn, entityLiving);
|
||||
return new ItemStack(Items.BOWL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSpade extends ItemTool
|
||||
{
|
||||
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH, Blocks.CONCRETE_POWDER);
|
||||
|
||||
public ItemSpade(Item.ToolMaterial material)
|
||||
{
|
||||
super(1.5F, -3.0F, material, EFFECTIVE_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(IBlockState blockIn)
|
||||
{
|
||||
Block block = blockIn.getBlock();
|
||||
|
||||
if (block == Blocks.SNOW_LAYER)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return block == Blocks.SNOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (facing != EnumFacing.DOWN && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && block == Blocks.GRASS)
|
||||
{
|
||||
IBlockState iblockstate1 = Blocks.GRASS_PATH.getDefaultState();
|
||||
worldIn.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
worldIn.setBlockState(pos, iblockstate1, 11);
|
||||
itemstack.damageItem(1, player);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.entity.projectile.EntitySpectralArrow;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSpectralArrow extends ItemArrow
|
||||
{
|
||||
public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter)
|
||||
{
|
||||
return new EntitySpectralArrow(worldIn, shooter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityPotion;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemSplashPotion extends ItemPotion
|
||||
{
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
return I18n.translateToLocal(PotionUtils.getPotionFromItem(stack).getNamePrefixed("splash_potion.effect."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
ItemStack itemstack1 = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
|
||||
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
EntityPotion entitypotion = new EntityPotion(worldIn, playerIn, itemstack1);
|
||||
entitypotion.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
|
||||
worldIn.spawnEntity(entitypotion);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
}
|
||||
1432
build/tmp/recompileMc/sources/net/minecraft/item/ItemStack.java
Normal file
1432
build/tmp/recompileMc/sources/net/minecraft/item/ItemStack.java
Normal file
File diff suppressed because it is too large
Load Diff
139
build/tmp/recompileMc/sources/net/minecraft/item/ItemSword.java
Normal file
139
build/tmp/recompileMc/sources/net/minecraft/item/ItemSword.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemSword extends Item
|
||||
{
|
||||
private final float attackDamage;
|
||||
private final Item.ToolMaterial material;
|
||||
|
||||
public ItemSword(Item.ToolMaterial material)
|
||||
{
|
||||
this.material = material;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(material.getMaxUses());
|
||||
this.setCreativeTab(CreativeTabs.COMBAT);
|
||||
this.attackDamage = 3.0F + material.getAttackDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points.
|
||||
*/
|
||||
public float getAttackDamage()
|
||||
{
|
||||
return this.material.getAttackDamage();
|
||||
}
|
||||
|
||||
public float getDestroySpeed(ItemStack stack, IBlockState state)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block == Blocks.WEB)
|
||||
{
|
||||
return 15.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
Material material = state.getMaterial();
|
||||
return material != Material.PLANTS && material != Material.VINE && material != Material.CORAL && material != Material.LEAVES && material != Material.GOURD ? 1.0F : 1.5F;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||
{
|
||||
stack.damageItem(1, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
|
||||
{
|
||||
if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
|
||||
{
|
||||
stack.damageItem(2, entityLiving);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(IBlockState blockIn)
|
||||
{
|
||||
return blockIn.getBlock() == Blocks.WEB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.material.getEnchantability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name for this tool's material.
|
||||
*/
|
||||
public String getToolMaterialName()
|
||||
{
|
||||
return this.material.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*
|
||||
* @param toRepair the {@code ItemStack} being repaired
|
||||
* @param repair the {@code ItemStack} being used to perform the repair
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
ItemStack mat = this.material.getRepairItemStack();
|
||||
if (!mat.isEmpty() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, repair, false)) return true;
|
||||
return super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
|
||||
*/
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
||||
{
|
||||
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
||||
|
||||
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
|
||||
{
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)this.attackDamage, 0));
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
|
||||
}
|
||||
|
||||
return multimap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.init.PotionTypes;
|
||||
import net.minecraft.potion.PotionType;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemTippedArrow extends ItemArrow
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getDefaultInstance()
|
||||
{
|
||||
return PotionUtils.addPotionToItemStack(super.getDefaultInstance(), PotionTypes.POISON);
|
||||
}
|
||||
|
||||
public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter)
|
||||
{
|
||||
EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, shooter);
|
||||
entitytippedarrow.setPotionEffect(stack);
|
||||
return entitytippedarrow;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
for (PotionType potiontype : PotionType.REGISTRY)
|
||||
{
|
||||
if (!potiontype.getEffects().isEmpty())
|
||||
{
|
||||
items.add(PotionUtils.addPotionToItemStack(new ItemStack(this), potiontype));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
PotionUtils.addPotionTooltip(stack, tooltip, 0.125F);
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
return I18n.translateToLocal(PotionUtils.getPotionFromItem(stack).getNamePrefixed("tipped_arrow.effect."));
|
||||
}
|
||||
}
|
||||
167
build/tmp/recompileMc/sources/net/minecraft/item/ItemTool.java
Normal file
167
build/tmp/recompileMc/sources/net/minecraft/item/ItemTool.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemTool extends Item
|
||||
{
|
||||
private final Set<Block> effectiveBlocks;
|
||||
protected float efficiency;
|
||||
/** Damage versus entities. */
|
||||
protected float attackDamage;
|
||||
protected float attackSpeed;
|
||||
/** The material this tool is made from. */
|
||||
protected Item.ToolMaterial toolMaterial;
|
||||
|
||||
protected ItemTool(float attackDamageIn, float attackSpeedIn, Item.ToolMaterial materialIn, Set<Block> effectiveBlocksIn)
|
||||
{
|
||||
this.efficiency = 4.0F;
|
||||
this.toolMaterial = materialIn;
|
||||
this.effectiveBlocks = effectiveBlocksIn;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(materialIn.getMaxUses());
|
||||
this.efficiency = materialIn.getEfficiency();
|
||||
this.attackDamage = attackDamageIn + materialIn.getAttackDamage();
|
||||
this.attackSpeed = attackSpeedIn;
|
||||
this.setCreativeTab(CreativeTabs.TOOLS);
|
||||
if (this instanceof ItemPickaxe)
|
||||
{
|
||||
toolClass = "pickaxe";
|
||||
}
|
||||
else if (this instanceof ItemAxe)
|
||||
{
|
||||
toolClass = "axe";
|
||||
}
|
||||
else if (this instanceof ItemSpade)
|
||||
{
|
||||
toolClass = "shovel";
|
||||
}
|
||||
}
|
||||
|
||||
protected ItemTool(Item.ToolMaterial materialIn, Set<Block> effectiveBlocksIn)
|
||||
{
|
||||
this(0.0F, 0.0F, materialIn, effectiveBlocksIn);
|
||||
}
|
||||
|
||||
public float getDestroySpeed(ItemStack stack, IBlockState state)
|
||||
{
|
||||
for (String type : getToolClasses(stack))
|
||||
{
|
||||
if (state.getBlock().isToolEffective(type, state))
|
||||
return efficiency;
|
||||
}
|
||||
return this.effectiveBlocks.contains(state.getBlock()) ? this.efficiency : 1.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||
{
|
||||
stack.damageItem(2, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
|
||||
{
|
||||
if (!worldIn.isRemote && (double)state.getBlockHardness(worldIn, pos) != 0.0D)
|
||||
{
|
||||
stack.damageItem(1, entityLiving);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns True is the item is renderer in full 3D when hold.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isFull3D()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.toolMaterial.getEnchantability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name for this tool's material.
|
||||
*/
|
||||
public String getToolMaterialName()
|
||||
{
|
||||
return this.toolMaterial.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*
|
||||
* @param toRepair the {@code ItemStack} being repaired
|
||||
* @param repair the {@code ItemStack} being used to perform the repair
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
ItemStack mat = this.toolMaterial.getRepairItemStack();
|
||||
if (!mat.isEmpty() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, repair, false)) return true;
|
||||
return super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
|
||||
*/
|
||||
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
||||
{
|
||||
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
||||
|
||||
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
|
||||
{
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Tool modifier", (double)this.attackDamage, 0));
|
||||
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", (double)this.attackSpeed, 0));
|
||||
}
|
||||
|
||||
return multimap;
|
||||
}
|
||||
|
||||
/*===================================== FORGE START =================================*/
|
||||
@javax.annotation.Nullable
|
||||
private String toolClass;
|
||||
@Override
|
||||
public int getHarvestLevel(ItemStack stack, String toolClass, @javax.annotation.Nullable net.minecraft.entity.player.EntityPlayer player, @javax.annotation.Nullable IBlockState blockState)
|
||||
{
|
||||
int level = super.getHarvestLevel(stack, toolClass, player, blockState);
|
||||
if (level == -1 && toolClass.equals(this.toolClass))
|
||||
{
|
||||
return this.toolMaterial.getHarvestLevel();
|
||||
}
|
||||
else
|
||||
{
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack)
|
||||
{
|
||||
return toolClass != null ? com.google.common.collect.ImmutableSet.of(toolClass) : super.getToolClasses(stack);
|
||||
}
|
||||
/*===================================== FORGE END =================================*/
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemWritableBook extends Item
|
||||
{
|
||||
public ItemWritableBook()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
playerIn.openBook(itemstack, handIn);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method returns true if the book's NBT Tag List "pages" is valid
|
||||
*/
|
||||
public static boolean isNBTValid(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!nbt.hasKey("pages", 9))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagList nbttaglist = nbt.getTagList("pages", 8);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
String s = nbttaglist.getStringTagAt(i);
|
||||
|
||||
if (s.length() > 32767)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package net.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.network.play.server.SPacketSetSlot;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentUtils;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemWrittenBook extends Item
|
||||
{
|
||||
public ItemWrittenBook()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
public static boolean validBookTagContents(NBTTagCompound nbt)
|
||||
{
|
||||
if (!ItemWritableBook.isNBTValid(nbt))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!nbt.hasKey("title", 8))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = nbt.getString("title");
|
||||
return s != null && s.length() <= 32 ? nbt.hasKey("author", 8) : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generation of the book (how many times it has been cloned)
|
||||
*/
|
||||
public static int getGeneration(ItemStack book)
|
||||
{
|
||||
return book.getTagCompound().getInteger("generation");
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
String s = nbttagcompound.getString("title");
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(s))
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getItemStackDisplayName(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
String s = nbttagcompound.getString("author");
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(s))
|
||||
{
|
||||
tooltip.add(TextFormatting.GRAY + I18n.translateToLocalFormatted("book.byAuthor", s));
|
||||
}
|
||||
|
||||
tooltip.add(TextFormatting.GRAY + I18n.translateToLocal("book.generation." + nbttagcompound.getInteger("generation")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the equipped item is right clicked.
|
||||
*/
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = playerIn.getHeldItem(handIn);
|
||||
|
||||
if (!worldIn.isRemote)
|
||||
{
|
||||
this.resolveContents(itemstack, playerIn);
|
||||
}
|
||||
|
||||
playerIn.openBook(itemstack, handIn);
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
|
||||
}
|
||||
|
||||
private void resolveContents(ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
if (stack.getTagCompound() != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (!nbttagcompound.getBoolean("resolved"))
|
||||
{
|
||||
nbttagcompound.setBoolean("resolved", true);
|
||||
|
||||
if (validBookTagContents(nbttagcompound))
|
||||
{
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("pages", 8);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
String s = nbttaglist.getStringTagAt(i);
|
||||
ITextComponent itextcomponent;
|
||||
|
||||
try
|
||||
{
|
||||
itextcomponent = ITextComponent.Serializer.fromJsonLenient(s);
|
||||
itextcomponent = TextComponentUtils.processComponent(player, itextcomponent, player);
|
||||
}
|
||||
catch (Exception var9)
|
||||
{
|
||||
itextcomponent = new TextComponentString(s);
|
||||
}
|
||||
|
||||
nbttaglist.set(i, new NBTTagString(ITextComponent.Serializer.componentToJson(itextcomponent)));
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("pages", nbttaglist);
|
||||
|
||||
if (player instanceof EntityPlayerMP && player.getHeldItemMainhand() == stack)
|
||||
{
|
||||
Slot slot = player.openContainer.getSlotFromInventory(player.inventory, player.inventory.currentItem);
|
||||
((EntityPlayerMP)player).connection.sendPacket(new SPacketSetSlot(0, slot.slotNumber, stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this item has an enchantment glint. By default, this returns
|
||||
* <code>stack.isItemEnchanted()</code>, but other items can override it (for instance, written books always return
|
||||
* true).
|
||||
*
|
||||
* Note that if you override this method, you generally want to also call the super version (on {@link Item}) to get
|
||||
* the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.RegistryNamespaced;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class CraftingManager
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static int nextAvailableId;
|
||||
public static final RegistryNamespaced<ResourceLocation, IRecipe> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(IRecipe.class);
|
||||
|
||||
public static boolean init()
|
||||
{
|
||||
try
|
||||
{
|
||||
register("armordye", new RecipesArmorDyes());
|
||||
register("bookcloning", new RecipeBookCloning());
|
||||
register("mapcloning", new RecipesMapCloning());
|
||||
register("mapextending", new RecipesMapExtending());
|
||||
register("fireworks", new RecipeFireworks());
|
||||
register("repairitem", new RecipeRepairItem());
|
||||
register("tippedarrow", new RecipeTippedArrow());
|
||||
register("bannerduplicate", new RecipesBanners.RecipeDuplicatePattern());
|
||||
register("banneraddpattern", new RecipesBanners.RecipeAddPattern());
|
||||
register("shielddecoration", new ShieldRecipes.Decoration());
|
||||
register("shulkerboxcoloring", new ShulkerBoxRecipes.ShulkerBoxColoring());
|
||||
return parseJsonRecipes();
|
||||
}
|
||||
catch (Throwable var1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean parseJsonRecipes()
|
||||
{
|
||||
FileSystem filesystem = null;
|
||||
Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
boolean flag1;
|
||||
|
||||
try
|
||||
{
|
||||
URL url = CraftingManager.class.getResource("/assets/.mcassetsroot");
|
||||
|
||||
if (url != null)
|
||||
{
|
||||
URI uri = url.toURI();
|
||||
Path path;
|
||||
|
||||
if ("file".equals(uri.getScheme()))
|
||||
{
|
||||
path = Paths.get(CraftingManager.class.getResource("/assets/minecraft/recipes").toURI());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!"jar".equals(uri.getScheme()))
|
||||
{
|
||||
LOGGER.error("Unsupported scheme " + uri + " trying to list all recipes");
|
||||
boolean flag2 = false;
|
||||
return flag2;
|
||||
}
|
||||
|
||||
filesystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
|
||||
path = filesystem.getPath("/assets/minecraft/recipes");
|
||||
}
|
||||
|
||||
Iterator<Path> iterator = Files.walk(path).iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Path path1 = iterator.next();
|
||||
|
||||
if ("json".equals(FilenameUtils.getExtension(path1.toString())))
|
||||
{
|
||||
Path path2 = path.relativize(path1);
|
||||
String s = FilenameUtils.removeExtension(path2.toString()).replaceAll("\\\\", "/");
|
||||
ResourceLocation resourcelocation = new ResourceLocation(s);
|
||||
BufferedReader bufferedreader = null;
|
||||
|
||||
try
|
||||
{
|
||||
boolean flag;
|
||||
|
||||
try
|
||||
{
|
||||
bufferedreader = Files.newBufferedReader(path1);
|
||||
register(s, parseRecipeJson((JsonObject)JsonUtils.fromJson(gson, bufferedreader, JsonObject.class)));
|
||||
}
|
||||
catch (JsonParseException jsonparseexception)
|
||||
{
|
||||
LOGGER.error("Parsing error loading recipe " + resourcelocation, (Throwable)jsonparseexception);
|
||||
flag = false;
|
||||
return flag;
|
||||
}
|
||||
catch (IOException ioexception)
|
||||
{
|
||||
LOGGER.error("Couldn't read recipe " + resourcelocation + " from " + path1, (Throwable)ioexception);
|
||||
flag = false;
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Reader)bufferedreader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGGER.error("Couldn't find .mcassetsroot");
|
||||
flag1 = false;
|
||||
}
|
||||
catch (IOException | URISyntaxException urisyntaxexception)
|
||||
{
|
||||
LOGGER.error("Couldn't get a list of all recipe files", (Throwable)urisyntaxexception);
|
||||
flag1 = false;
|
||||
return flag1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly((Closeable)filesystem);
|
||||
}
|
||||
|
||||
return flag1;
|
||||
}
|
||||
|
||||
private static IRecipe parseRecipeJson(JsonObject p_193376_0_)
|
||||
{
|
||||
String s = JsonUtils.getString(p_193376_0_, "type");
|
||||
|
||||
if ("crafting_shaped".equals(s))
|
||||
{
|
||||
return ShapedRecipes.deserialize(p_193376_0_);
|
||||
}
|
||||
else if ("crafting_shapeless".equals(s))
|
||||
{
|
||||
return ShapelessRecipes.deserialize(p_193376_0_);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid or unsupported recipe type '" + s + "'");
|
||||
}
|
||||
}
|
||||
|
||||
//Forge: Made private use GameData/Registry events!
|
||||
private static void register(String name, IRecipe recipe)
|
||||
{
|
||||
register(new ResourceLocation(name), recipe);
|
||||
}
|
||||
|
||||
//Forge: Made private use GameData/Registry events!
|
||||
private static void register(ResourceLocation name, IRecipe recipe)
|
||||
{
|
||||
if (REGISTRY.containsKey(name))
|
||||
{
|
||||
throw new IllegalStateException("Duplicate recipe ignored with ID " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
REGISTRY.register(nextAvailableId++, name, recipe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an ItemStack that has multiple recipes for it.
|
||||
*/
|
||||
public static ItemStack findMatchingResult(InventoryCrafting craftMatrix, World worldIn)
|
||||
{
|
||||
for (IRecipe irecipe : REGISTRY)
|
||||
{
|
||||
if (irecipe.matches(craftMatrix, worldIn))
|
||||
{
|
||||
return irecipe.getCraftingResult(craftMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IRecipe findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
|
||||
{
|
||||
for (IRecipe irecipe : REGISTRY)
|
||||
{
|
||||
if (irecipe.matches(craftMatrix, worldIn))
|
||||
{
|
||||
return irecipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
|
||||
{
|
||||
for (IRecipe irecipe : REGISTRY)
|
||||
{
|
||||
if (irecipe.matches(craftMatrix, worldIn))
|
||||
{
|
||||
return irecipe.getRemainingItems(craftMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
nonnulllist.set(i, craftMatrix.getStackInSlot(i));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IRecipe getRecipe(ResourceLocation name)
|
||||
{
|
||||
return REGISTRY.getObject(name);
|
||||
}
|
||||
|
||||
@Deprecated //DO NOT USE THIS
|
||||
public static int getIDForRecipe(IRecipe recipe)
|
||||
{
|
||||
return REGISTRY.getIDForObject(recipe);
|
||||
}
|
||||
|
||||
@Deprecated //DO NOT USE THIS
|
||||
@Nullable
|
||||
public static IRecipe getRecipeById(int id)
|
||||
{
|
||||
return REGISTRY.getObjectById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockStoneBrick;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemFishFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class FurnaceRecipes
|
||||
{
|
||||
private static final FurnaceRecipes SMELTING_BASE = new FurnaceRecipes();
|
||||
/** The list of smelting results. */
|
||||
private final Map<ItemStack, ItemStack> smeltingList = Maps.<ItemStack, ItemStack>newHashMap();
|
||||
/** A list which contains how many experience points each recipe output will give. */
|
||||
private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
|
||||
|
||||
/**
|
||||
* Returns an instance of FurnaceRecipes.
|
||||
*/
|
||||
public static FurnaceRecipes instance()
|
||||
{
|
||||
return SMELTING_BASE;
|
||||
}
|
||||
|
||||
private FurnaceRecipes()
|
||||
{
|
||||
this.addSmeltingRecipeForBlock(Blocks.IRON_ORE, new ItemStack(Items.IRON_INGOT), 0.7F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.GOLD_ORE, new ItemStack(Items.GOLD_INGOT), 1.0F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.DIAMOND_ORE, new ItemStack(Items.DIAMOND), 1.0F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.SAND, new ItemStack(Blocks.GLASS), 0.1F);
|
||||
this.addSmelting(Items.PORKCHOP, new ItemStack(Items.COOKED_PORKCHOP), 0.35F);
|
||||
this.addSmelting(Items.BEEF, new ItemStack(Items.COOKED_BEEF), 0.35F);
|
||||
this.addSmelting(Items.CHICKEN, new ItemStack(Items.COOKED_CHICKEN), 0.35F);
|
||||
this.addSmelting(Items.RABBIT, new ItemStack(Items.COOKED_RABBIT), 0.35F);
|
||||
this.addSmelting(Items.MUTTON, new ItemStack(Items.COOKED_MUTTON), 0.35F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.COBBLESTONE, new ItemStack(Blocks.STONE), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STONEBRICK, 1, BlockStoneBrick.DEFAULT_META), new ItemStack(Blocks.STONEBRICK, 1, BlockStoneBrick.CRACKED_META), 0.1F);
|
||||
this.addSmelting(Items.CLAY_BALL, new ItemStack(Items.BRICK), 0.3F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.CLAY, new ItemStack(Blocks.HARDENED_CLAY), 0.35F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.CACTUS, new ItemStack(Items.DYE, 1, EnumDyeColor.GREEN.getDyeDamage()), 0.2F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.LOG, new ItemStack(Items.COAL, 1, 1), 0.15F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.LOG2, new ItemStack(Items.COAL, 1, 1), 0.15F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.EMERALD_ORE, new ItemStack(Items.EMERALD), 1.0F);
|
||||
this.addSmelting(Items.POTATO, new ItemStack(Items.BAKED_POTATO), 0.35F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.NETHERRACK, new ItemStack(Items.NETHERBRICK), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.SPONGE, 1, 1), new ItemStack(Blocks.SPONGE, 1, 0), 0.15F);
|
||||
this.addSmelting(Items.CHORUS_FRUIT, new ItemStack(Items.CHORUS_FRUIT_POPPED), 0.1F);
|
||||
|
||||
for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
|
||||
{
|
||||
if (itemfishfood$fishtype.canCook())
|
||||
{
|
||||
this.addSmeltingRecipe(new ItemStack(Items.FISH, 1, itemfishfood$fishtype.getMetadata()), new ItemStack(Items.COOKED_FISH, 1, itemfishfood$fishtype.getMetadata()), 0.35F);
|
||||
}
|
||||
}
|
||||
|
||||
this.addSmeltingRecipeForBlock(Blocks.COAL_ORE, new ItemStack(Items.COAL), 0.1F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.REDSTONE_ORE, new ItemStack(Items.REDSTONE), 0.7F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.LAPIS_ORE, new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()), 0.2F);
|
||||
this.addSmeltingRecipeForBlock(Blocks.QUARTZ_ORE, new ItemStack(Items.QUARTZ), 0.2F);
|
||||
this.addSmelting(Items.CHAINMAIL_HELMET, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.CHAINMAIL_CHESTPLATE, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.CHAINMAIL_LEGGINGS, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.CHAINMAIL_BOOTS, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_PICKAXE, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_SHOVEL, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_AXE, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_HOE, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_SWORD, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_HELMET, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_CHESTPLATE, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_LEGGINGS, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_BOOTS, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.IRON_HORSE_ARMOR, new ItemStack(Items.IRON_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_PICKAXE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_SHOVEL, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_AXE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_HOE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_SWORD, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_HELMET, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_CHESTPLATE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_LEGGINGS, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_BOOTS, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmelting(Items.GOLDEN_HORSE_ARMOR, new ItemStack(Items.GOLD_NUGGET), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.WHITE.getMetadata()), new ItemStack(Blocks.WHITE_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.ORANGE.getMetadata()), new ItemStack(Blocks.ORANGE_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.MAGENTA.getMetadata()), new ItemStack(Blocks.MAGENTA_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.LIGHT_BLUE.getMetadata()), new ItemStack(Blocks.LIGHT_BLUE_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.YELLOW.getMetadata()), new ItemStack(Blocks.YELLOW_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.LIME.getMetadata()), new ItemStack(Blocks.LIME_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.PINK.getMetadata()), new ItemStack(Blocks.PINK_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.GRAY.getMetadata()), new ItemStack(Blocks.GRAY_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.SILVER.getMetadata()), new ItemStack(Blocks.SILVER_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.CYAN.getMetadata()), new ItemStack(Blocks.CYAN_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.PURPLE.getMetadata()), new ItemStack(Blocks.PURPLE_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BLUE.getMetadata()), new ItemStack(Blocks.BLUE_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BROWN.getMetadata()), new ItemStack(Blocks.BROWN_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.GREEN.getMetadata()), new ItemStack(Blocks.GREEN_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.RED.getMetadata()), new ItemStack(Blocks.RED_GLAZED_TERRACOTTA), 0.1F);
|
||||
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BLACK.getMetadata()), new ItemStack(Blocks.BLACK_GLAZED_TERRACOTTA), 0.1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a smelting recipe, where the input item is an instance of Block.
|
||||
*/
|
||||
public void addSmeltingRecipeForBlock(Block input, ItemStack stack, float experience)
|
||||
{
|
||||
this.addSmelting(Item.getItemFromBlock(input), stack, experience);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a smelting recipe using an Item as the input item.
|
||||
*/
|
||||
public void addSmelting(Item input, ItemStack stack, float experience)
|
||||
{
|
||||
this.addSmeltingRecipe(new ItemStack(input, 1, 32767), stack, experience);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a smelting recipe using an ItemStack as the input for the recipe.
|
||||
*/
|
||||
public void addSmeltingRecipe(ItemStack input, ItemStack stack, float experience)
|
||||
{
|
||||
if (getSmeltingResult(input) != ItemStack.EMPTY) { net.minecraftforge.fml.common.FMLLog.log.info("Ignored smelting recipe with conflicting input: {} = {}", input, stack); return; }
|
||||
this.smeltingList.put(input, stack);
|
||||
this.experienceList.put(stack, Float.valueOf(experience));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smelting result of an item.
|
||||
*/
|
||||
public ItemStack getSmeltingResult(ItemStack stack)
|
||||
{
|
||||
for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
|
||||
{
|
||||
if (this.compareItemStacks(stack, entry.getKey()))
|
||||
{
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two itemstacks to ensure that they are the same. This checks both the item and the metadata of the item.
|
||||
*/
|
||||
private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
|
||||
}
|
||||
|
||||
public Map<ItemStack, ItemStack> getSmeltingList()
|
||||
{
|
||||
return this.smeltingList;
|
||||
}
|
||||
|
||||
public float getSmeltingExperience(ItemStack stack)
|
||||
{
|
||||
float ret = stack.getItem().getSmeltingExperience(stack);
|
||||
if (ret != -1) return ret;
|
||||
|
||||
for (Entry<ItemStack, Float> entry : this.experienceList.entrySet())
|
||||
{
|
||||
if (this.compareItemStacks(stack, entry.getKey()))
|
||||
{
|
||||
return ((Float)entry.getValue()).floatValue();
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IRecipe extends net.minecraftforge.registries.IForgeRegistryEntry<IRecipe>
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
boolean matches(InventoryCrafting inv, World worldIn);
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
ItemStack getCraftingResult(InventoryCrafting inv);
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
boolean canFit(int width, int height);
|
||||
|
||||
ItemStack getRecipeOutput();
|
||||
|
||||
default NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
return net.minecraftforge.common.ForgeHooks.defaultRecipeGetRemainingItems(inv);
|
||||
}
|
||||
|
||||
default NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
return NonNullList.<Ingredient>create();
|
||||
}
|
||||
|
||||
default boolean isDynamic()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
default String getGroup()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntComparators;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.util.RecipeItemHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class Ingredient implements Predicate<ItemStack>
|
||||
{
|
||||
//Because Mojang caches things... we need to invalidate them.. so... here we go..
|
||||
private static final java.util.Set<Ingredient> INSTANCES = java.util.Collections.newSetFromMap(new java.util.WeakHashMap<Ingredient, Boolean>());
|
||||
public static final Ingredient EMPTY = new Ingredient(new ItemStack[0])
|
||||
{
|
||||
public boolean apply(@Nullable ItemStack p_apply_1_)
|
||||
{
|
||||
return p_apply_1_.isEmpty();
|
||||
}
|
||||
};
|
||||
public final ItemStack[] matchingStacks;
|
||||
private final ItemStack[] matchingStacksExploded;
|
||||
private IntList matchingStacksPacked;
|
||||
private final boolean isSimple;
|
||||
|
||||
protected Ingredient(int size)
|
||||
{
|
||||
this(new ItemStack[size]);
|
||||
}
|
||||
|
||||
protected Ingredient(ItemStack... p_i47503_1_)
|
||||
{
|
||||
boolean simple = true;
|
||||
this.matchingStacks = p_i47503_1_;
|
||||
net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
|
||||
for (ItemStack s : p_i47503_1_)
|
||||
{
|
||||
if (s.isEmpty())
|
||||
continue;
|
||||
if (s.getItem().isDamageable())
|
||||
simple = false;
|
||||
if (s.getMetadata() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE)
|
||||
s.getItem().getSubItems(net.minecraft.creativetab.CreativeTabs.SEARCH, lst);
|
||||
else
|
||||
lst.add(s);
|
||||
}
|
||||
this.matchingStacksExploded = lst.toArray(new ItemStack[lst.size()]);
|
||||
this.isSimple = simple && this.matchingStacksExploded.length > 0;
|
||||
Ingredient.INSTANCES.add(this);
|
||||
}
|
||||
|
||||
public ItemStack[] getMatchingStacks()
|
||||
{
|
||||
return this.matchingStacksExploded;
|
||||
}
|
||||
|
||||
public boolean apply(@Nullable ItemStack p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ItemStack itemstack : this.matchingStacks)
|
||||
{
|
||||
if (itemstack.getItem() == p_apply_1_.getItem())
|
||||
{
|
||||
int i = itemstack.getMetadata();
|
||||
|
||||
if (i == 32767 || i == p_apply_1_.getMetadata())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public IntList getValidItemStacksPacked()
|
||||
{
|
||||
if (this.matchingStacksPacked == null)
|
||||
{
|
||||
this.matchingStacksPacked = new IntArrayList(this.matchingStacksExploded.length);
|
||||
|
||||
for (ItemStack itemstack : this.matchingStacksExploded)
|
||||
{
|
||||
this.matchingStacksPacked.add(RecipeItemHelper.pack(itemstack));
|
||||
}
|
||||
|
||||
this.matchingStacksPacked.sort(IntComparators.NATURAL_COMPARATOR);
|
||||
}
|
||||
|
||||
return this.matchingStacksPacked;
|
||||
}
|
||||
|
||||
public static void invalidateAll()
|
||||
{
|
||||
for (Ingredient ing : INSTANCES)
|
||||
if (ing != null)
|
||||
ing.invalidate();
|
||||
}
|
||||
|
||||
protected void invalidate()
|
||||
{
|
||||
this.matchingStacksPacked = null;
|
||||
}
|
||||
|
||||
public static Ingredient fromItem(Item p_193367_0_)
|
||||
{
|
||||
return fromStacks(new ItemStack(p_193367_0_, 1, 32767));
|
||||
}
|
||||
|
||||
public static Ingredient fromItems(Item... items)
|
||||
{
|
||||
ItemStack[] aitemstack = new ItemStack[items.length];
|
||||
|
||||
for (int i = 0; i < items.length; ++i)
|
||||
{
|
||||
aitemstack[i] = new ItemStack(items[i]);
|
||||
}
|
||||
|
||||
return fromStacks(aitemstack);
|
||||
}
|
||||
|
||||
public static Ingredient fromStacks(ItemStack... stacks)
|
||||
{
|
||||
if (stacks.length > 0)
|
||||
{
|
||||
for (ItemStack itemstack : stacks)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return new Ingredient(stacks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
// Merges several vanilla Ingredients together. As a qwerk of how the json is structured, we can't tell if its a single Ingredient type or multiple so we split per item and remerge here.
|
||||
//Only public for internal use, so we can access a private field in here.
|
||||
public static Ingredient merge(java.util.Collection<Ingredient> parts)
|
||||
{
|
||||
net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
|
||||
for (Ingredient part : parts)
|
||||
{
|
||||
for (ItemStack stack : part.matchingStacks)
|
||||
lst.add(stack);
|
||||
}
|
||||
return new Ingredient(lst.toArray(new ItemStack[lst.size()]));
|
||||
}
|
||||
|
||||
public boolean isSimple()
|
||||
{
|
||||
return isSimple || this == EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemWrittenBook;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipeBookCloning extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
int i = 0;
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int j = 0; j < inv.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(j);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() == Items.WRITTEN_BOOK)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemstack1.getItem() != Items.WRITABLE_BOOK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !itemstack.isEmpty() && itemstack.hasTagCompound() && i > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
int i = 0;
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int j = 0; j < inv.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(j);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() == Items.WRITTEN_BOOK)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemstack1.getItem() != Items.WRITABLE_BOOK)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemstack.isEmpty() && itemstack.hasTagCompound() && i >= 1 && ItemWrittenBook.getGeneration(itemstack) < 2)
|
||||
{
|
||||
ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK, i);
|
||||
itemstack2.setTagCompound(itemstack.getTagCompound().copy());
|
||||
itemstack2.getTagCompound().setInteger("generation", ItemWrittenBook.getGeneration(itemstack) + 1);
|
||||
|
||||
if (itemstack.hasDisplayName())
|
||||
{
|
||||
itemstack2.setStackDisplayName(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
return itemstack2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (itemstack.getItem() instanceof ItemWrittenBook)
|
||||
{
|
||||
ItemStack itemstack1 = itemstack.copy();
|
||||
itemstack1.setCount(1);
|
||||
nonnulllist.set(i, itemstack1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width >= 3 && height >= 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipeFireworks extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
private ItemStack resultItem = ItemStack.EMPTY;
|
||||
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
this.resultItem = ItemStack.EMPTY;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
int i1 = 0;
|
||||
int j1 = 0;
|
||||
|
||||
for (int k1 = 0; k1 < inv.getSizeInventory(); ++k1)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(k1);
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
if (itemstack.getItem() == Items.GUNPOWDER)
|
||||
{
|
||||
++j;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.FIREWORK_CHARGE)
|
||||
{
|
||||
++l;
|
||||
}
|
||||
else if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack))
|
||||
{
|
||||
++k;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.PAPER)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.GLOWSTONE_DUST)
|
||||
{
|
||||
++i1;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.DIAMOND)
|
||||
{
|
||||
++i1;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.FIRE_CHARGE)
|
||||
{
|
||||
++j1;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.FEATHER)
|
||||
{
|
||||
++j1;
|
||||
}
|
||||
else if (itemstack.getItem() == Items.GOLD_NUGGET)
|
||||
{
|
||||
++j1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemstack.getItem() != Items.SKULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++j1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i1 = i1 + k + j1;
|
||||
|
||||
if (j <= 3 && i <= 1)
|
||||
{
|
||||
if (j >= 1 && i == 1 && i1 == 0)
|
||||
{
|
||||
this.resultItem = new ItemStack(Items.FIREWORKS, 3);
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
|
||||
if (l > 0)
|
||||
{
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int k2 = 0; k2 < inv.getSizeInventory(); ++k2)
|
||||
{
|
||||
ItemStack itemstack3 = inv.getStackInSlot(k2);
|
||||
|
||||
if (itemstack3.getItem() == Items.FIREWORK_CHARGE && itemstack3.hasTagCompound() && itemstack3.getTagCompound().hasKey("Explosion", 10))
|
||||
{
|
||||
nbttaglist.appendTag(itemstack3.getTagCompound().getCompoundTag("Explosion"));
|
||||
}
|
||||
}
|
||||
|
||||
nbttagcompound1.setTag("Explosions", nbttaglist);
|
||||
}
|
||||
|
||||
nbttagcompound1.setByte("Flight", (byte)j);
|
||||
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
|
||||
nbttagcompound3.setTag("Fireworks", nbttagcompound1);
|
||||
this.resultItem.setTagCompound(nbttagcompound3);
|
||||
return true;
|
||||
}
|
||||
else if (j == 1 && i == 0 && l == 0 && k > 0 && j1 <= 1)
|
||||
{
|
||||
this.resultItem = new ItemStack(Items.FIREWORK_CHARGE);
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
||||
byte b0 = 0;
|
||||
List<Integer> list = Lists.<Integer>newArrayList();
|
||||
|
||||
for (int l1 = 0; l1 < inv.getSizeInventory(); ++l1)
|
||||
{
|
||||
ItemStack itemstack2 = inv.getStackInSlot(l1);
|
||||
|
||||
if (!itemstack2.isEmpty())
|
||||
{
|
||||
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack2))
|
||||
{
|
||||
list.add(Integer.valueOf(ItemDye.DYE_COLORS[net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack2) & 15]));
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.GLOWSTONE_DUST)
|
||||
{
|
||||
nbttagcompound2.setBoolean("Flicker", true);
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.DIAMOND)
|
||||
{
|
||||
nbttagcompound2.setBoolean("Trail", true);
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.FIRE_CHARGE)
|
||||
{
|
||||
b0 = 1;
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.FEATHER)
|
||||
{
|
||||
b0 = 4;
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.GOLD_NUGGET)
|
||||
{
|
||||
b0 = 2;
|
||||
}
|
||||
else if (itemstack2.getItem() == Items.SKULL)
|
||||
{
|
||||
b0 = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] aint1 = new int[list.size()];
|
||||
|
||||
for (int l2 = 0; l2 < aint1.length; ++l2)
|
||||
{
|
||||
aint1[l2] = ((Integer)list.get(l2)).intValue();
|
||||
}
|
||||
|
||||
nbttagcompound2.setIntArray("Colors", aint1);
|
||||
nbttagcompound2.setByte("Type", b0);
|
||||
nbttagcompound.setTag("Explosion", nbttagcompound2);
|
||||
this.resultItem.setTagCompound(nbttagcompound);
|
||||
return true;
|
||||
}
|
||||
else if (j == 0 && i == 0 && l == 1 && k > 0 && k == i1)
|
||||
{
|
||||
List<Integer> list1 = Lists.<Integer>newArrayList();
|
||||
|
||||
for (int i2 = 0; i2 < inv.getSizeInventory(); ++i2)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(i2);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
|
||||
{
|
||||
list1.add(Integer.valueOf(ItemDye.DYE_COLORS[net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack1) & 15]));
|
||||
}
|
||||
else if (itemstack1.getItem() == Items.FIREWORK_CHARGE)
|
||||
{
|
||||
this.resultItem = itemstack1.copy();
|
||||
this.resultItem.setCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] aint = new int[list1.size()];
|
||||
|
||||
for (int j2 = 0; j2 < aint.length; ++j2)
|
||||
{
|
||||
aint[j2] = ((Integer)list1.get(j2)).intValue();
|
||||
}
|
||||
|
||||
if (!this.resultItem.isEmpty() && this.resultItem.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound4 = this.resultItem.getTagCompound().getCompoundTag("Explosion");
|
||||
|
||||
if (nbttagcompound4 == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbttagcompound4.setIntArray("FadeColors", aint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
return this.resultItem.copy();
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return this.resultItem;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width * height >= 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipeRepairItem extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
list.add(itemstack);
|
||||
|
||||
if (list.size() > 1)
|
||||
{
|
||||
ItemStack itemstack1 = list.get(0);
|
||||
|
||||
if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getCount() != 1 || itemstack.getCount() != 1 || !itemstack1.getItem().isRepairable())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list.size() == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
list.add(itemstack);
|
||||
|
||||
if (list.size() > 1)
|
||||
{
|
||||
ItemStack itemstack1 = list.get(0);
|
||||
|
||||
if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getCount() != 1 || itemstack.getCount() != 1 || !itemstack1.getItem().isRepairable())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() == 2)
|
||||
{
|
||||
ItemStack itemstack2 = list.get(0);
|
||||
ItemStack itemstack3 = list.get(1);
|
||||
|
||||
if (itemstack2.getItem() == itemstack3.getItem() && itemstack2.getCount() == 1 && itemstack3.getCount() == 1 && itemstack2.getItem().isRepairable())
|
||||
{
|
||||
// FORGE: Make itemstack sensitive // Item item = itemstack2.getItem();
|
||||
int j = itemstack2.getMaxDamage() - itemstack2.getItemDamage();
|
||||
int k = itemstack2.getMaxDamage() - itemstack3.getItemDamage();
|
||||
int l = j + k + itemstack2.getMaxDamage() * 5 / 100;
|
||||
int i1 = itemstack2.getMaxDamage() - l;
|
||||
|
||||
if (i1 < 0)
|
||||
{
|
||||
i1 = 0;
|
||||
}
|
||||
|
||||
return new ItemStack(itemstack2.getItem(), 1, i1);
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width * height >= 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipeTippedArrow extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
if (inv.getWidth() == 3 && inv.getHeight() == 3)
|
||||
{
|
||||
for (int i = 0; i < inv.getWidth(); ++i)
|
||||
{
|
||||
for (int j = 0; j < inv.getHeight(); ++j)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInRowAndColumn(i, j);
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Item item = itemstack.getItem();
|
||||
|
||||
if (i == 1 && j == 1)
|
||||
{
|
||||
if (item != Items.LINGERING_POTION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (item != Items.ARROW)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInRowAndColumn(1, 1);
|
||||
|
||||
if (itemstack.getItem() != Items.LINGERING_POTION)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack1 = new ItemStack(Items.TIPPED_ARROW, 8);
|
||||
PotionUtils.addPotionToItemStack(itemstack1, PotionUtils.getPotionFromItem(itemstack));
|
||||
PotionUtils.appendEffects(itemstack1, PotionUtils.getFullEffectsFromItem(itemstack));
|
||||
return itemstack1;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
return NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width >= 2 && height >= 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipesArmorDyes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
List<ItemStack> list = Lists.<ItemStack>newArrayList();
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() instanceof ItemArmor)
|
||||
{
|
||||
ItemArmor itemarmor = (ItemArmor)itemstack1.getItem();
|
||||
|
||||
if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || !itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
list.add(itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !itemstack.isEmpty() && !list.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
int[] aint = new int[3];
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
ItemArmor itemarmor = null;
|
||||
|
||||
for (int k = 0; k < inv.getSizeInventory(); ++k)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(k);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() instanceof ItemArmor)
|
||||
{
|
||||
itemarmor = (ItemArmor)itemstack1.getItem();
|
||||
|
||||
if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || !itemstack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
itemstack = itemstack1.copy();
|
||||
itemstack.setCount(1);
|
||||
|
||||
if (itemarmor.hasColor(itemstack1))
|
||||
{
|
||||
int l = itemarmor.getColor(itemstack);
|
||||
float f = (float)(l >> 16 & 255) / 255.0F;
|
||||
float f1 = (float)(l >> 8 & 255) / 255.0F;
|
||||
float f2 = (float)(l & 255) / 255.0F;
|
||||
i = (int)((float)i + Math.max(f, Math.max(f1, f2)) * 255.0F);
|
||||
aint[0] = (int)((float)aint[0] + f * 255.0F);
|
||||
aint[1] = (int)((float)aint[1] + f1 * 255.0F);
|
||||
aint[2] = (int)((float)aint[2] + f2 * 255.0F);
|
||||
++j;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
float[] afloat = net.minecraftforge.oredict.DyeUtils.colorFromStack(itemstack1).get().getColorComponentValues();
|
||||
int l1 = (int)(afloat[0] * 255.0F);
|
||||
int i2 = (int)(afloat[1] * 255.0F);
|
||||
int j2 = (int)(afloat[2] * 255.0F);
|
||||
i += Math.max(l1, Math.max(i2, j2));
|
||||
aint[0] += l1;
|
||||
aint[1] += i2;
|
||||
aint[2] += j2;
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemarmor == null)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i1 = aint[0] / j;
|
||||
int j1 = aint[1] / j;
|
||||
int k1 = aint[2] / j;
|
||||
float f3 = (float)i / (float)j;
|
||||
float f4 = (float)Math.max(i1, Math.max(j1, k1));
|
||||
i1 = (int)((float)i1 * f3 / f4);
|
||||
j1 = (int)((float)j1 * f3 / f4);
|
||||
k1 = (int)((float)k1 * f3 / f4);
|
||||
int k2 = (i1 << 8) + j1;
|
||||
k2 = (k2 << 8) + k1;
|
||||
itemarmor.setColor(itemstack, k2);
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width * height >= 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.ItemBanner;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.BannerPattern;
|
||||
import net.minecraft.tileentity.TileEntityBanner;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipesBanners
|
||||
{
|
||||
public static class RecipeAddPattern extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
boolean flag = false;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (itemstack.getItem() == Items.BANNER)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TileEntityBanner.getPatterns(itemstack) >= 6)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.matchPatterns(inv) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack1.isEmpty() && itemstack1.getItem() == Items.BANNER)
|
||||
{
|
||||
itemstack = itemstack1.copy();
|
||||
itemstack.setCount(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BannerPattern bannerpattern = this.matchPatterns(inv);
|
||||
|
||||
if (bannerpattern != null)
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
for (int j = 0; j < inv.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack2 = inv.getStackInSlot(j);
|
||||
|
||||
int color = net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack2);
|
||||
if (color != -1)
|
||||
{
|
||||
k = color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = itemstack.getOrCreateSubCompound("BlockEntityTag");
|
||||
NBTTagList nbttaglist;
|
||||
|
||||
if (nbttagcompound1.hasKey("Patterns", 9))
|
||||
{
|
||||
nbttaglist = nbttagcompound1.getTagList("Patterns", 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
nbttaglist = new NBTTagList();
|
||||
nbttagcompound1.setTag("Patterns", nbttaglist);
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setString("Pattern", bannerpattern.getHashname());
|
||||
nbttagcompound.setInteger("Color", k);
|
||||
nbttaglist.appendTag(nbttagcompound);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BannerPattern matchPatterns(InventoryCrafting p_190933_1_)
|
||||
{
|
||||
for (BannerPattern bannerpattern : BannerPattern.values())
|
||||
{
|
||||
if (bannerpattern.hasPattern())
|
||||
{
|
||||
boolean flag = true;
|
||||
|
||||
if (bannerpattern.hasPatternItem())
|
||||
{
|
||||
boolean flag1 = false;
|
||||
boolean flag2 = false;
|
||||
|
||||
for (int i = 0; i < p_190933_1_.getSizeInventory() && flag; ++i)
|
||||
{
|
||||
ItemStack itemstack = p_190933_1_.getStackInSlot(i);
|
||||
|
||||
if (!itemstack.isEmpty() && itemstack.getItem() != Items.BANNER)
|
||||
{
|
||||
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack))
|
||||
{
|
||||
if (flag2)
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
flag2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag1 || !itemstack.isItemEqual(bannerpattern.getPatternItem()))
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag1 || !flag2)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
else if (p_190933_1_.getSizeInventory() == bannerpattern.getPatterns().length * bannerpattern.getPatterns()[0].length())
|
||||
{
|
||||
int j = -1;
|
||||
|
||||
for (int k = 0; k < p_190933_1_.getSizeInventory() && flag; ++k)
|
||||
{
|
||||
int l = k / 3;
|
||||
int i1 = k % 3;
|
||||
ItemStack itemstack1 = p_190933_1_.getStackInSlot(k);
|
||||
|
||||
if (!itemstack1.isEmpty() && itemstack1.getItem() != Items.BANNER)
|
||||
{
|
||||
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (j != -1 && j != itemstack1.getMetadata())
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bannerpattern.getPatterns()[l].charAt(i1) == ' ')
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
j = itemstack1.getMetadata();
|
||||
}
|
||||
else if (bannerpattern.getPatterns()[l].charAt(i1) != ' ')
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
return bannerpattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width >= 3 && height >= 3;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RecipeDuplicatePattern extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
ItemStack itemstack1 = ItemStack.EMPTY;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack2 = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack2.isEmpty())
|
||||
{
|
||||
if (itemstack2.getItem() != Items.BANNER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!itemstack.isEmpty() && !itemstack1.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EnumDyeColor enumdyecolor = ItemBanner.getBaseColor(itemstack2);
|
||||
boolean flag = TileEntityBanner.getPatterns(itemstack2) > 0;
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (enumdyecolor != ItemBanner.getBaseColor(itemstack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemstack1 = itemstack2;
|
||||
}
|
||||
else if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (enumdyecolor != ItemBanner.getBaseColor(itemstack1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemstack = itemstack2;
|
||||
}
|
||||
else if (flag)
|
||||
{
|
||||
itemstack = itemstack2;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack1 = itemstack2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !itemstack.isEmpty() && !itemstack1.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack.isEmpty() && TileEntityBanner.getPatterns(itemstack) > 0)
|
||||
{
|
||||
ItemStack itemstack1 = itemstack.copy();
|
||||
itemstack1.setCount(1);
|
||||
return itemstack1;
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
if (itemstack.getItem().hasContainerItem(itemstack))
|
||||
{
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
else if (itemstack.hasTagCompound() && TileEntityBanner.getPatterns(itemstack) > 0)
|
||||
{
|
||||
ItemStack itemstack1 = itemstack.copy();
|
||||
itemstack1.setCount(1);
|
||||
nonnulllist.set(i, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width * height >= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipesMapCloning extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
int i = 0;
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int j = 0; j < inv.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(j);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() == Items.FILLED_MAP)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemstack1.getItem() != Items.MAP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !itemstack.isEmpty() && i > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
int i = 0;
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int j = 0; j < inv.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(j);
|
||||
|
||||
if (!itemstack1.isEmpty())
|
||||
{
|
||||
if (itemstack1.getItem() == Items.FILLED_MAP)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemstack1.getItem() != Items.MAP)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemstack.isEmpty() && i >= 1)
|
||||
{
|
||||
ItemStack itemstack2 = new ItemStack(Items.FILLED_MAP, i + 1, itemstack.getMetadata());
|
||||
|
||||
if (itemstack.hasDisplayName())
|
||||
{
|
||||
itemstack2.setStackDisplayName(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
itemstack2.setTagCompound(itemstack.getTagCompound());
|
||||
}
|
||||
|
||||
return itemstack2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width >= 3 && height >= 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraft.world.storage.MapDecoration;
|
||||
|
||||
public class RecipesMapExtending extends ShapedRecipes
|
||||
{
|
||||
public RecipesMapExtending()
|
||||
{
|
||||
super("", 3, 3, NonNullList.from(Ingredient.EMPTY, Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItem(Items.FILLED_MAP), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER)), new ItemStack(Items.MAP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
if (!super.matches(inv, worldIn))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory() && itemstack.isEmpty(); ++i)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(i);
|
||||
|
||||
if (itemstack1.getItem() == Items.FILLED_MAP)
|
||||
{
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapData mapdata = Items.FILLED_MAP.getMapData(itemstack, worldIn);
|
||||
|
||||
if (mapdata == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.isExplorationMap(mapdata))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mapdata.scale < 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExplorationMap(MapData p_190934_1_)
|
||||
{
|
||||
if (p_190934_1_.mapDecorations != null)
|
||||
{
|
||||
for (MapDecoration mapdecoration : p_190934_1_.mapDecorations.values())
|
||||
{
|
||||
if (mapdecoration.getType() == MapDecoration.Type.MANSION || mapdecoration.getType() == MapDecoration.Type.MONUMENT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory() && itemstack.isEmpty(); ++i)
|
||||
{
|
||||
ItemStack itemstack1 = inv.getStackInSlot(i);
|
||||
|
||||
if (itemstack1.getItem() == Items.FILLED_MAP)
|
||||
{
|
||||
itemstack = itemstack1;
|
||||
}
|
||||
}
|
||||
|
||||
itemstack = itemstack.copy();
|
||||
itemstack.setCount(1);
|
||||
|
||||
if (itemstack.getTagCompound() == null)
|
||||
{
|
||||
itemstack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
itemstack.getTagCompound().setInteger("map_scale_direction", 1);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
public boolean isDynamic()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ShapedRecipes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements net.minecraftforge.common.crafting.IShapedRecipe
|
||||
{
|
||||
/** How many horizontal slots this recipe is wide. */
|
||||
public final int recipeWidth;
|
||||
/** How many vertical slots this recipe uses. */
|
||||
public final int recipeHeight;
|
||||
/** Is a array of ItemStack that composes the recipe. */
|
||||
public final NonNullList<Ingredient> recipeItems;
|
||||
/** Is the ItemStack that you get when craft the recipe. */
|
||||
private final ItemStack recipeOutput;
|
||||
private final String group;
|
||||
|
||||
public ShapedRecipes(String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result)
|
||||
{
|
||||
this.group = group;
|
||||
this.recipeWidth = width;
|
||||
this.recipeHeight = height;
|
||||
this.recipeItems = ingredients;
|
||||
this.recipeOutput = result;
|
||||
}
|
||||
|
||||
public String getGroup()
|
||||
{
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return this.recipeOutput;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
return this.recipeItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width >= this.recipeWidth && height >= this.recipeHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
for (int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i)
|
||||
{
|
||||
for (int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j)
|
||||
{
|
||||
if (this.checkMatch(inv, i, j, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.checkMatch(inv, i, j, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the region of a crafting inventory is match for the recipe.
|
||||
*/
|
||||
private boolean checkMatch(InventoryCrafting p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_)
|
||||
{
|
||||
for (int i = 0; i < p_77573_1_.getWidth(); ++i)
|
||||
{
|
||||
for (int j = 0; j < p_77573_1_.getHeight(); ++j)
|
||||
{
|
||||
int k = i - p_77573_2_;
|
||||
int l = j - p_77573_3_;
|
||||
Ingredient ingredient = Ingredient.EMPTY;
|
||||
|
||||
if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight)
|
||||
{
|
||||
if (p_77573_4_)
|
||||
{
|
||||
ingredient = this.recipeItems.get(this.recipeWidth - k - 1 + l * this.recipeWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
ingredient = this.recipeItems.get(k + l * this.recipeWidth);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ingredient.apply(p_77573_1_.getStackInRowAndColumn(i, j)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
return this.getRecipeOutput().copy();
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return this.recipeWidth;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return this.recipeHeight;
|
||||
}
|
||||
|
||||
public static ShapedRecipes deserialize(JsonObject p_193362_0_)
|
||||
{
|
||||
String s = JsonUtils.getString(p_193362_0_, "group", "");
|
||||
Map<String, Ingredient> map = deserializeKey(JsonUtils.getJsonObject(p_193362_0_, "key"));
|
||||
String[] astring = shrink(patternFromJson(JsonUtils.getJsonArray(p_193362_0_, "pattern")));
|
||||
int i = astring[0].length();
|
||||
int j = astring.length;
|
||||
NonNullList<Ingredient> nonnulllist = deserializeIngredients(astring, map, i, j);
|
||||
ItemStack itemstack = deserializeItem(JsonUtils.getJsonObject(p_193362_0_, "result"), true);
|
||||
return new ShapedRecipes(s, i, j, nonnulllist, itemstack);
|
||||
}
|
||||
|
||||
private static NonNullList<Ingredient> deserializeIngredients(String[] p_192402_0_, Map<String, Ingredient> p_192402_1_, int p_192402_2_, int p_192402_3_)
|
||||
{
|
||||
NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>withSize(p_192402_2_ * p_192402_3_, Ingredient.EMPTY);
|
||||
Set<String> set = Sets.newHashSet(p_192402_1_.keySet());
|
||||
set.remove(" ");
|
||||
|
||||
for (int i = 0; i < p_192402_0_.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < p_192402_0_[i].length(); ++j)
|
||||
{
|
||||
String s = p_192402_0_[i].substring(j, j + 1);
|
||||
Ingredient ingredient = p_192402_1_.get(s);
|
||||
|
||||
if (ingredient == null)
|
||||
{
|
||||
throw new JsonSyntaxException("Pattern references symbol '" + s + "' but it's not defined in the key");
|
||||
}
|
||||
|
||||
set.remove(s);
|
||||
nonnulllist.set(j + p_192402_2_ * i, ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
if (!set.isEmpty())
|
||||
{
|
||||
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + set);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nonnulllist;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static String[] shrink(String... p_194134_0_)
|
||||
{
|
||||
int i = Integer.MAX_VALUE;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
|
||||
for (int i1 = 0; i1 < p_194134_0_.length; ++i1)
|
||||
{
|
||||
String s = p_194134_0_[i1];
|
||||
i = Math.min(i, firstNonSpace(s));
|
||||
int j1 = lastNonSpace(s);
|
||||
j = Math.max(j, j1);
|
||||
|
||||
if (j1 < 0)
|
||||
{
|
||||
if (k == i1)
|
||||
{
|
||||
++k;
|
||||
}
|
||||
|
||||
++l;
|
||||
}
|
||||
else
|
||||
{
|
||||
l = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (p_194134_0_.length == l)
|
||||
{
|
||||
return new String[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] astring = new String[p_194134_0_.length - l - k];
|
||||
|
||||
for (int k1 = 0; k1 < astring.length; ++k1)
|
||||
{
|
||||
astring[k1] = p_194134_0_[k1 + k].substring(i, j + 1);
|
||||
}
|
||||
|
||||
return astring;
|
||||
}
|
||||
}
|
||||
|
||||
private static int firstNonSpace(String str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < str.length() && str.charAt(i) == ' '; ++i)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private static int lastNonSpace(String str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = str.length() - 1; i >= 0 && str.charAt(i) == ' '; --i)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private static String[] patternFromJson(JsonArray p_192407_0_)
|
||||
{
|
||||
String[] astring = new String[p_192407_0_.size()];
|
||||
|
||||
if (astring.length > 3)
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid pattern: too many rows, 3 is maximum");
|
||||
}
|
||||
else if (astring.length == 0)
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < astring.length; ++i)
|
||||
{
|
||||
String s = JsonUtils.getString(p_192407_0_.get(i), "pattern[" + i + "]");
|
||||
|
||||
if (s.length() > 3)
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid pattern: too many columns, 3 is maximum");
|
||||
}
|
||||
|
||||
if (i > 0 && astring[0].length() != s.length())
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
|
||||
}
|
||||
|
||||
astring[i] = s;
|
||||
}
|
||||
|
||||
return astring;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Ingredient> deserializeKey(JsonObject p_192408_0_)
|
||||
{
|
||||
Map<String, Ingredient> map = Maps.<String, Ingredient>newHashMap();
|
||||
|
||||
for (Entry<String, JsonElement> entry : p_192408_0_.entrySet())
|
||||
{
|
||||
if (((String)entry.getKey()).length() != 1)
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid key entry: '" + (String)entry.getKey() + "' is an invalid symbol (must be 1 character only).");
|
||||
}
|
||||
|
||||
if (" ".equals(entry.getKey()))
|
||||
{
|
||||
throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
|
||||
}
|
||||
|
||||
map.put(entry.getKey(), deserializeIngredient(entry.getValue()));
|
||||
}
|
||||
|
||||
map.put(" ", Ingredient.EMPTY);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Ingredient deserializeIngredient(@Nullable JsonElement p_193361_0_)
|
||||
{
|
||||
if (p_193361_0_ != null && !p_193361_0_.isJsonNull())
|
||||
{
|
||||
if (p_193361_0_.isJsonObject())
|
||||
{
|
||||
return Ingredient.fromStacks(deserializeItem(p_193361_0_.getAsJsonObject(), false));
|
||||
}
|
||||
else if (!p_193361_0_.isJsonArray())
|
||||
{
|
||||
throw new JsonSyntaxException("Expected item to be object or array of objects");
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonArray jsonarray = p_193361_0_.getAsJsonArray();
|
||||
|
||||
if (jsonarray.size() == 0)
|
||||
{
|
||||
throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack[] aitemstack = new ItemStack[jsonarray.size()];
|
||||
|
||||
for (int i = 0; i < jsonarray.size(); ++i)
|
||||
{
|
||||
aitemstack[i] = deserializeItem(JsonUtils.getJsonObject(jsonarray.get(i), "item"), false);
|
||||
}
|
||||
|
||||
return Ingredient.fromStacks(aitemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSyntaxException("Item cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack deserializeItem(JsonObject p_192405_0_, boolean useCount)
|
||||
{
|
||||
String s = JsonUtils.getString(p_192405_0_, "item");
|
||||
Item item = Item.REGISTRY.getObject(new ResourceLocation(s));
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
throw new JsonSyntaxException("Unknown item '" + s + "'");
|
||||
}
|
||||
else if (item.getHasSubtypes() && !p_192405_0_.has("data"))
|
||||
{
|
||||
throw new JsonParseException("Missing data for item '" + s + "'");
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = JsonUtils.getInt(p_192405_0_, "data", 0);
|
||||
int j = useCount ? JsonUtils.getInt(p_192405_0_, "count", 1) : 1;
|
||||
return new ItemStack(item, j, i);
|
||||
}
|
||||
}
|
||||
|
||||
//================================================ FORGE START ================================================
|
||||
@Override
|
||||
public int getRecipeWidth()
|
||||
{
|
||||
return this.getWidth();
|
||||
}
|
||||
@Override
|
||||
public int getRecipeHeight()
|
||||
{
|
||||
return this.getHeight();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package net.minecraft.item.crafting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.List;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ShapelessRecipes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
/** Is the ItemStack that you get when craft the recipe. */
|
||||
private final ItemStack recipeOutput;
|
||||
/** Is a List of ItemStack that composes the recipe. */
|
||||
public final NonNullList<Ingredient> recipeItems;
|
||||
private final String group;
|
||||
private final boolean isSimple;
|
||||
|
||||
public ShapelessRecipes(String group, ItemStack output, NonNullList<Ingredient> ingredients)
|
||||
{
|
||||
this.group = group;
|
||||
this.recipeOutput = output;
|
||||
this.recipeItems = ingredients;
|
||||
boolean simple = true;
|
||||
for (Ingredient i : ingredients)
|
||||
simple &= i.isSimple();
|
||||
this.isSimple = simple;
|
||||
}
|
||||
|
||||
public String getGroup()
|
||||
{
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return this.recipeOutput;
|
||||
}
|
||||
|
||||
public NonNullList<Ingredient> getIngredients()
|
||||
{
|
||||
return this.recipeItems;
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
|
||||
{
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < nonnulllist.size(); ++i)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInSlot(i);
|
||||
|
||||
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
int ingredientCount = 0;
|
||||
net.minecraft.client.util.RecipeItemHelper recipeItemHelper = new net.minecraft.client.util.RecipeItemHelper();
|
||||
List<ItemStack> inputs = Lists.newArrayList();
|
||||
|
||||
for (int i = 0; i < inv.getHeight(); ++i)
|
||||
{
|
||||
for (int j = 0; j < inv.getWidth(); ++j)
|
||||
{
|
||||
ItemStack itemstack = inv.getStackInRowAndColumn(j, i);
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
++ingredientCount;
|
||||
if (this.isSimple)
|
||||
recipeItemHelper.accountStack(itemstack, 1);
|
||||
else
|
||||
inputs.add(itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ingredientCount != this.recipeItems.size())
|
||||
return false;
|
||||
|
||||
if (this.isSimple)
|
||||
return recipeItemHelper.canCraft(this, null);
|
||||
|
||||
return net.minecraftforge.common.util.RecipeMatcher.findMatches(inputs, this.recipeItems) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
return this.recipeOutput.copy();
|
||||
}
|
||||
|
||||
public static ShapelessRecipes deserialize(JsonObject json)
|
||||
{
|
||||
String s = JsonUtils.getString(json, "group", "");
|
||||
NonNullList<Ingredient> nonnulllist = deserializeIngredients(JsonUtils.getJsonArray(json, "ingredients"));
|
||||
|
||||
if (nonnulllist.isEmpty())
|
||||
{
|
||||
throw new JsonParseException("No ingredients for shapeless recipe");
|
||||
}
|
||||
else if (nonnulllist.size() > 9)
|
||||
{
|
||||
throw new JsonParseException("Too many ingredients for shapeless recipe");
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = ShapedRecipes.deserializeItem(JsonUtils.getJsonObject(json, "result"), true);
|
||||
return new ShapelessRecipes(s, itemstack, nonnulllist);
|
||||
}
|
||||
}
|
||||
|
||||
private static NonNullList<Ingredient> deserializeIngredients(JsonArray array)
|
||||
{
|
||||
NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>create();
|
||||
|
||||
for (int i = 0; i < array.size(); ++i)
|
||||
{
|
||||
Ingredient ingredient = ShapedRecipes.deserializeIngredient(array.get(i));
|
||||
|
||||
if (ingredient != Ingredient.EMPTY)
|
||||
{
|
||||
nonnulllist.add(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if this recipe can fit in a grid of the given width/height
|
||||
*/
|
||||
public boolean canFit(int width, int height)
|
||||
{
|
||||
return width * height >= this.recipeItems.size();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user