Search in sources :

Example 1 with BoatEntity

use of net.minecraft.entity.item.BoatEntity in project endergetic by team-abnormals.

the class BolloomBalloonItem method use.

@Override
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getItemInHand(hand);
    if (!world.isClientSide && hasNoEntityTarget(player) && EntityUtil.rayTrace(player, getPlayerReach(player), 1.0F).getType() == Type.MISS && !player.isShiftKeyDown()) {
        Entity ridingEntity = player.getVehicle();
        boolean isRidingBoat = ridingEntity instanceof BoatEntity;
        if (isRidingBoat && canAttachBalloonToTarget(ridingEntity)) {
            attachToEntity(this.balloonColor, ridingEntity);
            player.swing(hand, true);
            if (!player.isCreative())
                stack.shrink(1);
            return ActionResult.consume(stack);
        }
        if (!isRidingBoat && canAttachBalloonToTarget(player)) {
            attachToEntity(this.balloonColor, player);
            player.swing(hand, true);
            if (!player.isCreative())
                stack.shrink(1);
            return ActionResult.consume(stack);
        }
    }
    return ActionResult.pass(stack);
}
Also used : BoatEntity(net.minecraft.entity.item.BoatEntity) Entity(net.minecraft.entity.Entity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) BolloomKnotEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomKnotEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BoatEntity

use of net.minecraft.entity.item.BoatEntity in project endergetic by team-abnormals.

the class EntityEvents method onPlayerSwing.

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onPlayerSwing(InputEvent.ClickInputEvent event) {
    if (event.isAttack()) {
        ClientPlayerEntity player = ClientInfo.getClientPlayer();
        if (player.xRot > -25.0F)
            return;
        Entity ridingEntity = player.getVehicle();
        if (ridingEntity instanceof BoatEntity && BolloomBalloonItem.hasNoEntityTarget(player) && EntityUtil.rayTrace(player, BolloomBalloonItem.getPlayerReach(player), 1.0F).getType() == Type.MISS) {
            List<BolloomBalloonEntity> balloons = ((BalloonHolder) ridingEntity).getBalloons();
            if (!balloons.isEmpty()) {
                Minecraft.getInstance().gameMode.attack(player, balloons.get(player.getRandom().nextInt(balloons.size())));
                event.setSwingHand(true);
            }
        }
    }
}
Also used : BoatEntity(net.minecraft.entity.item.BoatEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Entity(net.minecraft.entity.Entity) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with BoatEntity

use of net.minecraft.entity.item.BoatEntity in project Arclight by IzzelAliz.

the class BoatItemMixin method onItemRightClick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    RayTraceResult raytraceresult = rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.ANY);
    if (raytraceresult.getType() == RayTraceResult.Type.MISS) {
        return new ActionResult<>(ActionResultType.PASS, itemstack);
    } else {
        Vec3d vec3d = playerIn.getLook(1.0F);
        double d0 = 5.0D;
        List<Entity> list = worldIn.getEntitiesInAABBexcluding(playerIn, playerIn.getBoundingBox().expand(vec3d.scale(5.0D)).grow(1.0D), field_219989_a);
        if (!list.isEmpty()) {
            Vec3d vec3d1 = playerIn.getEyePosition(1.0F);
            for (Entity entity : list) {
                AxisAlignedBB axisalignedbb = entity.getBoundingBox().grow((double) entity.getCollisionBorderSize());
                if (axisalignedbb.contains(vec3d1)) {
                    return new ActionResult<>(ActionResultType.PASS, itemstack);
                }
            }
        }
        if (raytraceresult.getType() == RayTraceResult.Type.BLOCK) {
            BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) raytraceresult;
            PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockRayTraceResult.getPos(), blockRayTraceResult.getFace(), itemstack, handIn);
            if (event.isCancelled()) {
                return new ActionResult<>(ActionResultType.PASS, itemstack);
            }
            BoatEntity boatentity = new BoatEntity(worldIn, raytraceresult.getHitVec().x, raytraceresult.getHitVec().y, raytraceresult.getHitVec().z);
            boatentity.setBoatType(this.type);
            boatentity.rotationYaw = playerIn.rotationYaw;
            if (!worldIn.hasNoCollisions(boatentity, boatentity.getBoundingBox().grow(-0.1D))) {
                return new ActionResult<>(ActionResultType.FAIL, itemstack);
            } else {
                if (!worldIn.isRemote) {
                    if (CraftEventFactory.callEntityPlaceEvent(worldIn, blockRayTraceResult.getPos(), blockRayTraceResult.getFace(), playerIn, boatentity).isCancelled()) {
                        return new ActionResult<>(ActionResultType.FAIL, itemstack);
                    }
                    if (!worldIn.addEntity(boatentity)) {
                        return new ActionResult<>(ActionResultType.PASS, itemstack);
                    }
                    if (!playerIn.abilities.isCreativeMode) {
                        itemstack.shrink(1);
                    }
                }
                playerIn.addStat(Stats.ITEM_USED.get(this));
                return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
            }
        } else {
            return new ActionResult<>(ActionResultType.PASS, itemstack);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BoatEntity(net.minecraft.entity.item.BoatEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) ActionResult(net.minecraft.util.ActionResult) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with BoatEntity

use of net.minecraft.entity.item.BoatEntity in project Fragile-Glass by fredtargaryen.

the class EntityDataManager method addCapabilityIfPossible.

public void addCapabilityIfPossible(Entity e, AttachCapabilitiesEvent<Entity> evt) {
    // A player would reasonably expect many existing entities to be able to break fragile blocks, but it is
    // very unlikely that anyone would go to the trouble of writing out all the config lines for every entity.
    // The following code does some type checks and creates BreakerDatas if the entity probably would break a block.
    BreakerData breakerData = this.data.get(e.getType());
    if (breakerData == null) {
        // A breakerdata for this entitytype has not been created yet
        if (e instanceof LivingEntity || e instanceof ArrowEntity || e instanceof FireballEntity || e instanceof MinecartEntity || e instanceof FireworkRocketEntity || e instanceof BoatEntity || e instanceof TNTEntity || e instanceof FallingBlockEntity) {
            breakerData = new BreakerData(DataReference.MINIMUM_ENTITY_SPEED_SQUARED, DataReference.MAXIMUM_ENTITY_SPEED_SQUARED, new String[] {});
            this.data.put(e.getType(), breakerData);
        }
    }
    if (breakerData != null) {
        // The entity was predefined (via configs or commands) as being able to break a block,
        // or a BreakerData was automatically created above.
        ICapabilityProvider iCapProv = new ICapabilityProvider() {

            IBreakCapability inst = new IBreakCapability() {

                @Override
                public void init(Entity e) {
                }

                @Override
                public void update(Entity e) {
                }

                @Override
                public double getSpeedSquared(Entity e) {
                    Vector3d motion = e.getMotion();
                    return motion.x * motion.x + motion.y * motion.y + motion.z * motion.z;
                }

                @Override
                public boolean isAbleToBreak(Entity e, double speedSq) {
                    BreakerData breakerData = EntityDataManager.this.data.get(e.getType());
                    if (breakerData == null)
                        return false;
                    return speedSq >= breakerData.getMinSpeedSquared() && speedSq <= breakerData.getMaxSpeedSquared();
                }

                @Override
                public double getMotionX(Entity e) {
                    return e.getMotion().x;
                }

                @Override
                public double getMotionY(Entity e) {
                    return e.getMotion().y;
                }

                @Override
                public double getMotionZ(Entity e) {
                    return e.getMotion().z;
                }

                @Override
                public byte getNoOfBreaks(Entity e) {
                    return 1;
                }
            };

            @Nullable
            @Override
            public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
                return capability == FragileGlassBase.BREAKCAP ? LazyOptional.of(() -> (T) inst) : LazyOptional.empty();
            }
        };
        evt.addCapability(DataReference.BREAK_LOCATION, iCapProv);
    }
}
Also used : FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) BreakerData(com.fredtargaryen.fragileglass.config.behaviour.data.BreakerData) BoatEntity(net.minecraft.entity.item.BoatEntity) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) FireballEntity(net.minecraft.entity.projectile.FireballEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) IBreakCapability(com.fredtargaryen.fragileglass.entity.capability.IBreakCapability) Capability(net.minecraftforge.common.capabilities.Capability) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Nonnull(javax.annotation.Nonnull) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) Direction(net.minecraft.util.Direction) IBreakCapability(com.fredtargaryen.fragileglass.entity.capability.IBreakCapability) LivingEntity(net.minecraft.entity.LivingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) Nullable(javax.annotation.Nullable) FireballEntity(net.minecraft.entity.projectile.FireballEntity)

Aggregations

Entity (net.minecraft.entity.Entity)4 BoatEntity (net.minecraft.entity.item.BoatEntity)4 LivingEntity (net.minecraft.entity.LivingEntity)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 BolloomBalloonEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)2 ItemStack (net.minecraft.item.ItemStack)2 BreakerData (com.fredtargaryen.fragileglass.config.behaviour.data.BreakerData)1 IBreakCapability (com.fredtargaryen.fragileglass.entity.capability.IBreakCapability)1 BolloomKnotEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomKnotEntity)1 BalloonHolder (com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 FallingBlockEntity (net.minecraft.entity.item.FallingBlockEntity)1 TNTEntity (net.minecraft.entity.item.TNTEntity)1 MinecartEntity (net.minecraft.entity.item.minecart.MinecartEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)1 FireballEntity (net.minecraft.entity.projectile.FireballEntity)1 FireworkRocketEntity (net.minecraft.entity.projectile.FireworkRocketEntity)1