forked from micdoodle8/Galacticraft
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix oversights of last PR See @eigenraven's review of #76 * Update dependencies * Rework rocket fuel API
- Loading branch information
1 parent
4a0c7b3
commit 1cd5fcd
Showing
18 changed files
with
227 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/java/micdoodle8/mods/galacticraft/api/recipe/RocketFuel.java
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
src/main/java/micdoodle8/mods/galacticraft/api/recipe/RocketFuelRecipe.java
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
src/main/java/micdoodle8/mods/galacticraft/api/recipe/RocketFuels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package micdoodle8.mods.galacticraft.api.recipe; | ||
|
||
import java.util.Set; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.SetMultimap; | ||
|
||
import micdoodle8.mods.galacticraft.api.entity.IFuelable; | ||
|
||
/** | ||
* Handles which fluids can be used to fuel an {@link IFuelable} object. This is used by the Fuel Loader but you can use | ||
* this for other things too. | ||
* | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public class RocketFuels { | ||
|
||
private static final SetMultimap<Class<? extends IFuelable>, String> FUEL_MAP = HashMultimap.create(); | ||
|
||
/** | ||
* Allow a fluid to be used as fuel | ||
* | ||
* @param fluid must be either of type {@link String}, {@link Fluid} or {@link FluidStack} | ||
* @return {@code true} if the fuel map changed | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public static boolean addFuel(@Nonnull Class<? extends IFuelable> fuelableClass, @Nonnull Object fluid) { | ||
return FUEL_MAP.put(fuelableClass, getFluidName(fluid)); | ||
} | ||
|
||
/** | ||
* Remove a fluid from the fuelable's allowed-list of fuels | ||
* | ||
* @param fluid must be either of type {@link String}, {@link Fluid} or {@link FluidStack} | ||
* @return {@code true} if the fuel map changed | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public static boolean removeFuel(@Nonnull Class<? extends IFuelable> fuelableClass, @Nonnull Object fluid) { | ||
return FUEL_MAP.remove(fuelableClass, getFluidName(fluid)); | ||
} | ||
|
||
/** | ||
* Remove all fluids from the fuelable's allowed-list of fuels | ||
* | ||
* @return the values that were removed (possibly empty). | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public static Set<String> removeFuelable(@Nonnull Class<? extends IFuelable> fuelableClass) { | ||
return FUEL_MAP.removeAll(fuelableClass); | ||
} | ||
|
||
/** | ||
* Check if the given fuel can be used for this fuelable | ||
* | ||
* @param fluid must be either of type {@link String}, {@link Fluid} or {@link FluidStack} | ||
* @return {@code true} if it is usable | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public static boolean isCorrectFuel(@Nonnull IFuelable fuelable, @Nonnull Object fluid) { | ||
return FUEL_MAP.containsEntry(fuelable.getClass(), getFluidName(fluid)); | ||
} | ||
|
||
/** | ||
* Check if the given fuel can be used for any fuelable | ||
* | ||
* @param fluid must be either of type {@link String}, {@link Fluid} or {@link FluidStack} | ||
* @return {@code true} if it is usable | ||
* @since 3.0.70-GTNH | ||
* @author glowredman | ||
*/ | ||
public static boolean isValidFuel(@Nonnull Object fluid) { | ||
return FUEL_MAP.containsValue(getFluidName(fluid)); | ||
} | ||
|
||
private static String getFluidName(Object fluid) { | ||
if (fluid instanceof String fluidName) { | ||
return fluidName; | ||
} | ||
if (fluid instanceof Fluid fluidObj) { | ||
return fluidObj.getName(); | ||
} | ||
if (fluid instanceof FluidStack fluidStack) { | ||
return fluidStack.getFluid().getName(); | ||
} | ||
throw new IllegalArgumentException(fluid + " is not an instace of String, FLuid or FluidStack!"); | ||
} | ||
|
||
private RocketFuels() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.