本文整理匯總了Java中net.minecraftforge.event.entity.player.FillBucketEvent.getResult方法的典型用法代碼示例。如果您正苦於以下問題:Java FillBucketEvent.getResult方法的具體用法?Java FillBucketEvent.getResult怎麽用?Java FillBucketEvent.getResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraftforge.event.entity.player.FillBucketEvent
的用法示例。
在下文中一共展示了FillBucketEvent.getResult方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBucketUse
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
public static ActionResult<ItemStack> onBucketUse(EntityPlayer player, World world, ItemStack stack, RayTraceResult target)
{
FillBucketEvent event = new FillBucketEvent(player, stack, world, target);
if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
if (event.getResult() == Result.ALLOW)
{
if (player.capabilities.isCreativeMode)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
if (--stack.stackSize <= 0)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getFilledBucket());
if (!player.inventory.addItemStackToInventory(event.getFilledBucket()))
player.dropItem(event.getFilledBucket(), false);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
return null;
}
示例2: onBucketFill
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.HIGH)
public void onBucketFill(FillBucketEvent evt) {
if (evt.getResult() != Result.DEFAULT) return;
if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return;
final RayTraceResult target = evt.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return;
final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos());
if (te == null) return;
if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) {
final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit);
final FluidStack drained = source.drain(containedFluid, false);
if (containedFluid.isFluidStackIdentical(drained)) {
source.drain(containedFluid, true);
evt.setFilledBucket(filledBucket.copy());
evt.setResult(Result.ALLOW);
}
}
}
示例3: onFillBucket
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onFillBucket(FillBucketEvent event)
{
ItemStack itemInHand = event.entityPlayer.getCurrentEquippedItem();
if(event.getResult() != Result.DENY && itemInHand.getItem() == TFCItems.woodenBucketEmpty)
{
if(event.result != null && event.result.getItem() == BuildCraftEnergy.bucketOil)
{
event.result = new ItemStack(TFPItems.CustomBucketOil);
}
}
}
示例4: onBucketFill
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onBucketFill(FillBucketEvent evt) {
if (evt.getResult() != Result.DEFAULT) return;
if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return;
final RayTraceResult target = evt.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return;
final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos());
if (te == null) return;
if (!canFill(evt.getWorld(), target.getBlockPos(), te)) { return; }
if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) {
final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit);
final FluidStack fluidInContainer = source.drain(Fluid.BUCKET_VOLUME, false);
if (fluidInContainer != null) {
final ItemStack filledBucket = getFilledBucket(fluidInContainer);
if (!filledBucket.isEmpty()) {
final IFluidHandlerItem container = FluidUtil.getFluidHandler(filledBucket);
if (container != null) {
final FluidStack fluidInBucket = container.drain(Integer.MAX_VALUE, false);
if (fluidInBucket != null && fluidInBucket.isFluidStackIdentical(source.drain(fluidInBucket, false))) {
source.drain(fluidInBucket, true);
evt.setFilledBucket(filledBucket.copy());
evt.setResult(Result.ALLOW);
}
}
}
}
}
}
示例5: onFillBucket
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOW) // low priority so other mods can handle their stuff first
public void onFillBucket(FillBucketEvent event)
{
if (event.getResult() != Event.Result.DEFAULT)
{
// event was already handled
return;
}
// not for us to handle
ItemStack emptyBucket = event.getEmptyBucket();
if (emptyBucket == null ||
!emptyBucket.isItemEqual(getEmpty()) ||
(isNbtSensitive() && ItemStack.areItemStackTagsEqual(emptyBucket, getEmpty())))
{
return;
}
// needs to target a block
RayTraceResult target = event.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK)
{
return;
}
World world = event.getWorld();
BlockPos pos = target.getBlockPos();
ItemStack singleBucket = emptyBucket.copy();
singleBucket.stackSize = 1;
ItemStack filledBucket = FluidUtil.tryPickUpFluid(singleBucket, event.getEntityPlayer(), world, pos, target.sideHit);
if (filledBucket != null)
{
event.setResult(Event.Result.ALLOW);
event.setFilledBucket(filledBucket);
}
else
{
// cancel event, otherwise the vanilla minecraft ItemBucket would
// convert it into a water/lava bucket depending on the blocks material
event.setCanceled(true);
}
}
示例6: onItemRightClick
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@Override
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
boolean isEmpty = this.bucketContents == Blocks.air;
MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, isEmpty);
if (mop == null) {
return is;
} else {
if (mop.typeOfHit == MovingObjectType.BLOCK) {
int x = mop.blockX;
int y = mop.blockY;
int z = mop.blockZ;
if (!world.canMineBlock(player, x, y, z))
return is;
if (isEmpty) {
if (!player.canPlayerEdit(x, y, z, mop.sideHit, is))
return is;
FillBucketEvent event = new FillBucketEvent(player, is, world, mop);
if (MinecraftForge.EVENT_BUS.post(event) || event.isCanceled())
return is;
if (event.getResult() == Event.Result.ALLOW)
return event.result;
if (world.getBlock(x, y, z).equals(ModBlocks.latex)) {
world.setBlockToAir(x, y, z);
if (player.capabilities.isCreativeMode)
return is;
return new ItemStack(ModItems.steelBucketLatex);
} else if (world.getBlock(x, y, z).equals(BuildCraftEnergy.blockOil)) {
world.setBlockToAir(x, y, z);
if (player.capabilities.isCreativeMode)
return is;
return new ItemStack(ModItems.steelBucketOil);
} else if (world.getBlock(x, y, z).equals(BuildCraftEnergy.blockFuel)) {
world.setBlockToAir(x, y, z);
if (player.capabilities.isCreativeMode)
return is;
return new ItemStack(ModItems.steelBucketFuel);
}
} else {
return new ItemStack(ModItems.steelBucketEmpty);
}
}
return is;
}
}
示例7: onItemRightClick
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
boolean flag = itemStack.getItemDamage() == 0;
MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, flag);
if (mop == null)
return itemStack;
FillBucketEvent event = new FillBucketEvent(player, itemStack, world, mop);
if (MinecraftForge.EVENT_BUS.post(event))
return itemStack;
if (event.getResult() == Event.Result.ALLOW) {
if (player.capabilities.isCreativeMode)
return itemStack;
if (--itemStack.stackSize <= 0)
return event.result;
if (!player.inventory.addItemStackToInventory(event.result))
player.dropPlayerItemWithRandomChoice(event.result, false);
return itemStack;
}
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int x = mop.blockX;
int y = mop.blockY;
int z = mop.blockZ;
if (!world.canMineBlock(player, x, y, z))
return itemStack;
if (flag) {
if (!player.canPlayerEdit(x, y, z, mop.sideHit, itemStack))
return itemStack;
Fluid fluid = FluidRegistry.lookupFluidForBlock(world.getBlock(x, y, z));
if (fluid == null)
return itemStack;
if (!canStore(itemStack, fluid)) {
spawnBurnEffects(world, x, y, z);
if (!player.capabilities.isCreativeMode)
itemStack.stackSize = 0;
return itemStack;
}
world.setBlockToAir(x, y, z);
return getFilledBucket(new FluidStack(fluid, 1000));
}
ForgeDirection direction = ForgeDirection.getOrientation(mop.sideHit);
x += direction.offsetX;
y += direction.offsetY;
z += direction.offsetZ;
if (!player.canPlayerEdit(x, y, z, mop.sideHit, itemStack))
return itemStack;
if (tryPlaceContainedLiquid(itemStack, world, x, y, z) && !player.capabilities.isCreativeMode)
return getEmptyBucket();
}
return itemStack;
}
示例8: onItemRightClick
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
@Override
public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition == null)
return item;
else {
FillBucketEvent event = new FillBucketEvent(player, item, world, movingobjectposition);
if (MinecraftForge.EVENT_BUS.post(event))
return item;
if (event.getResult() == Event.Result.ALLOW) {
if (player.capabilities.isCreativeMode)
return item;
if (--item.stackSize <= 0)
return event.result;
if (!player.inventory.addItemStackToInventory(event.result)) {
player.dropPlayerItem(event.result);
}
return item;
}
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
int x = movingobjectposition.blockX;
int y = movingobjectposition.blockY;
int z = movingobjectposition.blockZ;
if (!world.canMineBlock(player, x, y, z))
return item;
if (movingobjectposition.sideHit == 0) {
--y;
}
if (movingobjectposition.sideHit == 1) {
++y;
}
if (movingobjectposition.sideHit == 2) {
--z;
}
if (movingobjectposition.sideHit == 3) {
++z;
}
if (movingobjectposition.sideHit == 4) {
--x;
}
if (movingobjectposition.sideHit == 5) {
++x;
}
if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, item))
return item;
if (this.tryPlaceContainedLiquid(world, x, y, z) && !player.capabilities.isCreativeMode)
return new ItemStack(Item.bucketEmpty);
}
return item;
}
}
示例9: onItemRightClick
import net.minecraftforge.event.entity.player.FillBucketEvent; //導入方法依賴的package包/類
public ItemStack onItemRightClick(ItemStack item, World world,
EntityPlayer player) {
MovingObjectPosition movingobjectposition = this
.getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition == null) {
return item;
} else {
FillBucketEvent event = new FillBucketEvent(player, item, world,
movingobjectposition);
if (MinecraftForge.EVENT_BUS.post(event)) {
return item;
}
if (event.getResult() == Event.Result.ALLOW) {
if (player.capabilities.isCreativeMode) {
return item;
}
if (--item.stackSize <= 0) {
return event.result;
}
if (!player.inventory.addItemStackToInventory(event.result)) {
player.dropPlayerItem(event.result);
}
return item;
}
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
int x = movingobjectposition.blockX;
int y = movingobjectposition.blockY;
int z = movingobjectposition.blockZ;
if (!world.canMineBlock(player, x, y, z)) {
return item;
}
if (movingobjectposition.sideHit == 0) {
--y;
}
if (movingobjectposition.sideHit == 1) {
++y;
}
if (movingobjectposition.sideHit == 2) {
--z;
}
if (movingobjectposition.sideHit == 3) {
++z;
}
if (movingobjectposition.sideHit == 4) {
--x;
}
if (movingobjectposition.sideHit == 5) {
++x;
}
if (!player.canPlayerEdit(x, y, z,
movingobjectposition.sideHit, item)) {
return item;
}
if (this.tryPlaceContainedLiquid(world, x, y, z)
&& !player.capabilities.isCreativeMode) {
return new ItemStack(Item.bucketEmpty);
}
}
return item;
}
}