本文整理匯總了Java中net.minecraftforge.event.ForgeEventFactory類的典型用法代碼示例。如果您正苦於以下問題:Java ForgeEventFactory類的具體用法?Java ForgeEventFactory怎麽用?Java ForgeEventFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ForgeEventFactory類屬於net.minecraftforge.event包,在下文中一共展示了ForgeEventFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertItem
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
EntityPlayer player = getPlayer();
if (player == null || getFoodValue(stack) <= 0) return stack;
if (!okToFeed(stack, player)) return stack;
if (simulate) return ItemStack.EMPTY;
int startValue = stack.getCount();
ItemStack remainingItem = stack;
while (stack.getCount() > 0) {
remainingItem = stack.onItemUseFinish(player.world, player);
remainingItem = ForgeEventFactory.onItemUseFinish(player, stack, 0, remainingItem);
if (remainingItem.getCount() > 0 && (remainingItem != stack || remainingItem.getCount() != startValue)) {
if (!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.getCount() > 0) {
player.dropItem(remainingItem, false);
}
}
if (stack.getCount() == startValue) break;
}
return remainingItem.getCount() > 0 ? remainingItem : ItemStack.EMPTY;
}
示例2: onItemRightClick
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (isCooked)
{
player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.marshmallowCooked));
player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.roastingStick));
stack.setCount(stack.getCount() - 1);
}
else
{
player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.marshmallow));
player.inventory.addItemStackToInventory(new ItemStack(RegisterItems.roastingStick));
stack.setCount(stack.getCount() - 1);
}
if (stack.getCount() <= 0)
{
player.inventory.setItemStack(ItemStack.EMPTY);
ForgeEventFactory.onPlayerDestroyItem(player, stack, hand);
}
player.inventoryContainer.detectAndSendChanges();
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
示例3: onItemRightClick
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (player.inventory.hasItemStack(new ItemStack(RegisterItems.marshmallow)))
{
stack.setCount(stack.getCount() - 1);
ItemStack mallowStick = new ItemStack(RegisterItems.roastingStickRawMallow);
if (!player.inventory.addItemStackToInventory(mallowStick))
{
EntityItem drop = new EntityItem(world, player.posX, player.posY, player.posZ, mallowStick);
world.spawnEntity(drop);
}
stack.setCount(stack.getCount() - 1); // Why is this done twice?
if (stack.getCount() <= 0)
{
player.inventory.setItemStack(ItemStack.EMPTY);
ForgeEventFactory.onPlayerDestroyItem(player, stack, hand);
}
}
player.inventoryContainer.detectAndSendChanges();
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
示例4: getContainerItem
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
public static ItemStack getContainerItem(ItemStack stack)
{
if (stack == null) return null;
if (stack.getItem().hasContainerItem(stack))
{
stack = stack.getItem().getContainerItem(stack);
if (stack != null && stack.isItemStackDamageable() && stack.getMetadata() > stack.getMaxDamage())
{
ForgeEventFactory.onPlayerDestroyItem(craftingPlayer.get(), stack, null);
return null;
}
return stack;
}
return null;
}
示例5: damageShield
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
/** Fixed vanilla code */
private void damageShield(EntityPlayer owner, float damage) {
int i = 1 + MathHelper.floor(damage);
owner.getActiveItemStack().damageItem(i, owner);
if (owner.getActiveItemStack().getCount() <= 0) {
EnumHand enumhand = owner.getActiveHand();
ForgeEventFactory.onPlayerDestroyItem(owner, owner.getActiveItemStack(), enumhand);
if(enumhand == EnumHand.MAIN_HAND) {
owner.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
} else {
owner.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
}
owner.resetActiveHand();
owner.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + owner.world.rand.nextFloat() * 0.4F);
}
}
示例6: onItemUseFinish
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
protected void onItemUseFinish()
{
if (this.itemInUse != null)
{
updateItemUse(this.itemInUse, 16);
int i = this.itemInUse.stackSize;
ItemStack itemstack = this.itemInUse.onFoodEaten(this.worldObj, this);
itemstack = ForgeEventFactory.onItemUseFinish(this, this.itemInUse, this.itemInUseCount, itemstack);
if ((itemstack != this.itemInUse) || ((itemstack != null) && (itemstack.stackSize != i)))
{
this.inventory.mainInventory[this.inventory.currentItem] = itemstack;
if ((itemstack != null) && (itemstack.stackSize == 0)) {
this.inventory.mainInventory[this.inventory.currentItem] = null;
}
}
clearItemInUse();
}
}
示例7: breakBlock
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
public void breakBlock(BlockPos pos) {
IBlockState state = this.blockSystem.getBlockState(pos);
Block block = state.getBlock();
if (this.blockSystem.getMainWorld().isRemote) {
this.blockSystem.playEvent(2001, pos, Block.getStateId(state));
if (BlockSystems.PROXY.isClientPlayer(this.player)) {
BlockSystems.NETWORK_WRAPPER.sendToServer(new BreakBlockMessage(this.player, this.blockSystem, pos, BreakBlockMessage.BreakState.BREAK));
}
}
if (!this.player.capabilities.isCreativeMode) {
ItemStack heldItem = this.player.getHeldItemMainhand();
if (heldItem != null) {
heldItem.onBlockDestroyed(this.blockSystem, state, pos, this.player);
if (heldItem.stackSize <= 0) {
ForgeEventFactory.onPlayerDestroyItem(this.player, heldItem, EnumHand.MAIN_HAND);
this.player.setHeldItem(EnumHand.MAIN_HAND, null);
}
}
block.harvestBlock(this.blockSystem, this.player, pos, state, this.blockSystem.getTileEntity(pos), heldItem);
}
boolean removed = block.removedByPlayer(state, this.blockSystem, pos, this.player, false);
if (removed) {
block.onBlockDestroyedByPlayer(this.blockSystem, pos, state);
}
}
示例8: onReceiveServer
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public void onReceiveServer(MinecraftServer server, WorldServer world, EntityPlayerMP player, MessageContext context) {
BlockSystem blockSystem = BlockSystems.PROXY.getBlockSystemHandler(world).getBlockSystem(this.blockSystem);
if (blockSystem != null) {
IBlockState state = blockSystem.getBlockState(this.position);
ItemStack heldItem = player.getHeldItem(this.hand);
if (!state.getBlock().onBlockActivated(blockSystem, this.position, state, player, this.hand, heldItem, this.side, this.hitX, this.hitY, this.hitZ)) {
if (heldItem != null) {
int size = heldItem.stackSize;
heldItem.onItemUse(player, blockSystem, this.position, this.hand, this.side, this.hitX, this.hitY, this.hitZ);
if (player.capabilities.isCreativeMode && heldItem.stackSize < size) {
heldItem.stackSize = size;
}
if (heldItem.stackSize <= 0) {
player.setHeldItem(this.hand, null);
ForgeEventFactory.onPlayerDestroyItem(player, heldItem, this.hand);
}
}
}
}
}
示例9: transform
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public ItemStack transform(ItemStack input, EntityPlayer craftingPlayer) {
if(!input.isItemStackDamageable()) return input;
// Shockingly, there's already code to prevent us from going below 0 (undamaged)
int newDamage = input.getItemDamage()+by;
input.setItemDamage(newDamage);
// Check if we've destroyed it.
if (input.getMetadata() > input.getMaxDamage())
{
ForgeEventFactory.onPlayerDestroyItem(craftingPlayer, input, null);
return null;
}
return input;
}
示例10: attackEvent
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@SubscribeEvent
public void attackEvent (LivingAttackEvent e) {
if (e.getEntityLiving().getActiveItemStack() == null)
return;
final ItemStack stack = e.getEntityLiving().getActiveItemStack();
if (stack.getItem() instanceof ItemCustomShield && e.getAmount() > 0.0f) {
final int i = 1 + MathHelper.floor(e.getAmount());
stack.damageItem(i, e.getEntityLiving());
if (stack.stackSize <= 0) {
final EnumHand enumhand = e.getEntityLiving().getActiveHand();
if (e.getEntityLiving() instanceof EntityPlayer)
ForgeEventFactory.onPlayerDestroyItem((EntityPlayer) e.getEntityLiving(), stack, enumhand);
e.getEntityLiving().setItemStackToSlot(enumhand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, null);
if (e.getEntityLiving().getEntityWorld().isRemote)
e.getEntityLiving().playSound(SoundEvents.BLOCK_ANVIL_BREAK, 0.8F, 0.8F + e.getEntityLiving().getEntityWorld().rand.nextFloat() * 0.4F);
}
}
}
示例11: update
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public void update() {
if(!worldObj.isRemote && !worldObj.isBlockPowered(pos) && worldObj.getTotalWorldTime() % breakModTime == 0 &&
this.hasLPCell() && this.canDrawCellPower(breakLE)) {
BlockPos check = this.pos.offset(EnumFacing.getFront(this.getBlockMetadata()));
// make sure the block is valid and isn't unbreakable
IBlockState checkState = worldObj.getBlockState(check);
Block checkBlock = checkState.getBlock();
if(checkBlock != null && !checkBlock.isAir(checkState, worldObj, check) && checkState.getBlockHardness(worldObj, check) >= 0) {
List<ItemStack> drops = checkBlock.getDrops(this.worldObj, check, checkState, 0);
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.worldObj, check,
this.worldObj.getBlockState(check), 0, 1, false, null);
if(random.nextFloat() <= chance) {
this.drawCellPower(breakLE);
worldObj.destroyBlock(check, true);
}
}
}
}
示例12: processRightClick
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
/**
* Handles right clicking of an item
*/
public EnumActionResult processRightClick(ItemStack stack, EnumHand hand) {
if (getSettler().getCooldownTracker().hasCooldown(stack.getItem())) {
return EnumActionResult.PASS;
} else {
EnumActionResult eventResult = ForgeHooks.onItemRightClick(getSettler().getFakePlayerImplementation(), hand);
if (eventResult != null) {
return eventResult;
}
int stackSize = stack.getCount();
int meta = stack.getMetadata();
ActionResult<ItemStack> result = stack.useItemRightClick(getWorld(), getSettler().getFakePlayerImplementation(), hand);
ItemStack newStack = result.getResult();
if (newStack == stack && newStack.getCount() == stackSize && newStack.getMaxItemUseDuration() <= 0 && newStack.getMetadata() == meta) {
return result.getType();
} else {
getSettler().setHeldItem(hand, newStack);
if (newStack.isEmpty()) {
getSettler().setHeldItem(hand, ItemStack.EMPTY);
ForgeEventFactory.onPlayerDestroyItem(getSettler().getFakePlayerImplementation(), newStack, hand);
}
}
return result.getType();
}
}
示例13: onMessage
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public IMessage onMessage(SculptureOperationMessage message,
MessageContext ctx) {
World w = ctx.getServerHandler().playerEntity.worldObj;
if (Operations.validOperation(w, message.x, message.y, message.z, message.pos, message.flags)) {
Operations.applyOperation(w, message.x, message.y, message.z, message.pos, message.flags, message.block, message.meta);
}
EntityPlayer ep = ctx.getServerHandler().playerEntity;
ItemStack is = ep.getCurrentEquippedItem();
if ((message.flags & Operations.DAMAGE) != 0) {
is.damageItem(1, ep);
} else if ((Operations.CONSUME & message.flags) != 0) {
if (!ep.capabilities.isCreativeMode) {
is.stackSize--;
if (is.stackSize <= 0) {
ForgeEventFactory.onPlayerDestroyItem(ep, is);
ep.inventory.mainInventory[ep.inventory.currentItem] = null;
}
}
}
return null;
}
示例14: dropBlockAsItemWithChance
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
if (!p_149690_1_.isRemote)
{
ArrayList<ItemStack> items = getDrops(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_7_);
p_149690_6_ = ForgeEventFactory.fireBlockHarvesting(items, p_149690_1_, this, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_7_, p_149690_6_, false, harvesters.get());
for (ItemStack item : items)
{
if (p_149690_1_.rand.nextFloat() <= p_149690_6_)
{
this.dropBlockAsItem(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, item);
}
}
}
}
示例15: onMessage
import net.minecraftforge.event.ForgeEventFactory; //導入依賴的package包/類
@Override
public IMessage onMessage(SculptureOperationMessage message,
MessageContext ctx) {
World w = ctx.getServerHandler().playerEntity.worldObj;
if(Operations.validOperation(w, message.x, message.y, message.z, message.pos, message.flags))
Operations.applyOperation(w, message.x, message.y, message.z, message.pos, message.flags, message.block, message.meta);
EntityPlayer ep = ctx.getServerHandler().playerEntity;
ItemStack is = ep.getCurrentEquippedItem();
if((message.flags & Operations.DAMAGE) > 0)
is.damageItem(1, ep);
else if((Operations.CONSUME & message.flags) > 0){
if(!ep.capabilities.isCreativeMode){
is.stackSize--;
if(is.stackSize <= 0){
ForgeEventFactory.onPlayerDestroyItem(ep,is);
ep.inventory.mainInventory[ep.inventory.currentItem] = null;
}
}
}
return null;
}