Search in sources :

Example 1 with PlaneEntity

use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.

the class PlaneItem method use.

@Override
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
    ItemStack itemstack = playerIn.getItemInHand(handIn);
    HitResult hitResult = getPlayerPOVHitResult(worldIn, playerIn, ClipContext.Fluid.ANY);
    if (hitResult.getType() == HitResult.Type.MISS) {
        return InteractionResultHolder.pass(itemstack);
    } else {
        Vec3 vec3d = playerIn.getViewVector(1.0F);
        List<Entity> list = worldIn.getEntities(playerIn, playerIn.getBoundingBox().expandTowards(vec3d.scale(5.0D)).inflate(1.0D), ENTITY_PREDICATE);
        if (!list.isEmpty()) {
            Vec3 vec3d1 = playerIn.getEyePosition(1.0F);
            for (Entity entity : list) {
                AABB aabb = entity.getBoundingBox().inflate(entity.getPickRadius());
                if (aabb.contains(vec3d1)) {
                    return InteractionResultHolder.pass(itemstack);
                }
            }
        }
        if (hitResult.getType() == HitResult.Type.BLOCK) {
            PlaneEntity planeEntity = planeEntityType.get().create(worldIn);
            planeEntity.setPos(hitResult.getLocation().x(), hitResult.getLocation().y(), hitResult.getLocation().z());
            planeEntity.setYRot(playerIn.getYRot());
            planeEntity.yRotO = playerIn.yRotO;
            planeEntity.setCustomName(itemstack.getHoverName());
            CompoundTag entityTag = itemstack.getTagElement("EntityTag");
            if (entityTag != null) {
                planeEntity.readAdditionalSaveData(entityTag);
            }
            if (!worldIn.noCollision(planeEntity, planeEntity.getBoundingBox().inflate(-0.1D))) {
                return InteractionResultHolder.fail(itemstack);
            } else {
                if (!worldIn.isClientSide) {
                    worldIn.addFreshEntity(planeEntity);
                    if (!playerIn.getAbilities().instabuild) {
                        itemstack.shrink(1);
                    }
                }
                playerIn.awardStat(Stats.ITEM_USED.get(this));
                return InteractionResultHolder.success(itemstack);
            }
        } else {
            return InteractionResultHolder.pass(itemstack);
        }
    }
}
Also used : HitResult(net.minecraft.world.phys.HitResult) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) Entity(net.minecraft.world.entity.Entity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) Vec3(net.minecraft.world.phys.Vec3) ItemStack(net.minecraft.world.item.ItemStack) AABB(net.minecraft.world.phys.AABB) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with PlaneEntity

use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.

the class UpdateUpgradePacket method handle.

public void handle(Supplier<NetworkEvent.Context> ctxSup) {
    NetworkEvent.Context ctx = ctxSup.get();
    ctx.enqueueWork(() -> {
        ClientLevel clientWorld = Minecraft.getInstance().level;
        ((PlaneEntity) clientWorld.getEntity(planeEntityID)).readUpdateUpgradePacket(upgradeID, packetBuffer, newUpgrade);
    });
    ctx.setPacketHandled(true);
}
Also used : ClientLevel(net.minecraft.client.multiplayer.ClientLevel) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) NetworkEvent(net.minecraftforge.network.NetworkEvent)

Example 3 with PlaneEntity

use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.

the class CommonEventHandler method interact.

@SubscribeEvent
public static void interact(PlayerInteractEvent.RightClickItem event) {
    Player player = event.getPlayer();
    Entity entity = player.getRootVehicle();
    if (entity instanceof PlaneEntity) {
        ItemStack itemStack = player.getItemInHand(event.getHand());
        if (!itemStack.isEmpty()) {
            if (itemStack.getItem() == Items.TNT && entity instanceof LargePlaneEntity && ((LargePlaneEntity) entity).tryToAddTNT(player, itemStack)) {
                return;
            }
            PlaneEntity planeEntity = (PlaneEntity) entity;
            for (Upgrade upgrade : planeEntity.upgrades.values()) {
                upgrade.onItemRightClick(event);
            }
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) Player(net.minecraft.world.entity.player.Player) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) ItemStack(net.minecraft.world.item.ItemStack) Upgrade(xyz.przemyk.simpleplanes.upgrades.Upgrade) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with PlaneEntity

use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.

the class RemoveUpgradesScreen method init.

@Override
protected void init() {
    super.init();
    Entity entity = minecraft.level.getEntity(menu.planeID);
    if (entity instanceof PlaneEntity) {
        buttonsList = new UpgradeButtonsList(minecraft, 120, height, 32, height - 61, 20, (PlaneEntity) entity);
        addRenderableWidget(buttonsList);
    } else {
        onClose();
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) UpgradeButtonsList(xyz.przemyk.simpleplanes.UpgradeButtonsList)

Example 5 with PlaneEntity

use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.

the class SUpgradeRemovedPacket method handle.

public void handle(Supplier<NetworkEvent.Context> ctxSup) {
    NetworkEvent.Context ctx = ctxSup.get();
    ctx.enqueueWork(() -> {
        ClientLevel clientWorld = Minecraft.getInstance().level;
        ((PlaneEntity) clientWorld.getEntity(planeEntityID)).removeUpgrade(upgradeID);
    });
    ctx.setPacketHandled(true);
}
Also used : ClientLevel(net.minecraft.client.multiplayer.ClientLevel) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) NetworkEvent(net.minecraftforge.network.NetworkEvent)

Aggregations

PlaneEntity (xyz.przemyk.simpleplanes.entities.PlaneEntity)6 Entity (net.minecraft.world.entity.Entity)3 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)2 ItemStack (net.minecraft.world.item.ItemStack)2 NetworkEvent (net.minecraftforge.network.NetworkEvent)2 CompoundTag (net.minecraft.nbt.CompoundTag)1 Player (net.minecraft.world.entity.player.Player)1 AABB (net.minecraft.world.phys.AABB)1 HitResult (net.minecraft.world.phys.HitResult)1 Vec3 (net.minecraft.world.phys.Vec3)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 UpgradeButtonsList (xyz.przemyk.simpleplanes.UpgradeButtonsList)1 LargePlaneEntity (xyz.przemyk.simpleplanes.entities.LargePlaneEntity)1 Upgrade (xyz.przemyk.simpleplanes.upgrades.Upgrade)1