Fixed ICBM integration

This commit fixes a bug where ICBM explosions would not trigger Trinity
explosions on servers.

Event handlers were only being registered on the client side which means
that integration would only work in singleplayer. Also most of the ICBM
code was commented out so I assume this was mid rewrite or it was
causing build errors.

Event handlers have been split into 3 classes:
    ClientEvents - Events that are only clientside, currently used
for the TextureSwitchEvent handler
    CommonEvents - Events that occur on both the server and client,
currently handles player tick events
    ICBMEvents - Events related to ICBM integration, handles adding the
warning tooltip and the Explosion.Start hook

Explosion code has been updated to use the new Explosion api, most
fields being used were made private.

The ICBMEvents handler is only registered if ICBM is acually enabled,
removing the need to check in the event itself
This commit is contained in:
Thomas Muller 2021-10-21 20:32:38 -04:00
parent 71dddda6cb
commit d8d09ec90c
Signed by: thomas
GPG key ID: AF006EB730564952
10 changed files with 276 additions and 39 deletions

View file

@ -15,7 +15,6 @@ import trinity.config.TrinityConfig;
import trinity.entities.EntityFalloutRain; import trinity.entities.EntityFalloutRain;
import trinity.entities.EntityNuclearCloud; import trinity.entities.EntityNuclearCloud;
import trinity.entities.EntityNuclearExplosion; import trinity.entities.EntityNuclearExplosion;
import trinity.entities.EntityShockwave;
import trinity.entities.EntityThermonuclearBlast; import trinity.entities.EntityThermonuclearBlast;
import trinity.explosion.ExplosionNukeGeneric; import trinity.explosion.ExplosionNukeGeneric;
import trinity.init.ModBlocks; import trinity.init.ModBlocks;

View file

@ -20,7 +20,6 @@ import trinity.entities.EntityBlackHole;
import trinity.entities.EntityFalloutRain; import trinity.entities.EntityFalloutRain;
import trinity.entities.EntityNuclearCloud; import trinity.entities.EntityNuclearCloud;
import trinity.entities.EntityNuclearExplosion; import trinity.entities.EntityNuclearExplosion;
import trinity.entities.EntityShockwave;
import trinity.entities.EntityThermonuclearBlast; import trinity.entities.EntityThermonuclearBlast;
import trinity.explosion.ExplosionNukeGeneric; import trinity.explosion.ExplosionNukeGeneric;
import trinity.init.ModBlocks; import trinity.init.ModBlocks;

View file

@ -17,7 +17,6 @@ import trinity.entities.EntityFalloutRain;
import trinity.entities.EntityBlackHole; import trinity.entities.EntityBlackHole;
import trinity.entities.EntityNuclearCloud; import trinity.entities.EntityNuclearCloud;
import trinity.entities.EntityNuclearExplosion; import trinity.entities.EntityNuclearExplosion;
import trinity.entities.EntityShockwave;
import trinity.entities.EntityThermonuclearBlast; import trinity.entities.EntityThermonuclearBlast;
import trinity.explosion.ExplosionNukeGeneric; import trinity.explosion.ExplosionNukeGeneric;
import trinity.init.ModBlocks; import trinity.init.ModBlocks;

View file

@ -31,7 +31,6 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import trinity.handler.Vec3; import trinity.handler.Vec3;
import trinity.init.ModDamageSources; import trinity.init.ModDamageSources;
import trinity.init.ModEvents;
//import net.minecraft.world.WorldSettings.GameType; //import net.minecraft.world.WorldSettings.GameType;
//import net.minecraftforge.common.util.ForgeDirection; //import net.minecraftforge.common.util.ForgeDirection;

View file

@ -33,7 +33,6 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import trinity.handler.Vec3; import trinity.handler.Vec3;
import trinity.init.ModDamageSources; import trinity.init.ModDamageSources;
import trinity.init.ModEvents;
public class ExplosionThermonuclear { public class ExplosionThermonuclear {

View file

@ -0,0 +1,23 @@
package trinity.init;
import net.minecraftforge.fml.common.Mod;
import trinity.Global;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import trinity.util.Reference;
@Mod.EventBusSubscriber(modid= Reference.MODID)
public class ClientEvents {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureStitch(TextureStitchEvent.Pre evt) {
evt.getMap().registerSprite(new ResourceLocation(Global.MOD_ID, "blocks/liquid_still"));
evt.getMap().registerSprite(new ResourceLocation(Global.MOD_ID, "blocks/liquid_flow"));
}
}

View file

@ -0,0 +1,133 @@
package trinity.init;
import java.util.List;
import net.minecraftforge.fml.common.Mod;
import nc.capability.radiation.entity.IEntityRads;
import nc.config.NCConfig;
import nc.network.PacketHandler;
import nc.network.radiation.PlayerRadsUpdatePacket;
import nc.radiation.RadSources;
import nc.radiation.RadiationHelper;
import net.minecraftforge.fml.relauncher.SideOnly;
import trinity.items.RadioactiveSource2;
import trinity.items.ShieldedContainerItem;
import trinity.radiation.FalloutSavedData;
import trinity.tiles.TileEntityShieldedContainer;
import trinity.util.Reference;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
@Mod.EventBusSubscriber(modid=Reference.MODID)
public class CommonEvents {
public static String Pu_238 = "c95fdfd3-bea7-4255-a44b-d21bc3df95e3";
@SubscribeEvent(priority=EventPriority.LOW)
@SideOnly(Side.SERVER)
public void sealedRadiationSources(TickEvent.PlayerTickEvent event) {
if (!NCConfig.radiation_enabled_public) { return; }
if (event.phase != TickEvent.Phase.START ||
((event.player.world.getTotalWorldTime() + event.player.getUniqueID().hashCode()) %
NCConfig.radiation_player_tick_rate) != 0) { return; }
if (event.player instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP)event.player;
IEntityRads playerRads = RadiationHelper.getEntityRadiation(player);
if (player.getUniqueID().toString().equals(Pu_238) )
{
if(playerRads.getInternalRadiationResistance()<500)
{
playerRads.setInternalRadiationResistance(2800);
}
}
double radiationLevel = 0D;
FalloutSavedData data = FalloutSavedData.getData(event.player.world);
if(data.worldObj == null) {
data.worldObj = event.player.world;
}
radiationLevel += data.getRadNumFromCoord((int)player.posX, (int)player.posZ);
List Tes = player.world.loadedTileEntityList;
for (int i = 0; i < Tes.size(); ++i)
{
TileEntity tile = (TileEntity) Tes.get(i);
int tileDim = tile.getWorld().provider.getDimension();
int playerDim = player.getEntityWorld().provider.getDimension();
if(tile instanceof TileEntityShieldedContainer && (tileDim == playerDim))
{
TileEntityShieldedContainer te = ((TileEntityShieldedContainer)tile);
double X = player.posX;
double Y = player.posY;
double Z = player.posZ;
double dist = te.getDistanceSq(X, Y, Z);
radiationLevel += Math.min(te.getRadiation(), (te.getRadiation()/dist));
//System.out.println("Radioactivity: "+te.getRadioactivity()+" Rad/t");
}
}
if (!player.getUniqueID().toString().equals(Pu_238))
{
List entities = player.world.playerEntities;
for (int i = 0; i < entities.size(); ++i)
{
EntityPlayer p = (EntityPlayer) entities.get(i);
if (p.getUniqueID().toString().equals(Pu_238) )
{
double X = player.posX;
double Y = player.posY;
double Z = player.posZ;
double dist = p.getDistanceSq(X, Y, Z);
radiationLevel += Math.min(RadSources.PLUTONIUM_238, (RadSources.PLUTONIUM_238/dist));
}
}
}
InventoryPlayer inventory = player.inventory;
for (ItemStack stack : inventory.mainInventory) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
/*if(Trinity.QMDLoaded)
{
if(item instanceof RadioactiveSource)
{
radiationLevel += (((RadioactiveSource)item).rads)*stack.getCount();
//System.out.println("Radioactivity: "+radiationLevel);
}
}*/
if(item instanceof RadioactiveSource2)
{
radiationLevel += (((RadioactiveSource2)item).rads)*stack.getCount();
//System.out.println("Radioactivity: "+radiationLevel);
}
if(item instanceof ShieldedContainerItem)
{
radiationLevel += (((ShieldedContainerItem)item).getRadiation(stack))*stack.getCount();
}
}
}
double appliedRads = RadiationHelper.addRadsToEntity(playerRads, player, radiationLevel, false, false, NCConfig.radiation_player_tick_rate);
playerRads.setRadiationLevel(playerRads.getRadiationLevel() + appliedRads);
//System.out.println("Radiation: "+playerRads.getRadiationLevel()+" Rad/t");
//System.out.println("Adjusted Radiation: "+playerRads.getRadiationLevel()/3+" Rad/t");
PacketHandler.instance.sendTo(new PlayerRadsUpdatePacket(playerRads), player);
}
}
}

View file

@ -0,0 +1,110 @@
package trinity.init;
import java.util.List;
import icbm.classic.api.EnumTier;
import icbm.classic.api.ExplosiveRefs;
import icbm.classic.content.blast.BlastEMP;
import icbm.classic.content.blast.threaded.BlastAntimatter;
import icbm.classic.content.blast.threaded.BlastNuclear;
import icbm.classic.content.blocks.explosive.ItemBlockExplosive;
import icbm.classic.content.items.ItemMissile;
import trinity.Trinity;
import trinity.config.TrinityConfig;
import trinity.entities.EntityNuclearCloud;
import trinity.entities.EntityNuclearExplosion;
import trinity.explosion.ExplosionNukeGeneric;
import trinity.util.Reference;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Mod.EventBusSubscriber(modid=Reference.MODID)
public class ICBMEvents {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void addAdditionalTooltips(ItemTooltipEvent event) {
if(Trinity.ICBMLoaded)
{
ItemStack stack = event.getItemStack();
Item item = stack.getItem();
if(item instanceof ItemBlockExplosive || item instanceof ItemMissile)
{
if(stack.getItemDamage() == ExplosiveRefs.NUCLEAR.getRegistryID())
{
addNukeTooltip(event.getToolTip(), stack);
}
}
}
}
@SideOnly(Side.CLIENT)
private static void addNukeTooltip(List<String> tooltip, ItemStack stack) {
tooltip.add(TextFormatting.RED+"Warning: Trinity installed. ICBM nuclear explosives cause Trinity's explosions instead of ICBM's");
}
@SubscribeEvent
// @SideOnly(Side.SERVER)
public void explosion(ExplosionEvent.Start event)
{
World world = event.getWorld();
Explosion exp = event.getExplosion();
Vec3d position = exp.getPosition();
if(exp instanceof BlastNuclear)
{
if(((BlastNuclear)exp).getExplosiveData().getTier()==EnumTier.THREE)
{
event.setCanceled(true);
EntityNuclearCloud entity2 = new EntityNuclearCloud(world, 1000, (Math.min(TrinityConfig.icbm_radius,TrinityConfig.max_radius)*2) * 0.005F);
entity2.posX = position.x;
entity2.posY = position.y;
entity2.posZ = position.z;
world.spawnEntity(entity2);
// world.setBlockToAir(pos);
new BlastEMP().setBlastWorld(event.getWorld()).setBlastSource(exp.getExplosivePlacedBy()).setBlastPosition(((BlastNuclear) exp).location.x(), ((BlastNuclear) exp).location.y(), ((BlastNuclear) exp).location.z())
.setBlastSize(((BlastNuclear) exp).getBlastRadius()*2)
.setExplosiveData(ExplosiveRefs.EMP)
.buildBlast().runBlast();
ExplosionNukeGeneric.irradiate(world, (int)position.x, (int)position.y, (int)position.z, Math.min(TrinityConfig.icbm_radius,TrinityConfig.max_radius)*2);
world.spawnEntity(EntityNuclearExplosion.statFac(world, Math.min(TrinityConfig.icbm_radius,TrinityConfig.max_radius), position.x, position.y, position.z));
//System.out.println("If you are seeing this line, this means your blast detector is at least partially working.");
}
}
else if(exp instanceof BlastAntimatter)
{
if(((BlastNuclear)exp).getExplosiveData().getTier()==EnumTier.THREE)
{
event.setCanceled(true);
EntityNuclearCloud entity2 = new EntityNuclearCloud(world, 1000, (Math.min(TrinityConfig.antimatter_radius,TrinityConfig.max_radius)*2) * 0.005F);
entity2.posX = position.x;
entity2.posY = position.y;
entity2.posZ = position.z;
world.spawnEntity(entity2);
// exp.world.setBlockToAir(pos);
ExplosionNukeGeneric.irradiate(world, (int)position.x, (int)position.y, (int)position.z, Math.min(TrinityConfig.antimatter_radius,TrinityConfig.max_radius)*6);
world.spawnEntity(EntityNuclearExplosion.statFacAntimatter(world, Math.min(TrinityConfig.antimatter_radius,TrinityConfig.max_radius), position.x, position.y, position.z));
new BlastEMP().setBlastWorld(event.getWorld()).setBlastSource(exp.getExplosivePlacedBy()).setBlastPosition(((BlastNuclear) exp).location.x(), ((BlastNuclear) exp).location.y(), ((BlastNuclear) exp).location.z())
.setBlastSize(((BlastNuclear) exp).getBlastRadius()*2)
.setExplosiveData(ExplosiveRefs.EMP)
.buildBlast().runBlast();
//System.out.println("If you are seeing this line, this means your blast detector is at least partially working.");
}
}
}
}

View file

@ -2,10 +2,7 @@ package trinity.proxy;
import java.util.List; import java.util.List;
import nc.handler.TooltipHandler;
import nc.render.BlockHighlightHandler;
import trinity.Global; import trinity.Global;
import trinity.Trinity;
import trinity.config.TrinityConfig; import trinity.config.TrinityConfig;
import trinity.entities.EntityBlackHole; import trinity.entities.EntityBlackHole;
import trinity.entities.EntityDirtyBomb; import trinity.entities.EntityDirtyBomb;
@ -15,12 +12,11 @@ import trinity.entities.EntityThermalBlast;
import trinity.fluid.TrinityFluids; import trinity.fluid.TrinityFluids;
import trinity.handler.INuclearEffect; import trinity.handler.INuclearEffect;
import trinity.init.ModBlocks; import trinity.init.ModBlocks;
import trinity.init.ModEvents;
import trinity.init.ModItems; import trinity.init.ModItems;
import trinity.init.ClientEvents;
import trinity.render.AdvancedModelLoader; import trinity.render.AdvancedModelLoader;
import trinity.render.HmfModelLoader; import trinity.render.HmfModelLoader;
import trinity.render.entity.RenderBlackHole; import trinity.render.entity.RenderBlackHole;
import trinity.render.entity.RenderFallout;
import trinity.render.entity.RenderFalloutRainFactory; import trinity.render.entity.RenderFalloutRainFactory;
import trinity.render.entity.RenderNuclearExplosion; import trinity.render.entity.RenderNuclearExplosion;
import trinity.render.entity.RenderPrimedDirtyBomb; import trinity.render.entity.RenderPrimedDirtyBomb;
@ -40,7 +36,6 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@ -48,7 +43,6 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
public class ClientProxy extends CommonProxy { public class ClientProxy extends CommonProxy {
@ -62,8 +56,7 @@ private final Minecraft mc = Minecraft.getMinecraft();
ModItems.registerRenders(); ModItems.registerRenders();
ModBlocks.registerRenders(); ModBlocks.registerRenders();
MinecraftForge.EVENT_BUS.register(new ModEvents()); MinecraftForge.EVENT_BUS.register(new ClientEvents());
//MinecraftForge.EVENT_BUS.register(new ICBMEvents());
TrinityFluids.renderFluids(); TrinityFluids.renderFluids();
} }

View file

@ -1,42 +1,22 @@
package trinity.proxy; package trinity.proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import com.google.common.collect.Ordering;
import nc.radiation.RadSources;
import nc.recipe.NCRecipes;
import nc.recipe.ingredient.OreIngredient;
import trinity.Trinity; import trinity.Trinity;
import trinity.init.*;
import trinity.fluid.TrinityFluids; import trinity.fluid.TrinityFluids;
import trinity.gui.GuiHandlerRegistry; import trinity.gui.GuiHandlerRegistry;
import trinity.gui.GuiHandlerTrinity; import trinity.gui.GuiHandlerTrinity;
//import trinity.fluid.TrinityFluids;
import trinity.handler.OredictHandler; import trinity.handler.OredictHandler;
import trinity.init.ModBlocks;
import trinity.init.ModItems;
import trinity.init.TrinityEntities;
import trinity.init.TrinityRecipes;
import trinity.radiation.RadiationHandler; import trinity.radiation.RadiationHandler;
import trinity.tiles.TileEntityShieldedContainer; import trinity.tiles.TileEntityShieldedContainer;
import trinity.world.TrinityBiomes; import trinity.world.TrinityBiomes;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent; import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
public class CommonProxy { public class CommonProxy {
@ -51,6 +31,9 @@ public class CommonProxy {
ModBlocks.register(); ModBlocks.register();
OredictHandler.registerOres(); OredictHandler.registerOres();
MinecraftForge.EVENT_BUS.register(new TrinityRecipes()); MinecraftForge.EVENT_BUS.register(new TrinityRecipes());
MinecraftForge.EVENT_BUS.register(new CommonEvents());
if(Trinity.ICBMLoaded)
MinecraftForge.EVENT_BUS.register(new ICBMEvents());
GuiHandlerRegistry.getInstance().registerGuiHandler(new GuiHandlerTrinity(), GuiHandlerTrinity.getGuiID()); GuiHandlerRegistry.getInstance().registerGuiHandler(new GuiHandlerTrinity(), GuiHandlerTrinity.getGuiID());
GameRegistry.registerTileEntity(TileEntityShieldedContainer.class, "trinity:tile_inventory_basic"); GameRegistry.registerTileEntity(TileEntityShieldedContainer.class, "trinity:tile_inventory_basic");
//TrinityRecipes.init(); //TrinityRecipes.init();