IFluidRegisterListener

This commit is contained in:
Boblet 2025-06-20 14:47:15 +02:00
parent 381ef334b2
commit c2354adbc3
12 changed files with 181 additions and 108 deletions

View File

@ -28,6 +28,9 @@
* New chemical plant now has sound
* Old chemical plant and factory have been renamed and their recipes removed
* The new recipe selector no longer changes recipe instantly on click, rather as soon as the selector GUI is closed. This should prevent issues when misclicking, which would destroy buffered fluids
* The memespoon is now safe(tm)
* Instead of using a bugged instakill implementation, a fall distance of >2 now deals 50 extra melee damage
* Instead of blowing up like a nuke with a fall distance of >20, it now explodes similarly to a non-HE artillery grenade. This deals 150 damage in an AoE, has armor piercing properties and is, like the original functionality, still lethal to the user
## Fixed
* Chemical plant ports. For real this time.

View File

@ -0,0 +1,9 @@
package api.hbm.fluidmk2;
public interface IFluidRegisterListener {
/**
* Called when the fluid registry initializes all fluids. Use CompatFluidRegistry to create new instances of FluidType, which are automatically registered.
*/
public void onFluidsLoad();
}

View File

@ -43,7 +43,7 @@ public class FluidType {
public int flammability;
public int reactivity;
public EnumSymbol symbol;
public boolean customFluid = false;
public boolean renderWithTint = false;
public static final int ROOM_TEMPERATURE = 20;
@ -81,7 +81,7 @@ public class FluidType {
this.texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/fluids/" + texName + ".png");
this.guiTint = tint;
this.localizedOverride = displayName;
this.customFluid = true;
this.renderWithTint = true;
this.id = id;
Fluids.register(this, id);
@ -95,6 +95,22 @@ public class FluidType {
}
}
/** For CompatFluidRegistry */
public FluidType(String name, int id, int color, int p, int f, int r, EnumSymbol symbol, ResourceLocation texture) {
this.stringId = name;
this.color = color;
this.unlocalized = "hbmfluid." + name.toLowerCase(Locale.US);
this.poison = p;
this.flammability = f;
this.reactivity = r;
this.symbol = symbol;
this.texture = texture;
this.renderWithTint = true;
this.id = id;
Fluids.register(this, id);
}
public FluidType setTemp(int temperature) {
this.temperature = temperature;
return this;

View File

@ -28,12 +28,15 @@ import com.hbm.inventory.fluid.trait.FT_Toxin.*;
import com.hbm.render.util.EnumSymbol;
import com.hbm.util.ArmorRegistry.HazardClass;
import api.hbm.fluidmk2.IFluidRegisterListener;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class Fluids {
public static final Gson gson = new Gson();
public static List<IFluidRegisterListener> additionalListeners = new ArrayList();
public static FluidType NONE;
public static FluidType AIR;
@ -197,8 +200,10 @@ public class Fluids {
private static final HashMap<Integer, FluidType> idMapping = new HashMap();
private static final HashMap<String, FluidType> nameMapping = new HashMap();
/** Inconsequential, only actually used when listing all fluids with niceOrder disabled */
protected static final List<FluidType> registerOrder = new ArrayList();
protected static final List<FluidType> metaOrder = new ArrayList();
/** What's used to list fluids with niceOrder enabled */
public static final List<FluidType> metaOrder = new ArrayList();
public static final FT_Liquid LIQUID = new FT_Liquid();
public static final FT_Viscous VISCOUS = new FT_Viscous();
@ -588,6 +593,8 @@ public class Fluids {
// LEGACY
ACID = PEROXIDE;
for(IFluidRegisterListener listener : additionalListeners) listener.onFluidsLoad();
for(FluidType custom : customFluids) metaOrder.add(custom);

View File

@ -34,10 +34,10 @@ import net.minecraft.item.ItemStack;
public abstract class SerializableRecipe {
public static final Gson gson = new Gson();
public static List<SerializableRecipe> recipeHandlers = new ArrayList<>();
public static List<IRecipeRegisterListener> additionalListeners = new ArrayList<>();
public static List<SerializableRecipe> recipeHandlers = new ArrayList();
public static List<IRecipeRegisterListener> additionalListeners = new ArrayList();
public static Map<String, InputStream> recipeSyncHandlers = new HashMap<>();
public static Map<String, InputStream> recipeSyncHandlers = new HashMap();
public boolean modified = false;

View File

@ -4,11 +4,13 @@ import java.util.List;
import java.util.Random;
import com.google.common.collect.Multimap;
import com.hbm.entity.effect.EntityNukeTorex;
import com.hbm.entity.logic.EntityNukeExplosionMK5;
import com.hbm.entity.projectile.EntityRubble;
import com.hbm.explosion.vanillant.ExplosionVNT;
import com.hbm.explosion.vanillant.standard.EntityProcessorCrossSmooth;
import com.hbm.explosion.vanillant.standard.PlayerProcessorStandard;
import com.hbm.items.ModItems;
import com.hbm.main.MainRegistry;
import com.hbm.particle.helper.ExplosionCreator;
import com.hbm.potion.HbmPotion;
import com.hbm.util.ArmorUtil;
@ -23,21 +25,21 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public class WeaponSpecial extends ItemSword {
Random rand = new Random();
public WeaponSpecial(ToolMaterial p_i45356_1_) {
super(p_i45356_1_);
}
@Override
public EnumRarity getRarity(ItemStack p_77613_1_)
{
@Override
public EnumRarity getRarity(ItemStack p_77613_1_) {
if(this == ModItems.schrabidium_hammer) {
return EnumRarity.rare;
}
@ -47,26 +49,23 @@ public class WeaponSpecial extends ItemSword {
if(this == ModItems.shimmer_sledge || this == ModItems.shimmer_axe) {
return EnumRarity.epic;
}
return EnumRarity.common;
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entity, EntityLivingBase entityPlayer)
{
World world = entity.worldObj;
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entity, EntityLivingBase entityPlayer) {
World world = entity.worldObj;
if(this == ModItems.schrabidium_hammer) {
if (!world.isRemote)
{
entity.setHealth(0.0F);
}
world.playSoundAtEntity(entity, "hbm:weapon.bonk", 3.0F, 1.0F);
if(!world.isRemote) {
entity.setHealth(0.0F);
}
world.playSoundAtEntity(entity, "hbm:weapon.bonk", 3.0F, 1.0F);
}
if(this == ModItems.bottle_opener) {
if (!world.isRemote)
{
if(!world.isRemote) {
int i = rand.nextInt(7);
if(i == 0)
entity.addPotionEffect(new PotionEffect(Potion.blindness.id, 5 * 60 * 20, 0));
@ -76,19 +75,18 @@ public class WeaponSpecial extends ItemSword {
entity.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 5 * 60 * 20, 2));
if(i == 3)
entity.addPotionEffect(new PotionEffect(Potion.confusion.id, 1 * 60 * 20, 0));
}
world.playSoundAtEntity(entity, "random.anvil_land", 3.0F, 1.F);
}
world.playSoundAtEntity(entity, "random.anvil_land", 3.0F, 1.F);
}
if(this == ModItems.ullapool_caber) {
if (!world.isRemote)
{
if(!world.isRemote) {
world.createExplosion(null, entity.posX, entity.posY, entity.posZ, 7.5F, true);
}
}
stack.damageItem(505, entityPlayer);
}
if(this == ModItems.shimmer_sledge) {
Vec3 vec = entityPlayer.getLookVec();
double dX = vec.xCoord * 5;
@ -98,37 +96,37 @@ public class WeaponSpecial extends ItemSword {
entity.motionX += dX;
entity.motionY += dY;
entity.motionZ += dZ;
world.playSoundAtEntity(entity, "hbm:weapon.bang", 3.0F, 1.F);
world.playSoundAtEntity(entity, "hbm:weapon.bang", 3.0F, 1.F);
}
if(this == ModItems.shimmer_axe) {
entity.setHealth(entity.getHealth() / 2);
world.playSoundAtEntity(entity, "hbm:weapon.slice", 3.0F, 1.F);
world.playSoundAtEntity(entity, "hbm:weapon.slice", 3.0F, 1.F);
}
if(this == ModItems.wood_gavel) {
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
}
if(this == ModItems.lead_gavel) {
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
entity.addPotionEffect(new PotionEffect(HbmPotion.lead.id, 15 * 20, 4));
}
if(this == ModItems.diamond_gavel) {
float ded = entity.getMaxHealth() / 3;
entity.setHealth(entity.getHealth() - ded);
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
world.playSoundAtEntity(entity, "hbm:weapon.whack", 3.0F, 1.F);
}
if(this == ModItems.wrench) {
Vec3 vec = entityPlayer.getLookVec();
double dX = vec.xCoord * 0.5;
double dY = vec.yCoord * 0.5;
double dZ = vec.zCoord * 0.5;
@ -136,47 +134,47 @@ public class WeaponSpecial extends ItemSword {
entity.motionX += dX;
entity.motionY += dY;
entity.motionZ += dZ;
world.playSoundAtEntity(entity, "random.anvil_land", 3.0F, 0.75F);
world.playSoundAtEntity(entity, "random.anvil_land", 3.0F, 0.75F);
}
if(this == ModItems.memespoon) {
if(this == ModItems.memespoon && !world.isRemote) {
if(!(entityPlayer instanceof EntityPlayer))
return false;
if(entityPlayer.fallDistance >= 2) {
world.playSoundAtEntity(entity, "hbm:weapon.bang", 3.0F, 0.75F);
entity.setHealth(0);
entity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityPlayer), 50F);
}
if(!(entityPlayer instanceof EntityPlayer))
return false;
if(entityPlayer.fallDistance >= 20 && !((EntityPlayer)entityPlayer).capabilities.isCreativeMode) {
if(!world.isRemote) {
world.spawnEntityInWorld(EntityNukeExplosionMK5.statFac(world, 100, entity.posX, entity.posY, entity.posZ));
EntityNukeTorex.statFacStandard(world, entity.posX, entity.posY, entity.posZ, 100);
}
if(entityPlayer.fallDistance >= 20 && !((EntityPlayer) entityPlayer).capabilities.isCreativeMode) {
ExplosionVNT vnt = new ExplosionVNT(world, entity.posX, entity.posY + entity.height / 2D, entity.posZ, 15, entityPlayer);
vnt.setEntityProcessor(new EntityProcessorCrossSmooth(1, 150).setupPiercing(25, 0.5F));
vnt.setPlayerProcessor(new PlayerProcessorStandard());
ExplosionCreator.composeEffectSmall(world, entity.posX, entity.posY + entity.height / 2D, entity.posZ);
vnt.explode();
}
}
if(this == ModItems.stopsign || this == ModItems.sopsign)
world.playSoundAtEntity(entity, "hbm:weapon.stop", 1.0F, 1.0F);
world.playSoundAtEntity(entity, "hbm:weapon.stop", 1.0F, 1.0F);
return false;
}
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int i, float f1, float f2, float f3)
{
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int i, float f1, float f2, float f3) {
if(this == ModItems.shimmer_sledge) {
if(world.getBlock(x, y, z) != Blocks.air && world.getBlock(x, y, z).getExplosionResistance(null) < 6000) {
EntityRubble rubble = new EntityRubble(world);
rubble.posX = x + 0.5F;
rubble.posY = y;
rubble.posZ = z + 0.5F;
rubble.setMetaBasedOnBlock(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z));
Vec3 vec = player.getLookVec();
double dX = vec.xCoord * 5;
double dY = vec.yCoord * 5;
@ -185,22 +183,22 @@ public class WeaponSpecial extends ItemSword {
rubble.motionX += dX;
rubble.motionY += dY;
rubble.motionZ += dZ;
world.playSoundAtEntity(rubble, "hbm:weapon.bang", 3.0F, 1.0F);
if(!world.isRemote) {
world.spawnEntityInWorld(rubble);
world.playSoundAtEntity(rubble, "hbm:weapon.bang", 3.0F, 1.0F);
if(!world.isRemote) {
world.spawnEntityInWorld(rubble);
world.func_147480_a(x, y, z, false);
}
}
}
return true;
}
if(this == ModItems.shimmer_axe) {
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "hbm:weapon.kapeng", 3.0F, 1.0F);
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "hbm:weapon.kapeng", 3.0F, 1.0F);
if(!world.isRemote) {
if(!world.isRemote) {
if(world.getBlock(x, y, z) != Blocks.air && world.getBlock(x, y, z).getExplosionResistance(null) < 6000) {
world.func_147480_a(x, y, z, false);
}
@ -210,17 +208,16 @@ public class WeaponSpecial extends ItemSword {
if(world.getBlock(x, y - 1, z) != Blocks.air && world.getBlock(x, y - 1, z).getExplosionResistance(null) < 6000) {
world.func_147480_a(x, y - 1, z, false);
}
}
}
return true;
}
return false;
}
@Override
public Multimap getItemAttributeModifiers()
{
Multimap multimap = super.getItemAttributeModifiers();
}
@Override
public Multimap getItemAttributeModifiers() {
Multimap multimap = super.getItemAttributeModifiers();
if(this == ModItems.schrabidium_hammer) {
multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", -0.5, 1));
}
@ -230,24 +227,23 @@ public class WeaponSpecial extends ItemSword {
if(this == ModItems.wrench || this == ModItems.wrench_flipped) {
multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", -0.1, 1));
}
return multimap;
}
@Override
return multimap;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean b) {
if(entity instanceof EntityPlayer) {
if(ArmorUtil.checkForFiend((EntityPlayer) entity)) {
((EntityPlayer) entity).triggerAchievement(MainRegistry.achFiend);
} else if(ArmorUtil.checkForFiend2((EntityPlayer) entity)) {
((EntityPlayer) entity).triggerAchievement(MainRegistry.achFiend2);
}
}
}
if(entity instanceof EntityPlayer) {
if(ArmorUtil.checkForFiend((EntityPlayer) entity)) {
((EntityPlayer) entity).triggerAchievement(MainRegistry.achFiend);
} else if(ArmorUtil.checkForFiend2((EntityPlayer) entity)) {
((EntityPlayer) entity).triggerAchievement(MainRegistry.achFiend2);
}
}
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool)
{
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool) {
if(this == ModItems.schrabidium_hammer) {
list.add("Even though it says \"+1000000000");
list.add("damage\", it's actually \"onehit anything\"");

View File

@ -83,7 +83,7 @@ public class RenderFluidTank extends TileEntitySpecialRenderer implements IItemR
public String getTextureFromType(FluidType type) {
if(type.customFluid) {
if(type.renderWithTint) {
int color = type.getTint();
double r = ((color & 0xff0000) >> 16) / 255D;
double g = ((color & 0x00ff00) >> 8) / 255D;

View File

@ -9,6 +9,7 @@ import java.util.function.Consumer;
import api.hbm.energymk2.IEnergyHandlerMK2;
import api.hbm.energymk2.IEnergyReceiverMK2;
import api.hbm.fluidmk2.IFluidRegisterListener;
import api.hbm.fluidmk2.IFluidUserMK2;
import api.hbm.recipe.IRecipeRegisterListener;
@ -16,6 +17,7 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.entity.missile.EntityMissileCustom;
import com.hbm.explosion.ExplosionNukeSmall;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.recipes.loader.SerializableRecipe;
import com.hbm.items.weapon.ItemCustomMissilePart.WarheadType;
@ -198,6 +200,15 @@ public class CompatExternal {
public static void registerRecipeRegisterListener(IRecipeRegisterListener listener) {
SerializableRecipe.additionalListeners.add(listener);
}
/**
* Registers an IFluidRegisterListener which is called every time the fluid list is loaded, either during startup or when the refresh command is used.
* Ensures that fluids are registered when they should, instead of being purged permanently when the system reloads.
* @param listener
*/
public static void registerFluidRegisterListener(IFluidRegisterListener listener) {
Fluids.additionalListeners.add(listener);
}
public static void compatExamples() {
// Makes all cows be targeted by turrets if player mode is active in addition to the existing rules. Applies to all entities that inherit EntityCow.

View File

@ -0,0 +1,17 @@
package com.hbm.util;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.render.util.EnumSymbol;
import net.minecraft.util.ResourceLocation;
public class CompatFluidRegistry {
/** Registers a fluid with a custom ID. */
public static FluidType registerFluid(String name, int id, int color, int p, int f, int r, EnumSymbol symbol, ResourceLocation texture) {
FluidType type = new FluidType(name, id, color, p, f, r, symbol, texture);
Fluids.metaOrder.add(type);
return type;
}
}

View File

@ -29,6 +29,8 @@ import com.hbm.inventory.recipes.anvil.AnvilRecipes;
import com.hbm.inventory.recipes.anvil.AnvilRecipes.AnvilConstructionRecipe;
import com.hbm.inventory.recipes.anvil.AnvilRecipes.AnvilOutput;
import com.hbm.inventory.recipes.anvil.AnvilRecipes.OverlayType;
import com.hbm.inventory.recipes.loader.GenericRecipe;
import com.hbm.inventory.recipes.loader.GenericRecipes.IOutput;
import com.hbm.items.machine.ItemStamp.StampType;
import com.hbm.util.Tuple.Pair;
import com.hbm.util.Tuple.Triplet;
@ -70,8 +72,7 @@ public class CompatRecipeRegistry {
SolderingRecipes.recipes.add(new SolderingRecipe(output, time, power, fluid, copyFirst(toppings, 3), copyFirst(pcb, 2), copyFirst(solder, 1)));
}
/** Chemplant recipes need unique IDs, game will crash when an ID collision is detected! */
public static void registerChemplant(int id, String name, int duration, AStack[] inputItems, FluidStack[] inputFluids, ItemStack[] outputItems, FluidStack[] outputFluids) {
@Deprecated public static void registerChemplant(int id, String name, int duration, AStack[] inputItems, FluidStack[] inputFluids, ItemStack[] outputItems, FluidStack[] outputFluids) {
ChemRecipe recipe = new ChemRecipe(id, name, duration);
if(inputItems != null) recipe.inputItems(copyFirst(inputItems, 4));
if(inputFluids != null) recipe.inputFluids(copyFirst(inputFluids, 2));
@ -79,6 +80,18 @@ public class CompatRecipeRegistry {
if(outputFluids != null) recipe.outputFluids(copyFirst(outputFluids, 2));
ChemplantRecipes.recipes.add(recipe);
}
/** Chemical plant recipe needs a unique name for the registry. Zero length arrays should stay null*/
public static void registerChemicalPlant(String name, boolean named, ItemStack icon, int duration, long power, AStack[] inputItems, FluidStack[] inputFluids, IOutput[] outputItems, FluidStack[] outputFluids) {
GenericRecipe recipe = new GenericRecipe(name).setDuration(duration).setPower(power);
if(named) recipe.setNamed();
if(icon != null) recipe.setIcon(icon);
if(inputItems != null && inputItems.length > 0) recipe.inputItems(inputItems);
if(inputFluids != null && inputFluids.length > 0) recipe.inputFluids(inputFluids);
if(outputItems != null && outputItems.length > 0) recipe.outputItems(outputItems);
if(outputFluids != null && outputFluids.length > 0) recipe.outputFluids(outputFluids);
ChemicalPlantRecipes.INSTANCE.register(recipe);
}
/** Either solid or liquid output can be null */
public static void registerCombination(AStack input, ItemStack output, FluidStack fluid) {
@ -223,6 +236,7 @@ public class CompatRecipeRegistry {
AmmoPressRecipes.recipes.add(new AmmoPressRecipe(output, input));
}
/** Assembler recipes are identified by the output as a ComparableStack, so no two recipes can share output. */
public static void registerAssembler(ItemStack output, AStack[] input, int time) {
AssemblerRecipes.makeRecipe(new ComparableStack(output), copyFirst(input, 12), time);
}

View File

@ -5492,7 +5492,7 @@ tile.machine_catalytic_reformer.name=Catalytic Reformer
tile.machine_centrifuge.name=Centrifuge
tile.machine_chemfac.name=Chemical Factory (Legacy)
tile.machine_chemical_factory.name=Chemical Factory
tile.machine_chemical_factory.desc=Quadruple chemical plant.$Recipes process twice as fast,$but needs twice as much power.$Needs to be cooled with water,$produces low-pressure steam.
tile.machine_chemical_factory.desc=Quadruple chemical plant.$Recipes process twice as fast,$but need twice as much power.$Needs to be cooled with water,$produces low-pressure steam.
tile.machine_chemical_plant.name=Chemical Plant
tile.machine_chemplant.name=Chemical Plant (Legacy)
tile.machine_chungus.name=Leviathan Steam Turbine

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B