本文整理汇总了Java中net.minecraftforge.energy.IEnergyStorage.canReceive方法的典型用法代码示例。如果您正苦于以下问题:Java IEnergyStorage.canReceive方法的具体用法?Java IEnergyStorage.canReceive怎么用?Java IEnergyStorage.canReceive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.energy.IEnergyStorage
的用法示例。
在下文中一共展示了IEnergyStorage.canReceive方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemUse
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(player.getHeldItem(hand).getCount() == 1){
TileEntity tile = world.getTileEntity(pos);
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, facing)){
if(!world.isRemote){
IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, facing);
if(energy != null && energy.canExtract()){
IEnergyStorage storage = player.getHeldItem(hand).getCapability(CapabilityEnergy.ENERGY, null);
if(storage != null && storage.canReceive()){
storage.receiveEnergy(energy.extractEnergy(storage.receiveEnergy(Integer.MAX_VALUE, true), false), false);
}
}
}
return EnumActionResult.SUCCESS;
}
}
return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
示例2: recursive
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
private void recursive(BlockPos from, List<BlockPos> searched, List<BlockPos> found, Map<BlockPos, EnumFacing> receivers){
for(EnumFacing side : EnumFacing.values()){
BlockPos newPos = from.offset(side);
if(!searched.contains(newPos)){
searched.add(newPos);
TileEntity tile = this.world.getTileEntity(newPos);
if(tile != null){
if(tile instanceof TileCableBasic){
found.add(newPos);
((TileCableBasic) tile).network = this;
recursive(newPos, searched, found, receivers);
} else if(tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
if(storage != null && storage.canReceive()){
receivers.put(newPos, side.getOpposite());
}
}
}
}
}
}
示例3: transmitEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public int transmitEnergy(BlockPos from, int energy, boolean simulate){
int oldEnergy = energy;
for(Map.Entry<BlockPos, EnumFacing> entry : this.receiver.entrySet()){
TileEntity tile = this.world.getTileEntity(entry.getKey());
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, entry.getValue())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, entry.getValue());
if(storage != null && storage.canReceive()){
energy -= storage.receiveEnergy(energy, simulate);
}
}
if(energy <= 0){
return oldEnergy;
}
}
return oldEnergy - energy;
}
示例4: getAdjacentStorage
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static ArrayList<IEnergyStorage> getAdjacentStorage(World world, BlockPos pos) {
ArrayList<IEnergyStorage> consumers = new ArrayList<>();
if (pos.getY()<255) {
IEnergyStorage up = getStorage(world,pos.up(),EnumFacing.DOWN);
if (up.canReceive()) consumers.add(up);
}
if (pos.getY()>0) {
IEnergyStorage down = getStorage(world, pos.down(), EnumFacing.UP);
if (down.canReceive()) consumers.add(down);
}
IEnergyStorage north = getStorage(world, pos.north(), EnumFacing.SOUTH);
if (north.canReceive()) consumers.add(north);
IEnergyStorage south = getStorage(world, pos.south(), EnumFacing.NORTH);
if (south.canReceive()) consumers.add(south);
IEnergyStorage east = getStorage(world, pos.east(), EnumFacing.WEST);
if (east.canReceive()) consumers.add(east);
IEnergyStorage west = getStorage(world, pos.west(), EnumFacing.EAST);
if (west.canReceive()) consumers.add(west);
return consumers;
}
示例5: getValidPair
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static NNList<Triple<ItemStack, ItemStack, Integer>> getValidPair(List<ItemStack> validItems) {
NNList<Triple<ItemStack, ItemStack, Integer>> result = new NNList<>();
for (ItemStack stack : validItems) {
if (PowerHandlerUtil.getCapability(stack, null) != null) {
ItemStack copy = stack.copy();
IEnergyStorage emptyCap = PowerHandlerUtil.getCapability(copy, null);
if (emptyCap != null) {
int extracted = 1, maxloop = 200;
while (extracted > 0 && emptyCap.canExtract() && maxloop-- > 0) {
extracted = emptyCap.extractEnergy(Integer.MAX_VALUE, false);
}
if (emptyCap.canReceive() && emptyCap.getEnergyStored() < emptyCap.getMaxEnergyStored()) {
ItemStack empty = copy.copy();
int added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
int power = added;
maxloop = 200;
while (added > 0 && maxloop-- > 0) {
power += added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
}
result.add(Triple.of(empty, copy, power));
}
}
}
}
return result;
}
示例6: isSideValid
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
private List<EnumFacing> isSideValid(IBlockAccess world, BlockPos pos){
List<EnumFacing> sides = new ArrayList<>();
for(EnumFacing side : EnumFacing.values()){
TileEntity tile = world.getTileEntity(pos.offset(side));
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, side)){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side);
if(storage != null && (storage.canReceive() || storage.canExtract())){
sides.add(side);
}
}
}
return sides;
}
示例7: pushEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static int pushEnergy(World world, BlockPos pos, IEnergyStorage energy, EnumFacing... sides){
if(!world.isRemote && energy.canExtract()){
for(EnumFacing side : sides){
TileEntity tile = world.getTileEntity(pos.offset(side));
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
if(storage != null && storage.canReceive()){
return energy.extractEnergy(storage.receiveEnergy(energy.extractEnergy(Integer.MAX_VALUE, true), false), false);
}
}
}
}
return 0;
}
示例8: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update() {
this.energyStorage.tick();
IBlockState cur = world.getBlockState(pos);
EnumFacing facing = cur.getValue(BlockBattery.FACING);
IEnergyStorage target = RFTransport.getStorage(world, pos.offset(facing), facing.getOpposite());
if (target.canReceive()) {
int toPush = Math.min(energyStorage.getEnergyStored(), target.getMaxEnergyStored());
int received = target.receiveEnergy(toPush, false);
if (received>0) energyStorage.extractEnergy(received, false);
energyStorage.receiveEnergy(energyStorage.getMaxEnergyStored(), false);
}
}
示例9: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update() {
this.energyStorage.tick();
IBlockState cur = world.getBlockState(pos);
EnumFacing facing = cur.getValue(BlockBattery.FACING);
IEnergyStorage target = RFTransport.getStorage(world, pos.offset(facing), facing.getOpposite());
if (target.canReceive()) {
int toPush = Math.min(energyStorage.getEnergyStored(), 800);
int received = target.receiveEnergy(toPush, false);
if (received>0) energyStorage.extractEnergy(received, false);
}
}
示例10: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update()
{
if (this.getWorld().isRemote)
return;
for (EnumFacing dir : EnumFacing.VALUES)
{
EnumFacing side = dir.getOpposite();
BlockPos pos = this.getPos().offset(dir);
ICapabilityProvider provider = this.getWorld().getTileEntity(pos);
if (provider == null)
continue;
IEnergyStorage storage = null;
if (provider.hasCapability(CapabilityEnergy.ENERGY, side))
storage = provider.getCapability(CapabilityEnergy.ENERGY, side);
//TODO? Other compatible energy types?
if (storage == null)
continue;
if (storage.canReceive())
storage.receiveEnergy(POWER_PER_TICK, false);
}
}
示例11: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update()
{
if (getWorld().isRemote) return;
List<IEnergyStorage> receivers = new ArrayList<>(associates.stream().map((pt) -> (ReceiverTE)pt)
.filter(ReceiverTE::canReceive).collect(Collectors.toList()));
for (EnumFacing facing: EnumFacing.VALUES) {
TileEntity receiver = getWorld().getTileEntity(getPos().offset(facing));
if (receiver!=null && receiver.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) {
final IEnergyStorage receiverCapability = receiver.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite());
if (receiverCapability.canReceive())
receivers.add(receiverCapability);
}
}
if (receivers.isEmpty()) return;
if (storedEnergy < receivers.size()) return;
int amttosend = Math.min(100, storedEnergy/receivers.size());
int sum = 0;
for (IEnergyStorage e: receivers) {
int amt = e.receiveEnergy(amttosend, true);
amt = e.receiveEnergy(amt, false);
sum+=amt;
}
storedEnergy -= sum;
}
示例12: receiveEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public int receiveEnergy(int maxReceive, boolean simulate)
{
int remaining = maxReceive;
for (IEnergyStorage st : buffers)
{
if (st.canReceive())
remaining = st.receiveEnergy(remaining, simulate);
}
return remaining;
}