Skip to content

Commit

Permalink
增加一些雷击事件
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Apr 1, 2024
1 parent 8a4f5bd commit 30e51b1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/inventory/RoyalAnvilMenu.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package dev.dubhe.anvilcraft.inventory;

import dev.dubhe.anvilcraft.init.ModItems;
import dev.dubhe.anvilcraft.init.ModMenuTypes;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.MenuType;
Expand All @@ -12,6 +16,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand Down Expand Up @@ -150,4 +155,16 @@ public void createResult() {
this.resultSlots.setItem(0, itemStack2);
this.broadcastChanges();
}

@Override
protected void onTake(Player player, ItemStack stack) {
super.onTake(player, stack);
Level level = player.level();
if (level.isClientSide()) return;
int curedNumber = player.getInventory().countItem(ModItems.CURSED_GOLD_INGOT) + player.getInventory().countItem(ModItems.CURSED_GOLD_NUGGET) + player.getInventory().countItem(ModItems.CURSED_GOLD_BLOCK);
if (curedNumber <= 0) return;
LightningBolt bolt = new LightningBolt(EntityType.LIGHTNING_BOLT, level);
bolt.setPos(player.getX(), player.getY(), player.getZ());
level.addFreshEntity(bolt);
}
}
43 changes: 43 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/mixin/BeaconMenuMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.dubhe.anvilcraft.mixin;

import dev.dubhe.anvilcraft.init.ModItems;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.inventory.BeaconMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameRules;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;

@Mixin(BeaconMenu.class)
public class BeaconMenuMixin {
@Shadow
@Final
private BeaconMenu.PaymentSlot paymentSlot;

@Shadow
@Final
private ContainerLevelAccess access;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Inject(method = "updateEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/BeaconMenu$PaymentSlot;remove(I)Lnet/minecraft/world/item/ItemStack;"))
private void updateEffects(Optional<MobEffect> primaryEffect, Optional<MobEffect> secondaryEffect, CallbackInfo ci) {
ItemStack item = this.paymentSlot.getItem();
if (!item.is(ModItems.CURSED_GOLD_INGOT)) return;
this.access.execute((level, pos) -> {
if (!(level instanceof ServerLevel serverLevel)) return;
MinecraftServer server = serverLevel.getServer();
GameRules.BooleanValue rule = server.getGameRules().getRule(GameRules.RULE_WEATHER_CYCLE);
if (!rule.get()) return;
serverLevel.setWeatherParameters(0, ServerLevel.THUNDER_DURATION.sample(serverLevel.getRandom()), true, true);
});
}
}
1 change: 1 addition & 0 deletions src/main/resources/anvilcraft.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ accessible class net/minecraft/world/item/crafting/Ingredient$ItemValue
accessible class net/minecraft/server/MinecraftServer$ReloadableResources
accessible class net/minecraft/world/item/crafting/Ingredient$Value
accessible class net/minecraft/world/item/crafting/Ingredient$TagValue
accessible class net/minecraft/world/inventory/BeaconMenu$PaymentSlot
extendable method net/minecraft/client/gui/screens/inventory/AbstractContainerScreen renderSlot (Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/inventory/Slot;)V
accessible method net/minecraft/server/MinecraftServer$ReloadableResources resourceManager ()Lnet/minecraft/server/packs/resources/CloseableResourceManager;
accessible method net/minecraft/world/level/block/entity/HopperBlockEntity tryMoveInItem (Lnet/minecraft/world/Container;Lnet/minecraft/world/Container;Lnet/minecraft/world/item/ItemStack;ILnet/minecraft/core/Direction;)Lnet/minecraft/world/item/ItemStack;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/anvilcraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"AbstractCauldronBlockMixin",
"AnvilBlockMixin",
"AxeItemMixin",
"BeaconMenuMixin",
"BlockStateInjector",
"BucketItemMixin",
"ClientboundUpdateRecipesPacketMixin",
Expand Down

0 comments on commit 30e51b1

Please sign in to comment.