mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-23 13:43:22 +00:00
![SquidDev](/assets/img/avatar_default.png)
This should allow us (or other mods) to register custom refuel handlers should they so wish.
49 lines
1.7 KiB
Java
49 lines
1.7 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
|
|
package dan200.computercraft.shared.turtle.core;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
import dan200.computercraft.api.turtle.TurtleAnimation;
|
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
|
import dan200.computercraft.api.turtle.event.TurtleRefuelEvent;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
public class TurtleRefuelCommand implements ITurtleCommand
|
|
{
|
|
private final int limit;
|
|
|
|
public TurtleRefuelCommand( int limit )
|
|
{
|
|
this.limit = limit;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
|
{
|
|
int slot = turtle.getSelectedSlot();
|
|
ItemStack stack = turtle.getInventory().getStackInSlot( slot );
|
|
if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" );
|
|
|
|
TurtleRefuelEvent event = new TurtleRefuelEvent( turtle, stack );
|
|
if( MinecraftForge.EVENT_BUS.post( event ) ) return TurtleCommandResult.failure( event.getFailureMessage() );
|
|
if( event.getHandler() == null ) return TurtleCommandResult.failure( "Items not combustible" );
|
|
|
|
if( limit != 0 )
|
|
{
|
|
turtle.addFuel( event.getHandler().refuel( turtle, stack, slot, limit ) );
|
|
turtle.playAnimation( TurtleAnimation.Wait );
|
|
}
|
|
|
|
return TurtleCommandResult.success();
|
|
}
|
|
}
|