|
3 | 3 | import com.github.alexthe666.iceandfire.IafConfig;
|
4 | 4 | import com.github.alexthe666.iceandfire.IceAndFire;
|
5 | 5 | import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
|
| 6 | +import com.github.alexthe666.iceandfire.datagen.tags.IafItemTags; |
6 | 7 | import com.github.alexthe666.iceandfire.entity.*;
|
7 | 8 | import com.github.alexthe666.iceandfire.entity.ai.AiDebug;
|
8 | 9 | import com.github.alexthe666.iceandfire.entity.ai.EntitySheepAIFollowCyclops;
|
|
63 | 64 | import net.minecraft.world.phys.EntityHitResult;
|
64 | 65 | import net.minecraftforge.event.LootTableLoadEvent;
|
65 | 66 | import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
| 67 | +import net.minecraftforge.event.entity.EntityStruckByLightningEvent; |
66 | 68 | import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
67 | 69 | import net.minecraftforge.event.entity.living.*;
|
68 | 70 | import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
71 | 73 | import net.minecraftforge.event.level.BlockEvent;
|
72 | 74 | import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
73 | 75 | import net.minecraftforge.event.village.VillagerTradesEvent;
|
| 76 | +import net.minecraftforge.eventbus.api.EventPriority; |
74 | 77 | import net.minecraftforge.eventbus.api.SubscribeEvent;
|
75 | 78 | import net.minecraftforge.fml.common.Mod;
|
76 | 79 | import net.minecraftforge.registries.ForgeRegistries;
|
77 | 80 |
|
78 | 81 | import javax.annotation.Nullable;
|
79 | 82 | import java.util.*;
|
| 83 | +import java.util.stream.Collectors; |
80 | 84 |
|
81 | 85 | @Mod.EventBusSubscriber(modid = IceAndFire.MODID)
|
82 | 86 | public class ServerEvents {
|
@@ -287,6 +291,29 @@ public void onEntityDrop(LivingDropsEvent event) {
|
287 | 291 | }
|
288 | 292 | }
|
289 | 293 |
|
| 294 | + @SubscribeEvent(priority = EventPriority.LOWEST) |
| 295 | + public void makeItemDropsFireImmune(LivingDropsEvent event) { |
| 296 | + boolean makeFireImmune = false; |
| 297 | + |
| 298 | + if (event.getSource().getDirectEntity() instanceof LightningBolt bolt && bolt.getTags().contains(BOLT_DONT_DESTROY_ITEMS)) { |
| 299 | + makeFireImmune = true; |
| 300 | + } else if (event.getSource().getEntity() instanceof Player player && player.getItemInHand(player.getUsedItemHand()).is(IafItemTags.MAKE_ITEM_DROPS_FIREIMMUNE)) { |
| 301 | + makeFireImmune = true; |
| 302 | + } |
| 303 | + |
| 304 | + if (makeFireImmune) { |
| 305 | + Set<ItemEntity> fireImmuneDrops = event.getDrops().stream().map(itemEntity -> new ItemEntity(itemEntity.level, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), itemEntity.getItem()) { |
| 306 | + @Override |
| 307 | + public boolean fireImmune() { |
| 308 | + return true; |
| 309 | + } |
| 310 | + }).collect(Collectors.toSet()); |
| 311 | + |
| 312 | + event.getDrops().clear(); |
| 313 | + event.getDrops().addAll(fireImmuneDrops); |
| 314 | + } |
| 315 | + } |
| 316 | + |
290 | 317 | @SubscribeEvent
|
291 | 318 | public void onLivingAttacked(final LivingAttackEvent event) {
|
292 | 319 | if (event.getSource() != null && event.getSource().getEntity() != null) {
|
@@ -650,4 +677,13 @@ public void onVillagerTrades(VillagerTradesEvent event) {
|
650 | 677 | IafVillagerRegistry.addScribeTrades(event.getTrades());
|
651 | 678 | }
|
652 | 679 | }
|
| 680 | + |
| 681 | + public static String BOLT_DONT_DESTROY_ITEMS = "skip_items"; |
| 682 | + |
| 683 | + @SubscribeEvent |
| 684 | + public void onLightningHit(EntityStruckByLightningEvent event) { |
| 685 | + if (event.getLightning().getTags().contains(BOLT_DONT_DESTROY_ITEMS) && event.getEntity() instanceof ItemEntity) { |
| 686 | + event.setCanceled(true); |
| 687 | + } |
| 688 | + } |
653 | 689 | }
|
0 commit comments