diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index 02181a7db..61f5aff36 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -46,11 +46,13 @@ public class Registry { public static final DamageSource DAMAGE_BECOME_ANDROID = new DamageSource("otm_become_android"); public static final DamageSource DAMAGE_BECOME_HUMANE = new DamageSource("otm_become_humane"); public static final DamageSource DAMAGE_EVENT_HORIZON = new DamageSource("otm_event_horizon"); + public static final DamageSource DAMAGE_HAWKING_RADIATION = new DamageSource("otm_hawking_radiation"); static { DAMAGE_BECOME_ANDROID.bypassArmor().bypassInvul().bypassMagic(); DAMAGE_BECOME_HUMANE.bypassArmor().bypassInvul().bypassMagic(); DAMAGE_EVENT_HORIZON.bypassMagic().bypassArmor(); + DAMAGE_HAWKING_RADIATION.bypassMagic().bypassArmor(); } public static final ForgeRegistry> ANDROID_FEATURES; @@ -119,6 +121,8 @@ public class Registry { public static final ResourceLocation ANDROID_CAPABILITY = new ResourceLocation(OverdriveThatMatters.MOD_ID, "android_capability"); // items + public static final ResourceLocation GRAVITATIONAL_DISRUPTOR = new ResourceLocation(OverdriveThatMatters.MOD_ID, "gravitational_disruptor"); + public static final ResourceLocation PILL_ANDROID = new ResourceLocation(OverdriveThatMatters.MOD_ID, "pill_android"); public static final ResourceLocation PILL_HUMANE = new ResourceLocation(OverdriveThatMatters.MOD_ID, "pill_humane"); @@ -381,6 +385,8 @@ public class Registry { public static final Item BLACK_HOLE = new BlockItem(Blocks.BLACK_HOLE, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); + public static final ItemGravitationalDisruptor GRAVITATIONAL_DISRUPTOR = new ItemGravitationalDisruptor(); + public static final ItemPill PILL_ANDROID = new ItemPill(ItemPill.PillType.BECOME_ANDROID); public static final ItemPill PILL_HUMANE = new ItemPill(ItemPill.PillType.BECOME_HUMANE); @@ -451,6 +457,7 @@ public class Registry { BASIC_CONTROL_CIRCUIT.setRegistryName(Names.BASIC_CONTROL_CIRCUIT); ADVANCED_CONTROL_CIRCUIT.setRegistryName(Names.ADVANCED_CONTROL_CIRCUIT); + GRAVITATIONAL_DISRUPTOR.setRegistryName(Names.GRAVITATIONAL_DISRUPTOR); PILL_ANDROID.setRegistryName(Names.PILL_ANDROID); PILL_HUMANE.setRegistryName(Names.PILL_HUMANE); BATTERY_CRUDE.setRegistryName(Names.BATTERY_CRUDE); @@ -515,6 +522,7 @@ public class Registry { event.getRegistry().register(BASIC_CONTROL_CIRCUIT); event.getRegistry().register(ADVANCED_CONTROL_CIRCUIT); + event.getRegistry().register(GRAVITATIONAL_DISRUPTOR); event.getRegistry().register(PILL_ANDROID); event.getRegistry().register(PILL_HUMANE); event.getRegistry().register(BATTERY_CRUDE); diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityBlackHole.java b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityBlackHole.java index f97ab41f6..a9ed3da74 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityBlackHole.java +++ b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityBlackHole.java @@ -11,11 +11,16 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.ExplosionDamageCalculator; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import ru.dbotthepony.mc.otm.OverdriveThatMatters; @@ -25,6 +30,7 @@ import ru.dbotthepony.mc.otm.matter.MatterRegistry; import javax.annotation.Nullable; import java.math.BigDecimal; +import java.util.Optional; public class BlockEntityBlackHole extends BlockEntity { public BlockEntityBlackHole(BlockPos p_155229_, BlockState p_155230_) { @@ -41,8 +47,76 @@ public class BlockEntityBlackHole extends BlockEntity { return gravitation_strength; } - public void collapse() { + private static class BlackHoleExplosionDamageCalculator extends ExplosionDamageCalculator { + @Override + public Optional getBlockExplosionResistance(Explosion explosion, BlockGetter getter, BlockPos pos, BlockState state, FluidState fstate) { + return state.isAir() && fstate.isEmpty() ? + Optional.empty() : + Optional.of( + (float) Math.sqrt( + Math.max(0, + Math.max( + state.getExplosionResistance(getter, pos, explosion), + fstate.getExplosionResistance(getter, pos, explosion) + ) + ) + ) + ); + } + private static final BlackHoleExplosionDamageCalculator INSTANCE = new BlackHoleExplosionDamageCalculator(); + } + + public void collapse() { + level.setBlock(getBlockPos(), Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL); + + if (gravitation_strength > 0.25) { + final double x0 = getBlockPos().getX() + 0.5; + final double y0 = getBlockPos().getY() + 0.5; + final double z0 = getBlockPos().getZ() + 0.5; + + for (int radius = 0; radius < Math.ceil(gravitation_strength * 4); radius++) { + final int fragments = radius * 8; + + final double stack_step = Math.PI / (double) fragments; + final double sector_step = Math.PI / (double) fragments * 2; + + for (int stack = 0; stack < fragments; stack++) { + final double stack_angle = Math.PI / 2 - stack * stack_step; + final double xy = radius * 20 * Math.cos(stack_angle); + final double z = radius * 20 * Math.sin(stack_angle); + + for (int sector = 0; sector < fragments; sector++) { + final double sector_angle = sector * sector_step; + + final double x = xy * Math.cos(sector_angle); + final double y = xy * Math.sin(sector_angle); + + level.explode( + null, + Registry.DAMAGE_HAWKING_RADIATION, + BlackHoleExplosionDamageCalculator.INSTANCE, + x0 + x, + y0 + y, + z0 + z, + (float) Math.min(30, Math.max(1, (gravitation_strength * 4 - radius) * 30)), + false, + Explosion.BlockInteraction.DESTROY); + } + } + } + } else { + level.explode( + null, + Registry.DAMAGE_HAWKING_RADIATION, + null, + (double)getBlockPos().getX() + 0.5D, + (double)getBlockPos().getY() + 0.5D, + (double)getBlockPos().getZ() + 0.5D, + (float) gravitation_strength * 60, + false, + Explosion.BlockInteraction.DESTROY); + } } public void addMass(BigDecimal mass) { @@ -197,10 +271,14 @@ public class BlockEntityBlackHole extends BlockEntity { if (distance < tile.gravitation_strength + 1) { if (item.hurt(Registry.DAMAGE_EVENT_HORIZON, (float) (tile.gravitation_strength / distance)) && item.isRemoved()) { - var mass = MatterRegistry.getMatterValue(item.getItem()); + if (item.getItem().getItem() == Registry.Items.GRAVITATIONAL_DISRUPTOR) { + tile.collapse(); + } else { + var mass = MatterRegistry.getMatterValue(item.getItem()); - if (mass.compareTo(BigDecimal.ZERO) > 0) - tile.addMass(mass); + if (mass.compareTo(BigDecimal.ZERO) > 0) + tile.addMass(mass); + } } } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.java b/src/main/java/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.java new file mode 100644 index 000000000..442cf65b6 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/item/ItemGravitationalDisruptor.java @@ -0,0 +1,32 @@ +package ru.dbotthepony.mc.otm.item; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import ru.dbotthepony.mc.otm.OverdriveThatMatters; + +import javax.annotation.Nullable; +import java.util.List; + +public class ItemGravitationalDisruptor extends Item { + public ItemGravitationalDisruptor() { + super(new Properties().tab(OverdriveThatMatters.CREATIVE_TAB).stacksTo(1).rarity(Rarity.EPIC)); + } + + private static final Component DESCRIPTION = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description").withStyle(ChatFormatting.GRAY); + private static final Component DESCRIPTION2 = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description2").withStyle(ChatFormatting.GRAY); + private static final Component DESCRIPTION3 = new TranslatableComponent("item.overdrive_that_matters.gravitational_disruptor.description3").withStyle(ChatFormatting.DARK_RED); + + @Override + public void appendHoverText(ItemStack p_41421_, @Nullable Level p_41422_, List list, TooltipFlag p_41424_) { + super.appendHoverText(p_41421_, p_41422_, list, p_41424_); + list.add(DESCRIPTION); + list.add(DESCRIPTION2); + list.add(DESCRIPTION3); + } +} diff --git a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json index 1cf408535..21278fef0 100644 --- a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json +++ b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json @@ -114,10 +114,12 @@ "death.attack.otm_become_android": "%1$s lost their humanity", "death.attack.otm_become_humane": "%1$s gained their humanity", "death.attack.otm_event_horizon": "%1$s never crossed event horizon", + "death.attack.otm_hawking_radiation": "%1$s discovered Hawking radiation", "death.attack.otm_become_android.player": "%1$s lost their humanity whilst %2$s tried to reason with them", "death.attack.otm_become_humane.player": "%1$s gained their humanity whilst %2$s tried to reason with them", "death.attack.otm_event_horizon.player": "%1$s tried to cross event horizon whilst trying to escape %2$s", + "death.attack.otm_hawking_radiation.player": "%1$s disintegrated whilst fighting %2$s", "block.overdrive_that_matters.android_station": "Android Station", "block.overdrive_that_matters.battery_bank": "Battery Bank", @@ -180,6 +182,11 @@ "item.overdrive_that_matters.matter_capacitor_dense": "Dense Matter Capacitor", "item.overdrive_that_matters.matter_capacitor_creative": "Creative Matter Capacitor", + "item.overdrive_that_matters.gravitational_disruptor": "Gravitational Disruptor", + "item.overdrive_that_matters.gravitational_disruptor.description": "Once within close proximity of supermassive body, suppresses any gravity in it's radius", + "item.overdrive_that_matters.gravitational_disruptor.description2": "Allows collapse of black holes", + "item.overdrive_that_matters.gravitational_disruptor.description3": "Doesn't destroy all the mass singularity had acquired, which result in violent explosion of matter!", + "item.overdrive_that_matters.tritanium_ore_clump": "Raw Tritanium", "item.overdrive_that_matters.tritanium_ingot": "Tritanium Ingot",