mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Fix #3225 hopefully. My workspace is broken so I can't test
This commit is contained in:
1 parent
ba943c8158
commit
37f60f05a5
2 files changed
+28
-7
No files matched your search
@@ -1,16 +1,19 @@
|
||||
package vazkii.botania.common.core.helper;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementManager;
|
||||
import net.minecraft.advancements.PlayerAdvancements;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
@@ -115,14 +118,20 @@ public final class PlayerHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static ActionResultType substituteUse(ItemUseContext ctx, ItemStack toUse) {
|
||||
return substituteUseTrackPos(ctx, toUse).getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily swap <code>toUse</code> into the hand of the player, use it, then swap it back out.
|
||||
* This is to ensure that any code in mods' onItemUse that relies on player.getHeldItem(ctx.hand) == ctx.stack
|
||||
* will work as intended.
|
||||
*
|
||||
* Properly handles null players, as long as the Item's onItemUse also handles them.
|
||||
* @return The usage result, as well as a properly offset block position pointing at where the block was placed
|
||||
* (if the item was a BlockItem)
|
||||
*/
|
||||
public static ActionResultType substituteUse(ItemUseContext ctx, ItemStack toUse) {
|
||||
public static Pair<ActionResultType, BlockPos> substituteUseTrackPos(ItemUseContext ctx, ItemStack toUse) {
|
||||
ItemStack save = ItemStack.EMPTY;
|
||||
BlockRayTraceResult hit = new BlockRayTraceResult(ctx.getHitVec(), ctx.getFace(), ctx.getPos(), ctx.func_221533_k());
|
||||
ItemUseContext newCtx;
|
||||
@@ -136,13 +145,15 @@ public final class PlayerHelper {
|
||||
newCtx = new ItemUseContext(ctx.getWorld(), null, ctx.getHand(), toUse, hit);
|
||||
}
|
||||
|
||||
BlockPos finalPos = new BlockItemUseContext(newCtx).getPos();
|
||||
|
||||
ActionResultType result = toUse.onItemUse(newCtx);
|
||||
|
||||
if(ctx.getPlayer() != null) {
|
||||
ctx.getPlayer().setHeldItem(ctx.getHand(), save);
|
||||
}
|
||||
|
||||
return result;
|
||||
return Pair.of(result, finalPos);
|
||||
}
|
||||
|
||||
private PlayerHelper() {}
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -91,18 +93,26 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
|
||||
private ActionResultType placeSpawner(ItemUseContext ctx) {
|
||||
ItemStack useStack = new ItemStack(Blocks.SPAWNER);
|
||||
useStack.getOrCreateTag().put("BlockEntityTag", ctx.getItem().getChildTag(TAG_SPAWNER));
|
||||
ActionResultType res = PlayerHelper.substituteUse(ctx, useStack);
|
||||
Pair<ActionResultType, BlockPos> res = PlayerHelper.substituteUseTrackPos(ctx, useStack);
|
||||
|
||||
if(res == ActionResultType.SUCCESS) {
|
||||
if(res.getFirst() == ActionResultType.SUCCESS) {
|
||||
World world = ctx.getWorld();
|
||||
BlockPos pos = ctx.getPos();
|
||||
BlockPos pos = res.getSecond();
|
||||
ItemStack mover = ctx.getItem();
|
||||
|
||||
if(!world.isRemote) {
|
||||
if(ctx.getPlayer() != null)
|
||||
ctx.getPlayer().sendBreakAnimation(ctx.getHand());
|
||||
mover.shrink(1);
|
||||
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof MobSpawnerTileEntity) {
|
||||
CompoundNBT spawnerTag = ctx.getItem().getChildTag(TAG_SPAWNER).copy();
|
||||
spawnerTag.putInt("x", pos.getX());
|
||||
spawnerTag.putInt("y", pos.getY());
|
||||
spawnerTag.putInt("z", pos.getZ());
|
||||
te.read(spawnerTag);
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < 100; i++) {
|
||||
SparkleParticleData data = SparkleParticleData.sparkle(0.45F + 0.2F * (float) Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 6);
|
||||
@@ -111,7 +121,7 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return res.getFirst();
|
||||
}
|
||||
|
||||
private boolean captureSpawner(ItemUseContext ctx) {
|
||||
|
||||
Reference in new issue
Block a user