Skip to content

Commit

Permalink
Rework Rocket Fuel API (#77)
Browse files Browse the repository at this point in the history
* Fix oversights of last PR

See @eigenraven's review of #76

* Update dependencies

* Rework rocket fuel API
  • Loading branch information
glowredman authored Jun 12, 2023
1 parent 4a0c7b3 commit 1cd5fcd
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 171 deletions.
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dependencies {
implementation('com.github.GTNewHorizons:GT5-Unofficial:5.09.42.71:dev')
implementation('com.github.GTNewHorizons:TinkersConstruct:1.9.26-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.45-GTNH:dev')
implementation('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.82:dev')
implementation('com.github.GTNewHorizons:TinkersConstruct:1.9.36-GTNH:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.54-GTNH:dev')
api('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')

compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-195-GTNH:api')
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-223-GTNH:api')
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.33:api')

compileOnly('curse.maven:cofh-lib-220333:2388748')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,11 @@ public void onUpdate() {

AxisAlignedBB box = this.boundingBox.expand(0.2D, 0.2D, 0.2D);

final List<?> var15 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box);
final List<Entity> entitiesInAABB = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box);

if (var15 != null && !var15.isEmpty()) {
for (Object element : var15) {
final Entity var17 = (Entity) element;

if (var17 != this.riddenByEntity) {
var17.applyEntityCollision(this);
}
for (Entity entity : entitiesInAABB) {
if (entity != this.riddenByEntity) {
entity.applyEntityCollision(this);
}
}

Expand Down

This file was deleted.

This file was deleted.

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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
version = Constants.VERSION,
acceptedMinecraftVersions = "[1.7.10]",
useMetadata = true,
dependencies = "required-after:Forge@[10.12.2.1147,); required-after:FML@[7.2.217.1147,); before:GalaxySpace; after:IC2; after:TConstruct; after:Mantle; after:BuildCraft|Core; after:BuildCraft|Energy; after:PlayerAPI@[1.3,)",
dependencies = "required-after:NotEnoughItems;before:GalaxySpace;after:IC2;after:TConstruct;after:Mantle;after:BuildCraft|Core;after:BuildCraft|Energy;after:PlayerAPI@[1.3,)",
guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore")
public class GalacticraftCore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,16 @@ public void onUpdate() {
this.motionY *= 0.9599999785423279D;
this.motionZ *= 0.9599999785423279D;

final List<?> var3 = this.worldObj
final List<Entity> entitiesInAABB = this.worldObj
.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(1.0D, 0.5D, 1.0D));

if (var3 != null) {
for (Object element : var3) {
final Entity var5 = (Entity) element;

if (var5 instanceof EntityLivingBase && !var5.isDead
&& !var5.isBurning()
&& !var5.equals(this.ridingEntity)) {
var5.setFire(3);
GalacticraftCore.packetPipeline.sendToServer(
new PacketSimple(EnumSimplePacket.S_SET_ENTITY_FIRE, new Object[] { var5.getEntityId() }));
}
for (Entity entity : entitiesInAABB) {
if (entity instanceof EntityLivingBase && !entity.isDead
&& !entity.isBurning()
&& !entity.equals(this.ridingEntity)) {
entity.setFire(3);
GalacticraftCore.packetPipeline.sendToServer(
new PacketSimple(EnumSimplePacket.S_SET_ENTITY_FIRE, new Object[] { entity.getEntityId() }));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,16 @@ public void onUpdate() {
this.motionY *= 0.9599999785423279D;
this.motionZ *= 0.9599999785423279D;

final List<?> var3 = this.worldObj
final List<Entity> entitiesInAABB = this.worldObj
.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(1.0D, 0.5D, 1.0D));

if (var3 != null) {
for (Object element : var3) {
final Entity var5 = (Entity) element;

if (var5 instanceof EntityLivingBase && !var5.isDead
&& !var5.isBurning()
&& !var5.equals(this.ridingEntity)) {
var5.setFire(3);
GalacticraftCore.packetPipeline.sendToServer(
new PacketSimple(EnumSimplePacket.S_SET_ENTITY_FIRE, new Object[] { var5.getEntityId() }));
}
for (Entity entity : entitiesInAABB) {
if (entity instanceof EntityLivingBase && !entity.isDead
&& !entity.isBurning()
&& !entity.equals(this.ridingEntity)) {
entity.setFire(3);
GalacticraftCore.packetPipeline.sendToServer(
new PacketSimple(EnumSimplePacket.S_SET_ENTITY_FIRE, new Object[] { entity.getEntityId() }));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ private String getStatus() {
if (this.fuelLoader.fuelTank.getFluid() == null || this.fuelLoader.fuelTank.getFluid().amount == 0) {
return EnumColor.DARK_RED + GCCoreUtil.translate("gui.status.nofuel.name");
}
if (!this.fuelLoader.coorectTier) {
return EnumColor.DARK_RED + GCCoreUtil.translate("gui.status.lowtier.name");
if (!this.fuelLoader.correctFuel) {
return EnumColor.DARK_RED + GCCoreUtil.translate("gui.status.wrongfuel.name");
}
return this.fuelLoader.getGUIstatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public void afterSetRotationAngles(float par1, float par2, float par3, float par
}
}

final List<?> l = player.worldObj.getEntitiesWithinAABBExcludingEntity(
final List<Entity> entitiesInAABB = player.worldObj.getEntitiesWithinAABBExcludingEntity(
player,
AxisAlignedBB.getBoundingBox(
player.posX - 20,
Expand All @@ -418,10 +418,8 @@ public void afterSetRotationAngles(float par1, float par2, float par3, float par
200,
player.posZ + 20));

for (Object element : l) {
final Entity e = (Entity) element;

if (e instanceof EntityTieredRocket ship) {
for (Entity entity : entitiesInAABB) {
if (entity instanceof EntityTieredRocket ship) {
if (ship.riddenByEntity != null && !ship.riddenByEntity.equals(player)
&& (ship.getLaunched() || ship.timeUntilLaunch < 390)) {
this.modelPlayer.bipedRightArm.rotateAngleZ -= (float) (Math.PI / 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public void setRotationAngles(float par1, float par2, float par3, float par4, fl
this.grayOxygenTanks[1].rotateAngleY = this.bipedBody.rotateAngleY;
this.grayOxygenTanks[1].rotateAngleZ = this.bipedBody.rotateAngleZ;

final List<?> l = player.worldObj.getEntitiesWithinAABBExcludingEntity(
final List<Entity> entitiesInAABB = player.worldObj.getEntitiesWithinAABBExcludingEntity(
player,
AxisAlignedBB.getBoundingBox(
player.posX - 20,
Expand All @@ -543,10 +543,8 @@ public void setRotationAngles(float par1, float par2, float par3, float par4, fl
200,
player.posZ + 20));

for (Object element : l) {
final Entity e = (Entity) element;

if (e instanceof EntityTieredRocket ship) {
for (Entity entity : entitiesInAABB) {
if (entity instanceof EntityTieredRocket ship) {
if (ship.riddenByEntity != null && !ship.riddenByEntity.equals(player)
&& (ship.getLaunched() || ship.timeUntilLaunch < 390)) {
this.bipedRightArm.rotateAngleZ -= (float) (Math.PI / 8) + MathHelper.sin(par3 * 0.9F) * 0.2F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket;
import micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase;
import micdoodle8.mods.galacticraft.api.recipe.ISchematicPage;
import micdoodle8.mods.galacticraft.api.recipe.RocketFuelRecipe;
import micdoodle8.mods.galacticraft.api.recipe.SchematicEvent.FlipPage;
import micdoodle8.mods.galacticraft.api.recipe.SchematicEvent.Unlock;
import micdoodle8.mods.galacticraft.api.recipe.SchematicRegistry;
Expand Down Expand Up @@ -907,11 +906,18 @@ public void onSoundPlayed(PlaySoundEvent17 event) {
@SubscribeEvent
public void onItemTooltipEvent(ItemTooltipEvent event) {
FluidStack fluidStack = StackInfo.getFluid(event.itemStack);
int fuelTier = RocketFuelRecipe.getfuelMaxTier(fluidStack);
if (fuelTier >= 8) {
event.toolTip.add(StatCollector.translateToLocal("tooltip.rocket_fuel_tier_max"));
} else if (fuelTier != 0) {
event.toolTip.add(StatCollector.translateToLocalFormatted("tooltip.rocket_fuel_tier", fuelTier));
if (fluidStack == null) {
return;
}
switch (fluidStack.getFluid().getName()) {
case "fluid.rocketfuelmixb", "nitrofuel" -> event.toolTip
.add(StatCollector.translateToLocalFormatted("tooltip.rocket_fuel_tier", 2));
case "fluid.rocketfuelmixd" -> event.toolTip
.add(StatCollector.translateToLocalFormatted("tooltip.rocket_fuel_tier", 4));
case "fluid.rocketfuelmixc" -> event.toolTip
.add(StatCollector.translateToLocalFormatted("tooltip.rocket_fuel_tier", 6));
case "fluid.rocketfuelmixa", "rocket_fuel" -> event.toolTip
.add(StatCollector.translateToLocal("tooltip.rocket_fuel_tier_max"));
}
}

Expand Down
Loading

0 comments on commit 1cd5fcd

Please sign in to comment.