Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mob.transporter;
- import net.minecraft.client.MinecraftClient;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.CompoundTag;
- import net.minecraft.util.Hand;
- import net.minecraft.util.TypedActionResult;
- import net.minecraft.util.hit.BlockHitResult;
- import net.minecraft.util.hit.EntityHitResult;
- import net.minecraft.util.hit.HitResult;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- import net.minecraft.util.hit.HitResult.Type;
- public class FabricItem extends Item {
- public FabricItem(Settings settings) {
- super(settings);
- }
- @Override
- public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand)
- {
- ItemStack mainHand = playerEntity.inventory.getMainHandStack();
- CompoundTag tag = mainHand.getTag();
- EntityHitResult entityHit;
- Entity entity;
- MinecraftClient client = MinecraftClient.getInstance();
- HitResult hit = client.crosshairTarget;
- BlockPos blockPos;
- CompoundTag entityCTag = null;
- if (mainHand.getTag() == null)
- {
- CompoundTag newTag = mainHand.getOrCreateTag();
- newTag.putBoolean("hasEntity", false);
- newTag.put("entityTag", entityCTag);
- }
- if (hit.getType() == Type.ENTITY)
- {
- entityHit = (EntityHitResult) hit;
- entity = entityHit.getEntity();
- if (tag.getBoolean("hasEntity") == false)
- {
- entityCTag = new CompoundTag();
- entity.saveSelfToTag(entityCTag);
- entityCTag.remove("Pos");
- entity.remove();
- }
- else if (hit.getType() == Type.BLOCK)
- {
- BlockHitResult blockHit = (BlockHitResult) hit;
- blockPos = blockHit.getBlockPos();
- //BlockState blockState = client.world.getBlockState(blockPos);
- //Block block = blockState.getBlock();
- // i dont need these
- if (tag.getBoolean("hasEntity") == true)
- {
- if (entityCTag != null)
- {
- Vec3d SummonVec = new Vec3d(blockPos.getX(), blockPos.getY(), blockPos.getZ());
- Transporter.summon(tag.getCompound("entityTag"), world, SummonVec);
- tag.putBoolean("hasEntity", true);
- }
- }
- }
- }
- return TypedActionResult.success(playerEntity.getStackInHand(hand));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment