Skip to content

Commit 93554ad

Browse files
fix custom name not being saved when using markerAddInstantOnBannerPlace
closes #7
1 parent 55e2fe6 commit 93554ad

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/dev/nincodedo/bluemapbanners/mixin/BlockItemMixin.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import net.minecraft.block.entity.BannerBlockEntity;
77
import net.minecraft.entity.player.PlayerEntity;
88
import net.minecraft.item.BlockItem;
9-
import net.minecraft.item.ItemStack;
9+
import net.minecraft.item.ItemPlacementContext;
1010
import net.minecraft.registry.tag.BlockTags;
1111
import net.minecraft.text.ClickEvent;
1212
import net.minecraft.text.Style;
1313
import net.minecraft.text.Text;
14+
import net.minecraft.util.ActionResult;
1415
import net.minecraft.util.math.BlockPos;
1516
import net.minecraft.world.World;
1617
import org.spongepowered.asm.mixin.Mixin;
@@ -22,8 +23,13 @@
2223

2324
@Mixin(BlockItem.class)
2425
public class BlockItemMixin {
25-
@Inject(at = @At("HEAD"), method = "postPlacement")
26-
public void onPlaceInject(BlockPos pos, World world, PlayerEntity player, ItemStack stack, BlockState state, CallbackInfoReturnable<Boolean> cir) {
26+
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;",
27+
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;emitGameEvent(Lnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/event/GameEvent$Emitter;)V"))
28+
public void onPlaceInject(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> cir) {
29+
BlockPos pos = context.getBlockPos();
30+
World world = context.getWorld();
31+
PlayerEntity player = context.getPlayer();
32+
BlockState state = world.getBlockState(pos);
2733
if (state.isIn(BlockTags.BANNERS)) {
2834
MarkerManager markerManager = MarkerManager.getInstance();
2935
ConfigManager configManager = ConfigManager.getInstance();
@@ -38,11 +44,11 @@ public void onPlaceInject(BlockPos pos, World world, PlayerEntity player, ItemSt
3844
name = Text.translatable(blockTranslationKey).getString();
3945
}
4046
markerManager.addMarker(bannerBlockEntity, name);
41-
if (configManager.getBoolConfig("notifyPlayerOnMarkerAdd"))
47+
if (configManager.getBoolConfig("notifyPlayerOnMarkerAdd") && player != null)
4248
player.sendMessage(Text.literal("[BlueMap Banners] You added a marker to the ").append(Text.literal("web map").setStyle(Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(ConfigManager.getInstance().getConfig("bluemapUrl")))).withUnderline(true))).append(Text.of(".")), false);
4349
}
4450
} else {
45-
if (configManager.getBoolConfig("notifyPlayerOnBannerPlace")) {
51+
if (configManager.getBoolConfig("notifyPlayerOnBannerPlace") && player != null) {
4652
player.sendMessage(Text.literal("[BlueMap Banners] Use a map item on the banner to add a marker on the ").append(Text.literal("web map").setStyle(Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(ConfigManager.getInstance().getConfig("bluemapUrl")))).withUnderline(true))).append(Text.of(".")), false);
4753
}
4854
}

0 commit comments

Comments
 (0)