下面列出了net.minecraft.util.MovingObjectPosition#net.minecraft.item.Item 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SubscribeEvent
public void registerItemColorHandlers(ColorHandlerEvent.Item event)
{
ItemColors colors = event.getItemColors();
if (EnderUtilitiesBlocks.ELEVATOR.isEnabled())
{
colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR));
}
if (EnderUtilitiesBlocks.ELEVATOR_SLAB.isEnabled())
{
colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR_SLAB));
}
if (EnderUtilitiesBlocks.ELEVATOR_LAYER.isEnabled())
{
colors.registerItemColorHandler(new ItemColorHandlerDyes(1, 0xFFFFFF), Item.getItemFromBlock(EnderUtilitiesBlocks.ELEVATOR_LAYER));
}
}
private void dropLootItem(Item item, int amount) {
if (amount == 0) {
return;
}
for (int i = 0; i < amount; i++) {
ItemStack stack = new ItemStack(item);
EntityItem dropItem = new EntityItem(world, posX, posY, posZ, stack.copy());
dropItem.setNoPickupDelay();
dropItem.motionY = rand.nextDouble();
dropItem.motionZ = rand.nextDouble() - 0.5d;
dropItem.motionX = rand.nextDouble() - 0.5d;
world.spawnEntity(dropItem);
}
}
public static Object finalizeIngredient(Object ingredient) {
if (ingredient instanceof MetaItem.MetaValueItem) {
ingredient = ((MetaItem<?>.MetaValueItem) ingredient).getStackForm();
} else if (ingredient instanceof Enum) {
ingredient = ((Enum<?>) ingredient).name();
} else if (ingredient instanceof UnificationEntry) {
ingredient = ingredient.toString();
} else if (!(ingredient instanceof ItemStack
|| ingredient instanceof Item
|| ingredient instanceof Block
|| ingredient instanceof String
|| ingredient instanceof Character
|| ingredient instanceof Boolean)) {
throw new IllegalArgumentException(ingredient.getClass().getSimpleName() + " type is not suitable for crafting input.");
}
return ingredient;
}
public static void adaptCacheForWorld(){
Set<String> used = new HashSet<>(OreDictHandler.cache.keySet());
OreDictHandler.cache.clear();
OreDictHandler.cacheNonBW.clear();
for (String s : used) {
if (!OreDictionary.getOres(s).isEmpty()) {
ItemStack tmpstack = OreDictionary.getOres(s).get(0).copy();
Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(tmpstack.getItem()), (short) tmpstack.getItemDamage());
OreDictHandler.cache.put(s, p);
for (ItemStack tmp : OreDictionary.getOres(s)) {
Pair<Integer, Short> p2 = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
if (UI == null)
UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")) {
OreDictHandler.cacheNonBW.add(p2);
}
}
}
}
}
@Override
public void call(String[] args) throws CmdException
{
if(args.length == 0)
throw new CmdSyntaxError();
if(!MC.player.abilities.creativeMode)
throw new CmdError("Creative mode only.");
ItemStack heldItem = MC.player.inventory.getMainHandStack();
int heldItemID = Item.getRawId(heldItem.getItem());
int writtenBookID = Item.getRawId(Items.WRITTEN_BOOK);
if(heldItemID != writtenBookID)
throw new CmdError(
"You must hold a written book in your main hand.");
String author = String.join(" ", args);
heldItem.putSubTag("author", StringTag.of(author));
}
static Matcher<ItemStack> containsItem(final Item item, final int size) {
return new BaseMatcher<ItemStack>() {
@Override
public boolean matches(Object o) {
if (o instanceof ItemStack) {
ItemStack stack = (ItemStack)o;
return stack.getItem() == item && stack.getCount() == size;
}
return false;
}
@Override
public void describeTo(Description arg0) {
arg0.appendText(String.format("%dx%s", size, item.getUnlocalizedName()));
}
};
}
/**
* Checks to see if the passed item/block already has aspects associated with it.
* @param id
* @param meta
* @return
*/
public static boolean exists(Item item, int meta) {
AspectList tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,meta));
if (tmp==null) {
tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,OreDictionary.WILDCARD_VALUE));
if (meta==OreDictionary.WILDCARD_VALUE && tmp==null) {
int index=0;
do {
tmp = ThaumcraftApi.objectTags.get(Arrays.asList(item,index));
index++;
} while (index<16 && tmp==null);
}
if (tmp==null) return false;
}
return true;
}
private void dropBlock() {
final Block block = blockState.getBlock();
Random rand = world.rand;
final int count = block.quantityDropped(blockState, 0, rand);
for (int i = 0; i < count; i++) {
final Item item = block.getItemDropped(blockState, rand, 0);
if (item != null) {
ItemStack toDrop = new ItemStack(item, 1, block.damageDropped(blockState));
entityDropItem(toDrop, 0.1f);
}
}
if (tileEntity instanceof IInventory) {
IInventory inv = (IInventory)tileEntity;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack is = inv.getStackInSlot(i);
if (is != null) entityDropItem(is, 0.1f);
}
}
}
@Override
public void init()
{
if(config.getTag("checkUpdates").getBooleanValue(true))
CCUpdateChecker.updateCheck("EnderStorage");
ClientUtils.enhanceSupportersList("EnderStorage");
super.init();
PacketCustom.assignHandler(EnderStorageCPH.channel, new EnderStorageCPH());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(blockEnderChest), new ItemEnderStorageRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileEnderChest.class, new EnderChestRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileEnderTank.class, new EnderTankRenderer());
}
private static void registerThirdPartyRecipes() {
List<ItemStack> plasticInputs = new ArrayList<ItemStack>();
List<ItemStack> clearPlasticInputs = new ArrayList<ItemStack>();
List<ItemStack> paperInputs = new ArrayList<ItemStack>();
List<ItemStack> fertilizerInputs = new ArrayList<ItemStack>();
if (ModLoader.isDumpsterDivingLoaded()) {
fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_apple")));
fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_pumpkin")));
fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:slop_rand")));
fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_bread")));
fertilizerInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:mold_stew")));
paperInputs.add(new ItemStack(Item.getByNameOrId("dumpsterdiving:scrap_wooddust")));
}
registerProcessorRecipes(new ItemStack(ModItems.plasticblock), plasticInputs);
registerProcessorRecipes(new ItemStack(ModItems.clearplasticblock), clearPlasticInputs);
registerProcessorRecipes(new ItemStack(ModItems.paperpulp), paperInputs);
registerProcessorRecipes(new ItemStack(ModItems.fertilizer), fertilizerInputs);
}
private float getValue(Item item)
{
switch(priority.getSelected())
{
case SPEED:
if(item instanceof SwordItem)
return ((ISwordItem)item).fuckMcAfee();
else if(item instanceof MiningToolItem)
return ((IMiningToolItem)item).fuckMcAfee2();
break;
case DAMAGE:
if(item instanceof SwordItem)
return ((SwordItem)item).getAttackDamage();
else if(item instanceof MiningToolItem)
return ((IMiningToolItem)item).fuckMcAfee1();
break;
}
return Integer.MIN_VALUE;
}
private Block getPlantBlock (TileEntityGarden tileEntity, Item item) {
if (item == null)
return null;
if (item instanceof IPlantable)
return ((IPlantable)item).getPlant(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
if (item instanceof ItemBlock)
return Block.getBlockFromItem(item);
return null;
}
public boolean contains(Item ingred) {
for (ItemStack item : items) {
if (item.getItem() == ingred) {
return true;
}
}
return false;
}
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for(int i = 0; i < _subBlocks.length; i++) {
par3List.add(new ItemStack(this, 1, i));
}
}
private void loadPersonalItem() {
ConfigTag tag = config.getTag("personalItemID")
.setComment("The name of the item used to set the chest to personal. Diamond by default");
String name = tag.getValue("diamond");
personalItem = (Item) Item.itemRegistry.getObject(name);
if (personalItem == null) {
personalItem = Items.diamond;
tag.setValue("diamond");
}
}
public static Object[] getCraftingRecipeKey(EntityPlayer player, ItemStack stack) {
int[] key = new int[] {Item.getIdFromItem(stack.getItem()),stack.getItemDamage()};
if (keyCache.containsKey(key)) {
if (keyCache.get(key)==null) return null;
if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), (String)(keyCache.get(key))[0]))
return keyCache.get(key);
else
return null;
}
for (ResearchCategoryList rcl:ResearchCategories.researchCategories.values()) {
for (ResearchItem ri:rcl.research.values()) {
if (ri.getPages()==null) continue;
for (int a=0;a<ri.getPages().length;a++) {
ResearchPage page = ri.getPages()[a];
if (page.recipe!=null && page.recipe instanceof CrucibleRecipe[]) {
CrucibleRecipe[] crs = (CrucibleRecipe[]) page.recipe;
for (CrucibleRecipe cr:crs) {
if (cr.getRecipeOutput().isItemEqual(stack)) {
keyCache.put(key,new Object[] {ri.key,a});
if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key))
return new Object[] {ri.key,a};
}
}
} else
if (page.recipeOutput!=null && stack !=null && page.recipeOutput.isItemEqual(stack)) {
keyCache.put(key,new Object[] {ri.key,a});
if (ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), ri.key))
return new Object[] {ri.key,a};
else
return null;
}
}
}
}
keyCache.put(key,null);
return null;
}
@Override
protected int getDropItemId()
{
if (!getIsAdult()) { return Item.silk.itemID; }
boolean flag = (rand.nextInt(2) == 0);
switch (getType())
{
case 1:
if (flag) { return MoCreatures.stingDirt.itemID; }
return MoCreatures.chitinDirt.itemID;
case 2:
if (flag) { return MoCreatures.stingCave.itemID; }
return MoCreatures.chitinCave.itemID;
case 3:
if (flag) { return MoCreatures.stingNether.itemID; }
return MoCreatures.chitinNether.itemID;
case 4:
if (flag) { return MoCreatures.stingFrost.itemID; }
return MoCreatures.chitinFrost.itemID;
case 5:
return Item.rottenFlesh.itemID;
default:
return Item.silk.itemID;
}
}
/**
* Get the quantity dropped based on the given fortune level
*/
public int quantityDroppedWithBonus(int fortune, Random random) {
if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState) this.getBlockState().getValidStates().iterator().next(), random, fortune)) {
int i = random.nextInt(fortune + 2) - 1;
if (i < 0) {
i = 0;
}
return this.quantityDropped(random) * (i + 1);
} else {
return this.quantityDropped(random);
}
}
public static String getStackString(ItemStack stack)
{
if (stack.isEmpty() == false)
{
ResourceLocation rl = Item.REGISTRY.getNameForObject(stack.getItem());
return String.format("[%s @ %d - display: %s - NBT: %s] (%s)",
rl != null ? rl.toString() : "null", stack.getMetadata(), stack.getDisplayName(),
stack.getTagCompound() != null ? stack.getTagCompound().toString() : "<no NBT>",
stack.toString());
}
return "<empty>";
}
@Override
public Optional<Long> getFor(ItemStack stack) {
final Item item = stack.getItem();
if (item instanceof ITerminalItem) {
final ITerminalItem terminalItem = (ITerminalItem)item;
return Optional.fromNullable(terminalItem.getTerminalGuid(stack));
}
return Optional.absent();
}
@Inject(method = "renderLayer", at = @At("HEAD"), cancellable = true)
private void preRenderLayer(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks,
float netHeadYaw, float headPitch, float scale, int armorSlot, CallbackInfo ci) {
ItemStack itemstack = this.getCurrentArmor(entitylivingbaseIn, armorSlot);
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
Item item = itemstack.getItem();
if (Settings.HIDE_LEATHER_ARMOR &&
(item == Items.leather_boots || item == Items.leather_leggings || item == Items.leather_chestplate || item == Items.leather_helmet)) {
ci.cancel();
}
}
}
private static void registerBlockItem(Block toRegister) {
Item item = Item.getItemFromBlock(toRegister);
Minecraft.getMinecraft()
.getRenderItem()
.getItemModelMesher()
.register(item, 0,
new ModelResourceLocation(ValkyrienSkiesMod.MOD_ID + ":" + item.getTranslationKey()
.substring(5), "inventory"));
}
private static ImmutableList<ItemStack> retrieveValidItemsList() {
return StreamSupport.stream(Item.REGISTRY.spliterator(), false)
.filter(item -> item instanceof ItemBlock)
.flatMap(item -> getSubItems(item).stream())
.filter(FacadeHelper::isValidFacade)
.collect(GTUtility.toImmutableList());
}
@Override
public ArrayList<ItemStack> getDrops (World world, int x, int y, int z, int metadata, int fortune) {
TileEntityLantern tile = getTileEntity(world, x, y, z);
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
int count = quantityDropped(metadata, fortune, world.rand);
for(int i = 0; i < count; i++)
{
Item item = getItemDropped(metadata, world.rand, fortune);
if (item != null)
{
boolean glass = false;
String source = null;
int sourceMeta = 0;
if (tile != null) {
glass = tile.hasGlass();
source = tile.getLightSource();
sourceMeta = tile.getLightSourceMeta();
}
ItemStack stack = ((ItemLantern)Item.getItemFromBlock(this)).makeItemStack(1, metadata, glass, source, sourceMeta);
ret.add(stack);
}
}
return ret;
}
@SuppressWarnings({"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
if (getChargedItem(itemStack) == this) {
ItemStack charged = new ItemStack(this, 1);
ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, false);
itemList.add(charged);
}
if (getEmptyItem(itemStack) == this) {
itemList.add(new ItemStack(this, 1, getMaxDamage()));
}
}
private static Set<Item> excludedFuels() {
Set<Item> efuels = new HashSet<Item>();
efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.red_mushroom));
efuels.add(Item.getItemFromBlock(Blocks.standing_sign));
efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
return efuels;
}
@Override
public IMetaProviderProxy createProxy(final ItemStack stack) {
final Item item = stack.getItem();
if (item == null) return null;
final Map<String, IItemStackMetaProvider<?>> providers = getProviders(item, stack);
return new Proxy(providers, stack, item);
}
private NotebookWrapper createInventoryWrapper(TileEntity tile, Index slot) {
ItemStack notebook = GET_NOTEBOOK.call(tile, slot.byteValue());
Preconditions.checkState(notebook != null, "Empty slot");
Item item = notebook.getItem();
Preconditions.checkState(item instanceof IItemPageCollection, "Invalid item in slot");
return new NotebookWrapper((WorldServer)tile.getWorldObj(), (IItemPageCollection)item, notebook);
}
private Item getItem()
{
if(this == BlockLoader.BAMBOODOOR){
return ItemLoader.BAMBOO_DOOR;
}
return ItemLoader.BAMBOO_DOOR;
}
public LPHelper()
{
try
{
Class LPMain = Class.forName("logisticspipes.LogisticsPipes");
Field field = LPMain.getDeclaredField("LogisticsFluidContainer");
LPFluidItem = (Item) field.get(Item.appleGold);
} catch (Throwable e)
{
LPInstalled = false;
}
LPInstalled = LPFluidItem != null;
}